frontend/base: Fix lookup of nets by module index

Signed-off-by: David Shah <dave@ds0.me>
This commit is contained in:
David Shah 2019-11-15 18:08:27 +00:00
parent 3e21f894f4
commit c9a0033c5c

View File

@ -298,6 +298,10 @@ template <typename FrontendType> struct GenericFrontend
// Get a net by index in modulestate (not flatindex); creating it if it doesn't already exist // Get a net by index in modulestate (not flatindex); creating it if it doesn't already exist
NetInfo *create_or_get_net(HierModuleState &m, int idx) NetInfo *create_or_get_net(HierModuleState &m, int idx)
{ {
auto &midx = m.net_by_idx(idx);
if (midx != -1) {
return net_flatindex.at(midx);
} else {
std::string name; std::string name;
if (idx < int(m.net_names.size()) && !m.net_names.at(idx).empty()) { if (idx < int(m.net_names.size()) && !m.net_names.at(idx).empty()) {
// Use the rule above to find the preferred name for a net // Use the rule above to find the preferred name for a net
@ -312,10 +316,7 @@ template <typename FrontendType> struct GenericFrontend
// Add to the flat index of nets // Add to the flat index of nets
net->udata = int(net_flatindex.size()); net->udata = int(net_flatindex.size());
net_flatindex.push_back(net); net_flatindex.push_back(net);
// Add to the module-level index of nets // Add to the module-level index of netsd
auto &midx = m.net_by_idx(idx);
// Check we don't try and create more than one net with the same index
NPNR_ASSERT(midx == -1);
midx = net->udata; midx = net->udata;
// Create aliases for all possible names // Create aliases for all possible names
if (idx < int(m.net_names.size()) && !m.net_names.at(idx).empty()) { if (idx < int(m.net_names.size()) && !m.net_names.at(idx).empty()) {
@ -330,6 +331,7 @@ template <typename FrontendType> struct GenericFrontend
} }
return net; return net;
} }
}
// Get the name of a vector bit given basename; settings and index // Get the name of a vector bit given basename; settings and index
std::string get_bit_name(const std::string &base, int index, int length, int offset = 0, bool upto = false) std::string get_bit_name(const std::string &base, int index, int length, int offset = 0, bool upto = false)