diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-11-09 12:57:14 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2018-11-09 12:57:14 +0100 |
commit | 66dd17664c08aca17b53d2853558121aa9e702e4 (patch) | |
tree | b6bc5dd919e5f525ec7328861b81f616673a1ea6 /common/design_utils.cc | |
parent | e91241f10d68fcaaf0a81fa77e9a91666120ccee (diff) | |
parent | 15d9b3d3cc05656e58d01ba2f97ec92b6daaee1c (diff) | |
download | nextpnr-66dd17664c08aca17b53d2853558121aa9e702e4.tar.gz nextpnr-66dd17664c08aca17b53d2853558121aa9e702e4.tar.bz2 nextpnr-66dd17664c08aca17b53d2853558121aa9e702e4.zip |
Merge branch 'master' of github.com:YosysHQ/nextpnr into router_improve
Diffstat (limited to 'common/design_utils.cc')
-rw-r--r-- | common/design_utils.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/common/design_utils.cc b/common/design_utils.cc index 21c9dcc4..a0b87764 100644 --- a/common/design_utils.cc +++ b/common/design_utils.cc @@ -19,6 +19,7 @@ */ #include "design_utils.h" +#include <algorithm> #include <map> #include "log.h" #include "util.h" @@ -73,4 +74,55 @@ void print_utilisation(const Context *ctx) log_break(); } +// Connect a net to a port +void connect_port(const Context *ctx, NetInfo *net, CellInfo *cell, IdString port_name) +{ + if (net == nullptr) + return; + PortInfo &port = cell->ports.at(port_name); + NPNR_ASSERT(port.net == nullptr); + port.net = net; + if (port.type == PORT_OUT) { + NPNR_ASSERT(net->driver.cell == nullptr); + net->driver.cell = cell; + net->driver.port = port_name; + } else if (port.type == PORT_IN) { + PortRef user; + user.cell = cell; + user.port = port_name; + net->users.push_back(user); + } else { + NPNR_ASSERT_FALSE("invalid port type for connect_port"); + } +} + +void disconnect_port(const Context *ctx, CellInfo *cell, IdString port_name) +{ + if (!cell->ports.count(port_name)) + return; + PortInfo &port = cell->ports.at(port_name); + if (port.net != nullptr) { + port.net->users.erase(std::remove_if(port.net->users.begin(), port.net->users.end(), + [cell, port_name](const PortRef &user) { + return user.cell == cell && user.port == port_name; + }), + port.net->users.end()); + } +} + +void connect_ports(Context *ctx, CellInfo *cell1, IdString port1_name, CellInfo *cell2, IdString port2_name) +{ + PortInfo &port1 = cell1->ports.at(port1_name); + if (port1.net == nullptr) { + // No net on port1; need to create one + std::unique_ptr<NetInfo> p1net(new NetInfo()); + p1net->name = ctx->id(cell1->name.str(ctx) + "$conn$" + port1_name.str(ctx)); + connect_port(ctx, p1net.get(), cell1, port1_name); + IdString p1name = p1net->name; + NPNR_ASSERT(!ctx->cells.count(p1name)); + ctx->nets[p1name] = std::move(p1net); + } + connect_port(ctx, port1.net, cell2, port2_name); +} + NEXTPNR_NAMESPACE_END |