372 log_header(
"Executing HIERARCHY pass (managing design hierarchy).\n");
374 bool flag_check =
false;
375 bool purge_lib =
false;
377 std::vector<std::string> libdirs;
379 bool generate_mode =
false;
380 bool keep_positionals =
false;
381 bool nokeep_asserts =
false;
382 std::vector<std::string> generate_cells;
383 std::vector<generate_port_decl_t> generate_ports;
386 for (argidx = 1; argidx <
args.size(); argidx++)
388 if (
args[argidx] ==
"-generate" && !flag_check && !top_mod) {
389 generate_mode =
true;
390 log(
"Entering generate mode.\n");
391 while (++argidx <
args.size()) {
392 const char *p =
args[argidx].c_str();
394 if (p[0] ==
'i' && p[1] ==
'o')
404 decl.
index = strtol(++p, &endptr, 10);
415 log(
"Port declaration: %s", decl.
input ? decl.
output ?
"inout" :
"input" :
"output");
417 log(
" [at position %d]", decl.
index);
419 generate_ports.push_back(decl);
422 log(
"Celltype: %s\n",
args[argidx].c_str());
427 if (
args[argidx] ==
"-check") {
431 if (
args[argidx] ==
"-purge_lib") {
435 if (
args[argidx] ==
"-keep_positionals") {
436 keep_positionals =
true;
439 if (
args[argidx] ==
"-nokeep_asserts") {
440 nokeep_asserts =
true;
443 if (
args[argidx] ==
"-libdir" && argidx+1 <
args.size()) {
444 libdirs.push_back(
args[++argidx]);
447 if (
args[argidx] ==
"-top") {
448 if (++argidx >=
args.size())
449 log_cmd_error(
"Option -top requires an additional argument!\n");
452 std::map<RTLIL::IdString, RTLIL::Const> empty_parameters;
465 generate(design, generate_cells, generate_ports);
472 for (
auto &mod_it : design->
modules_)
473 if (mod_it.second->get_bool_attribute(
"\\top"))
474 top_mod = mod_it.second;
477 hierarchy(design, top_mod, purge_lib,
true);
480 bool did_something_once =
false;
481 while (did_something) {
482 did_something =
false;
483 std::vector<RTLIL::IdString> modnames;
484 modnames.reserve(design->
modules_.size());
485 for (
auto &mod_it : design->
modules_)
486 modnames.push_back(mod_it.first);
487 for (
auto &modname : modnames) {
488 if (design->
modules_.count(modname) == 0)
491 did_something =
true;
494 did_something_once =
true;
497 if (top_mod !=
NULL && did_something_once) {
498 log_header(
"Re-running hierarchy analysis..\n");
499 hierarchy(design, top_mod, purge_lib,
false);
502 if (top_mod !=
NULL) {
503 for (
auto &mod_it : design->
modules_)
504 if (mod_it.second == top_mod)
507 mod_it.second->attributes.erase(
"\\top");
510 if (!nokeep_asserts) {
511 std::map<RTLIL::Module*, bool> cache;
512 for (
auto mod : design->
modules())
514 log(
"Module %s directly or indirectly contains $assert cells -> setting \"keep\" attribute.\n",
log_id(mod));
515 mod->set_bool_attribute(
"\\keep");
519 if (!keep_positionals)
521 std::set<RTLIL::Module*> pos_mods;
523 std::vector<std::pair<RTLIL::Module*,RTLIL::Cell*>> pos_work;
525 for (
auto &mod_it : design->
modules_)
526 for (
auto &cell_it : mod_it.second->cells_) {
531 if (conn.first[0] ==
'$' &&
'0' <= conn.first[1] && conn.first[1] <=
'9') {
533 pos_work.push_back(std::pair<RTLIL::Module*,RTLIL::Cell*>(mod_it.second, cell));
538 for (
auto module : pos_mods)
545 for (
auto &work : pos_work) {
548 log(
"Mapping positional arguments of cell %s.%s (%s).\n",
550 std::map<RTLIL::IdString, RTLIL::SigSpec> new_connections;
552 if (conn.first[0] ==
'$' &&
'0' <= conn.first[1] && conn.first[1] <=
'9') {
553 int id = atoi(conn.first.c_str()+1);
554 std::pair<RTLIL::Module*,int> key(design->
modules_.at(cell->
type),
id);
555 if (pos_map.count(key) == 0) {
556 log(
" Failed to map positional argument %d of cell %s.%s (%s).\n",
558 new_connections[conn.first] = conn.second;
560 new_connections[pos_map.at(key)] = conn.second;
562 new_connections[conn.first] = conn.second;
const char * c_str() const
void log_header(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
static std::string unescape_id(std::string str)
static std::string escape_id(std::string str)
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool did_something
bool set_keep_assert(std::map< RTLIL::Module *, bool > &cache, RTLIL::Module *mod)
bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check, std::vector< std::string > &libdirs)
static const char * id2cstr(const RTLIL::IdString &str)
void log_cmd_error(const char *format,...)
RTLIL::ObjRange< RTLIL::Module * > modules()
std::map< RTLIL::IdString, RTLIL::Module * > modules_
void log(const char *format,...)
std::map< RTLIL::IdString, RTLIL::SigSpec > connections_
std::string id(RTLIL::IdString internal_id, bool may_rename=true)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
void hierarchy(RTLIL::Design *design, RTLIL::Module *top, bool purge_lib, bool first_pass)
const char * log_id(RTLIL::IdString str)
void generate(RTLIL::Design *design, const std::vector< std::string > &celltypes, const std::vector< generate_port_decl_t > &portdecls)