aboutsummaryrefslogtreecommitdiffstats
path: root/ice40/pcf.cc
blob: 756aba4a57b8b7e5bbc276eae52584b80e7b31fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 *  nextpnr -- Next Generation Place and Route
 *
 *  Copyright (C) 2018  Clifford Wolf <clifford@clifford.at>
 *  Copyright (C) 2018  David Shah <david@symbioticeda.com>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "pcf.h"
#include <sstream>
#include "log.h"

NEXTPNR_NAMESPACE_BEGIN

// Read a w

// Apply PCF constraints to a pre-packing design
void apply_pcf(Context *ctx, std::istream &in)
{
    if (!in)
        log_error("failed to open PCF file");
    std::string line;
    while (std::getline(in, line)) {
        size_t cstart = line.find("#");
        if (cstart != std::string::npos)
            line = line.substr(0, cstart);
        std::stringstream ss(line);
        std::vector<std::string> words;
        std::string tmp;
        while (ss >> tmp)
            words.push_back(tmp);
        if (words.size() == 0)
            continue;
        std::string cmd = words.at(0);
        if (cmd == "set_io") {
            size_t args_end = 1;
            while (args_end < words.size() && words.at(args_end).at(0) == '-')
                args_end++;
            std::string cell = words.at(args_end);
            std::string pin = words.at(args_end + 1);
            auto fnd_cell = ctx->cells.find(cell);
            if (fnd_cell == ctx->cells.end()) {
                log_warning("unmatched pcf constraint %s\n", cell.c_str());
            } else {
                BelId pin_bel = ctx->getPackagePinBel(pin);
                if (pin_bel == BelId())
                    log_error("package does not have a pin named %s\n",
                              pin.c_str());
                fnd_cell->second->attrs["BEL"] = ctx->getBelName(pin_bel).str();
                log_info("constrained '%s' to bel '%s'\n", cell.c_str(),
                         fnd_cell->second->attrs["BEL"].c_str());
            }
        } else {
            log_error("unsupported pcf command '%s'\n", cmd.c_str());
        }
    }
}

NEXTPNR_NAMESPACE_END