Skip to content

Commit

Permalink
kernel: call hierarchy for abstract modules automatically.
Browse files Browse the repository at this point in the history
Whenever there are abstract modules in the netlist and the pass does not
declare that it supports them, call `hierarchy -auto-top` or `hierarchy`
(depending on whether there is a module marked `top`) to instantiate
them first. This makes several CLI workflows much more usable, including
one as basic as:

    $ yosys file.v -o file.il
  • Loading branch information
whitequark committed Dec 21, 2023
1 parent 1c8e58a commit d2f3d07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions kernel/register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ Pass::~Pass()

Pass::pre_post_exec_state_t Pass::pre_execute()
{
if (!abstract_modules_ok) {
bool has_top = false;
bool has_abstract = false;
for (auto mod : yosys_design->modules()) {
if (mod->get_bool_attribute(ID::top))
has_top = true;
if (mod->name.begins_with("$abstract"))
has_abstract = true;
}
if (has_abstract) {
std::string command = has_top ? "hierarchy" : "hierarchy -auto-top";
log_warning("Pass `%s` does not accept abstract modules; running `%s` first!\n", pass_name.c_str(), command.c_str());
run_pass(command);
}
}

pre_post_exec_state_t state;
call_counter++;
state.begin_ns = PerformanceTimer::query();
Expand Down Expand Up @@ -443,6 +459,7 @@ Frontend::Frontend(std::string name, std::string short_help) :
Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "read_" + name, short_help),
frontend_name(name.rfind("=", 0) == 0 ? name.substr(1) : name)
{
abstract_modules_ok = true;
}

void Frontend::run_register()
Expand Down
7 changes: 6 additions & 1 deletion kernel/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct Pass
int call_counter;
int64_t runtime_ns;
bool experimental_flag = false;
bool abstract_modules_ok = false;

void experimental() {
experimental_flag = true;
Expand Down Expand Up @@ -78,7 +79,11 @@ struct ScriptPass : Pass
RTLIL::Design *active_design;
std::string active_run_from, active_run_to;

ScriptPass(std::string name, std::string short_help = "** document me **") : Pass(name, short_help) { }
ScriptPass(std::string name, std::string short_help = "** document me **") : Pass(name, short_help) {
// Either the script pass will include an explicit `hierarchy` invocation or one of the passes called inside will
// trigger the check for abstract modules.
abstract_modules_ok = true;
}

virtual void script() = 0;

Expand Down
2 changes: 1 addition & 1 deletion passes/hierarchy/hierarchy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ RTLIL::Wire *find_implicit_port_wire(Module *module, Cell *cell, const std::stri
}

struct HierarchyPass : public Pass {
HierarchyPass() : Pass("hierarchy", "check, expand and clean up design hierarchy") { }
HierarchyPass() : Pass("hierarchy", "check, expand and clean up design hierarchy") { abstract_modules_ok = true; }
void help() override
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
Expand Down

0 comments on commit d2f3d07

Please sign in to comment.