diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/design_utils.cc | 22 | ||||
-rw-r--r-- | common/design_utils.h | 6 |
2 files changed, 28 insertions, 0 deletions
diff --git a/common/design_utils.cc b/common/design_utils.cc index 9478afb2..7f339bac 100644 --- a/common/design_utils.cc +++ b/common/design_utils.cc @@ -164,4 +164,26 @@ void rename_net(Context *ctx, NetInfo *net, IdString new_name) net->name = new_name; } +std::vector<NetInfo *> create_bus(Context *ctx, IdString base_name, const std::string &postfix, int width) +{ + std::vector<NetInfo *> nets; + for (int i = 0; i < width; i++) + nets.push_back(ctx->createNet(ctx->id(stringf("%s/%s[%d]", base_name.c_str(ctx), postfix.c_str(), i)))); + return nets; +} + +void connect_bus(Context *ctx, CellInfo *cell, IdString port, std::vector<NetInfo *> &bus, PortType dir) +{ + for (int i = 0; i < int(bus.size()); i++) { + IdString p = ctx->id(stringf("%s%d", port.c_str(ctx), i)); + if (!cell->ports.count(p)) { + cell->ports[p].name = p; + cell->ports[p].type = dir; + } else { + NPNR_ASSERT(cell->ports.at(p).type == dir); + } + connect_port(ctx, bus.at(i), cell, p); + } +} + NEXTPNR_NAMESPACE_END diff --git a/common/design_utils.h b/common/design_utils.h index 301547c6..3a2245a7 100644 --- a/common/design_utils.h +++ b/common/design_utils.h @@ -104,6 +104,12 @@ void rename_port(Context *ctx, CellInfo *cell, IdString old_name, IdString new_n // Rename a net without invalidating pointers to it void rename_net(Context *ctx, NetInfo *net, IdString new_name); +// Create a bus of nets +std::vector<NetInfo *> create_bus(Context *ctx, IdString base_name, const std::string &postfix, int width); + +// Connect a bus of nets to a bus of ports +void connect_bus(Context *ctx, CellInfo *cell, IdString port, std::vector<NetInfo *> &bus, PortType dir); + void print_utilisation(const Context *ctx); NEXTPNR_NAMESPACE_END |