41 std::set<RTLIL::IdString> found_celltypes;
44 for (
auto i2 : i1.second->cells_)
51 for (
auto &pattern : celltypes)
53 found_celltypes.insert(cell->
type);
56 for (
auto &celltype : found_celltypes)
58 std::set<RTLIL::IdString> portnames;
59 std::set<RTLIL::IdString> parameters;
60 std::map<RTLIL::IdString, int> portwidths;
61 log(
"Generate module for cell type %s:\n", celltype.c_str());
64 for (
auto i2 : i1.second->cells_)
65 if (i2.second->type == celltype) {
66 for (
auto &conn : i2.second->connections()) {
67 if (conn.first[0] !=
'$')
68 portnames.insert(conn.first);
69 portwidths[conn.first] = std::max(portwidths[conn.first], conn.second.size());
71 for (
auto ¶ : i2.second->parameters)
72 parameters.insert(para.first);
75 for (
auto &decl : portdecls)
77 portnames.insert(decl.portname);
79 std::set<int> indices;
80 for (
int i = 0; i < int(portnames.size()); i++)
83 std::vector<generate_port_decl_t> ports(portnames.size());
85 for (
auto &decl : portdecls)
87 portwidths[decl.portname] = std::max(portwidths[decl.portname], 1);
88 portwidths[decl.portname] = std::max(portwidths[decl.portname], portwidths[
stringf(
"$%d", decl.index)]);
89 log(
" port %d: %s [%d:0] %s\n", decl.index, decl.input ? decl.output ?
"inout" :
"input" :
"output", portwidths[decl.portname]-1,
RTLIL::id2cstr(decl.portname));
90 if (indices.count(decl.index) > ports.size())
91 log_error(
"Port index (%d) exceeds number of found ports (%d).\n", decl.index,
int(ports.size()));
92 if (indices.count(decl.index) == 0)
93 log_error(
"Conflict on port index %d.\n", decl.index);
94 indices.erase(decl.index);
95 portnames.erase(decl.portname);
96 ports[decl.index-1] = decl;
99 while (portnames.size() > 0) {
101 for (
auto &decl : portdecls)
105 d.
index = *indices.begin();
107 indices.erase(d.
index);
108 ports[d.
index-1] = d;
111 goto found_matching_decl;
114 found_matching_decl:;
115 portnames.erase(portname);
121 mod->
name = celltype;
125 for (
auto &decl : ports) {
126 RTLIL::Wire *wire = mod->addWire(decl.portname, portwidths.at(decl.portname));
134 for (
auto ¶ : parameters)
std::string stringf(const char *fmt,...)
void add(RTLIL::Module *module)
static std::string unescape_id(std::string str)
void log_error(const char *format,...)
bool patmatch(const char *pattern, const char *string)
#define log_assert(_assert_expr_)
static const char * id2cstr(const RTLIL::IdString &str)
std::string substr(size_t pos=0, size_t len=std::string::npos) const
bool has(RTLIL::IdString id) const
std::map< RTLIL::IdString, RTLIL::Module * > modules_
void log(const char *format,...)