From 4a60e5842d6a39c5b1917b2a6b5f7433b08280a3 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 3 Nov 2013 09:00:51 +0100 Subject: [PATCH 1/2] Ignore explicit unconnected ports in intersynth backend --- backends/intersynth/intersynth.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backends/intersynth/intersynth.cc b/backends/intersynth/intersynth.cc index 83db8908..a3f61eeb 100644 --- a/backends/intersynth/intersynth.cc +++ b/backends/intersynth/intersynth.cc @@ -174,9 +174,11 @@ struct IntersynthBackend : public Backend { node_code = stringf("node %s %s", RTLIL::id2cstr(cell->name), RTLIL::id2cstr(cell->type)); for (auto &port : cell->connections) { RTLIL::SigSpec sig = sigmap(port.second); - conntypes_code.insert(stringf("conntype b%d %d 2 %d\n", sig.width, sig.width, sig.width)); - celltype_code += stringf(" b%d %s%s", sig.width, ct.cell_output(cell->type, port.first) ? "*" : "", RTLIL::id2cstr(port.first)); - node_code += stringf(" %s %s", RTLIL::id2cstr(port.first), netname(conntypes_code, celltypes_code, constcells_code, sig).c_str()); + if (sig.width != 0) { + conntypes_code.insert(stringf("conntype b%d %d 2 %d\n", sig.width, sig.width, sig.width)); + celltype_code += stringf(" b%d %s%s", sig.width, ct.cell_output(cell->type, port.first) ? "*" : "", RTLIL::id2cstr(port.first)); + node_code += stringf(" %s %s", RTLIL::id2cstr(port.first), netname(conntypes_code, celltypes_code, constcells_code, sig).c_str()); + } } for (auto ¶m : cell->parameters) { celltype_code += stringf(" cfg:%d %s", int(param.second.bits.size()), RTLIL::id2cstr(param.first)); From f7f0af6f9cf11c176065a97c721ccf8172439dc9 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 3 Nov 2013 09:42:51 +0100 Subject: [PATCH 2/2] Added resolution of positional arguments to hierarchy pass --- passes/hierarchy/hierarchy.cc | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/passes/hierarchy/hierarchy.cc b/passes/hierarchy/hierarchy.cc index 7d712d5e..7291aa80 100644 --- a/passes/hierarchy/hierarchy.cc +++ b/passes/hierarchy/hierarchy.cc @@ -272,6 +272,10 @@ struct HierarchyPass : public Pass { log(" also check the design hierarchy. this generates an error when\n"); log(" an unknown module is used as cell type.\n"); log("\n"); + log(" -keep_positionals\n"); + log(" per default this pass also converts positional arguments in cells\n"); + log(" to arguments using port names. this option disables this behavior.\n"); + log("\n"); log(" -top \n"); log(" use the specified top module to built a design hierarchy. modules\n"); log(" outside this tree (unused modules) are removed.\n"); @@ -301,6 +305,7 @@ struct HierarchyPass : public Pass { RTLIL::Module *top_mod = NULL; bool generate_mode = false; + bool keep_positionals = false; std::vector generate_cells; std::vector generate_ports; @@ -350,6 +355,10 @@ struct HierarchyPass : public Pass { flag_check = true; continue; } + if (args[argidx] == "-keep_positionals") { + keep_positionals = true; + continue; + } if (args[argidx] == "-top") { if (++argidx >= args.size()) log_cmd_error("Option -top requires an additional argument!\n"); @@ -398,6 +407,54 @@ struct HierarchyPass : public Pass { hierarchy(design, top_mod); } + if (!keep_positionals) + { + std::set pos_mods; + std::map, RTLIL::IdString> pos_map; + std::vector> pos_work; + + for (auto &mod_it : design->modules) + for (auto &cell_it : mod_it.second->cells) { + RTLIL::Cell *cell = cell_it.second; + if (design->modules.count(cell->type) == 0) + continue; + for (auto &conn : cell->connections) + if (conn.first[0] == '$' && '0' <= conn.first[1] && conn.first[1] <= '9') { + pos_mods.insert(design->modules.at(cell->type)); + pos_work.push_back(std::pair(mod_it.second, cell)); + break; + } + } + + for (auto module : pos_mods) + for (auto &wire_it : module->wires) { + RTLIL::Wire *wire = wire_it.second; + if (wire->port_id > 0) + pos_map[std::pair(module, wire->port_id)] = wire->name; + } + + for (auto &work : pos_work) { + RTLIL::Module *module = work.first; + RTLIL::Cell *cell = work.second; + log("Mapping positional arguments of cell %s.%s (%s).\n", + RTLIL::id2cstr(module->name), RTLIL::id2cstr(cell->name), RTLIL::id2cstr(cell->type)); + std::map new_connections; + for (auto &conn : cell->connections) + if (conn.first[0] == '$' && '0' <= conn.first[1] && conn.first[1] <= '9') { + int id = atoi(conn.first.c_str()+1); + std::pair key(design->modules.at(cell->type), id); + if (pos_map.count(key) == 0) { + log(" Failed to map positional argument %d of cell %s.%s (%s).\n", + id, RTLIL::id2cstr(module->name), RTLIL::id2cstr(cell->name), RTLIL::id2cstr(cell->type)); + new_connections[conn.first] = conn.second; + } else + new_connections[pos_map.at(key)] = conn.second; + } else + new_connections[conn.first] = conn.second; + cell->connections = new_connections; + } + } + log_pop(); } } HierarchyPass;