From d770eb672fcaf303d391d4fb22e57b13dd130ca5 Mon Sep 17 00:00:00 2001 From: David Shah Date: Mon, 1 Oct 2018 15:23:12 +0100 Subject: ecp5: Helper functions for distributed RAM support Signed-off-by: David Shah --- common/design_utils.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'common/design_utils.cc') diff --git a/common/design_utils.cc b/common/design_utils.cc index 7ad7f749..e3051d20 100644 --- a/common/design_utils.cc +++ b/common/design_utils.cc @@ -76,6 +76,8 @@ void print_utilisation(const Context *ctx) // 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; -- cgit v1.2.3 From a4ac174ccbc26eeef3cb49dab89658e2b5ecd90f Mon Sep 17 00:00:00 2001 From: David Shah Date: Mon, 1 Oct 2018 15:43:02 +0100 Subject: design_utils: Adding some design helper functions Signed-off-by: David Shah --- common/design_utils.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'common/design_utils.cc') diff --git a/common/design_utils.cc b/common/design_utils.cc index e3051d20..a0b87764 100644 --- a/common/design_utils.cc +++ b/common/design_utils.cc @@ -19,6 +19,7 @@ */ #include "design_utils.h" +#include #include #include "log.h" #include "util.h" @@ -95,4 +96,33 @@ void connect_port(const Context *ctx, NetInfo *net, CellInfo *cell, IdString por } } +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 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 -- cgit v1.2.3