Added "yosys -r <topmodule>"

Signed-off-by: Claire Xenia Wolf <claire@clairexen.net>
This commit is contained in:
Claire Xenia Wolf 2021-12-09 22:24:58 +01:00
parent 0cbdb42dcd
commit ce08046f44
3 changed files with 35 additions and 28 deletions

View File

@ -118,7 +118,7 @@ int main(int argc, char **argv)
if (argc == 2) if (argc == 2)
{ {
// Run the first argument as a script file // Run the first argument as a script file
run_frontend(argv[1], "script", 0, 0, 0); run_frontend(argv[1], "script");
} }
} }
@ -202,12 +202,13 @@ int main(int argc, char **argv)
std::string output_filename = ""; std::string output_filename = "";
std::string scriptfile = ""; std::string scriptfile = "";
std::string depsfile = ""; std::string depsfile = "";
std::string topmodule = "";
bool scriptfile_tcl = false; bool scriptfile_tcl = false;
bool got_output_filename = false;
bool print_banner = true; bool print_banner = true;
bool print_stats = true; bool print_stats = true;
bool call_abort = false; bool call_abort = false;
bool timing_details = false; bool timing_details = false;
bool run_shell = true;
bool mode_v = false; bool mode_v = false;
bool mode_q = false; bool mode_q = false;
@ -288,6 +289,9 @@ int main(int argc, char **argv)
printf(" -A\n"); printf(" -A\n");
printf(" will call abort() at the end of the script. for debugging\n"); printf(" will call abort() at the end of the script. for debugging\n");
printf("\n"); printf("\n");
printf(" -r <module_name>\n");
printf(" elaborate command line arguments using the specified top module\n");
printf("\n");
printf(" -D <macro>[=<value>]\n"); printf(" -D <macro>[=<value>]\n");
printf(" set the specified Verilog define (via \"read -define\")\n"); printf(" set the specified Verilog define (via \"read -define\")\n");
printf("\n"); printf("\n");
@ -342,7 +346,7 @@ int main(int argc, char **argv)
} }
int opt; int opt;
while ((opt = getopt(argc, argv, "MXAQTVSgm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:e:D:P:E:x:")) != -1) while ((opt = getopt(argc, argv, "MXAQTVSgm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:e:r:D:P:E:x:")) != -1)
{ {
switch (opt) switch (opt)
{ {
@ -384,13 +388,15 @@ int main(int argc, char **argv)
break; break;
case 'b': case 'b':
backend_command = optarg; backend_command = optarg;
run_shell = false;
break; break;
case 'p': case 'p':
passes_commands.push_back(optarg); passes_commands.push_back(optarg);
run_shell = false;
break; break;
case 'o': case 'o':
output_filename = optarg; output_filename = optarg;
got_output_filename = true; run_shell = false;
break; break;
case 'l': case 'l':
case 'L': case 'L':
@ -422,10 +428,12 @@ int main(int argc, char **argv)
case 's': case 's':
scriptfile = optarg; scriptfile = optarg;
scriptfile_tcl = false; scriptfile_tcl = false;
run_shell = false;
break; break;
case 'c': case 'c':
scriptfile = optarg; scriptfile = optarg;
scriptfile_tcl = true; scriptfile_tcl = true;
run_shell = false;
break; break;
case 'W': case 'W':
log_warn_regexes.push_back(YS_REGEX_COMPILE(optarg)); log_warn_regexes.push_back(YS_REGEX_COMPILE(optarg));
@ -436,6 +444,9 @@ int main(int argc, char **argv)
case 'e': case 'e':
log_werror_regexes.push_back(YS_REGEX_COMPILE(optarg)); log_werror_regexes.push_back(YS_REGEX_COMPILE(optarg));
break; break;
case 'r':
topmodule = optarg;
break;
case 'D': case 'D':
vlog_defines.push_back(optarg); vlog_defines.push_back(optarg);
break; break;
@ -506,12 +517,6 @@ int main(int argc, char **argv)
for (auto &fn : plugin_filenames) for (auto &fn : plugin_filenames)
load_plugin(fn, {}); load_plugin(fn, {});
if (optind == argc && passes_commands.size() == 0 && scriptfile.empty()) {
if (!got_output_filename)
backend_command = "";
shell(yosys_design);
}
if (!vlog_defines.empty()) { if (!vlog_defines.empty()) {
std::string vdef_cmd = "read -define"; std::string vdef_cmd = "read -define";
for (auto vdef : vlog_defines) for (auto vdef : vlog_defines)
@ -520,7 +525,11 @@ int main(int argc, char **argv)
} }
while (optind < argc) while (optind < argc)
run_frontend(argv[optind++], frontend_command, output_filename == "-" ? &backend_command : NULL); if (run_frontend(argv[optind++], frontend_command))
run_shell = false;
if (!topmodule.empty())
run_pass("hierarchy -top " + topmodule);
if (!scriptfile.empty()) { if (!scriptfile.empty()) {
if (scriptfile_tcl) { if (scriptfile_tcl) {
@ -531,13 +540,15 @@ int main(int argc, char **argv)
log_error("Can't exectue TCL script: this version of yosys is not built with TCL support enabled.\n"); log_error("Can't exectue TCL script: this version of yosys is not built with TCL support enabled.\n");
#endif #endif
} else } else
run_frontend(scriptfile, "script", output_filename == "-" ? &backend_command : NULL); run_frontend(scriptfile, "script");
} }
for (auto it = passes_commands.begin(); it != passes_commands.end(); it++) for (auto it = passes_commands.begin(); it != passes_commands.end(); it++)
run_pass(*it); run_pass(*it);
if (!backend_command.empty()) if (run_shell)
shell(yosys_design);
else
run_backend(output_filename, backend_command); run_backend(output_filename, backend_command);
yosys_design->check(); yosys_design->check();

View File

@ -956,7 +956,7 @@ static void handle_label(std::string &command, bool &from_to_active, const std::
} }
} }
void run_frontend(std::string filename, std::string command, std::string *backend_command, std::string *from_to_label, RTLIL::Design *design) bool run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *from_to_label)
{ {
if (design == nullptr) if (design == nullptr)
design = yosys_design; design = yosys_design;
@ -1056,10 +1056,12 @@ void run_frontend(std::string filename, std::string command, std::string *backen
if (filename != "-") if (filename != "-")
fclose(f); fclose(f);
if (backend_command != NULL && *backend_command == "auto") return true;
*backend_command = ""; }
return; if (command == "tcl") {
Pass::call(design, vector<string>({command, filename}));
return true;
} }
if (filename == "-") { if (filename == "-") {
@ -1068,20 +1070,15 @@ void run_frontend(std::string filename, std::string command, std::string *backen
log("\n-- Parsing `%s' using frontend `%s' --\n", filename.c_str(), command.c_str()); log("\n-- Parsing `%s' using frontend `%s' --\n", filename.c_str(), command.c_str());
} }
if (command == "tcl") if (command[0] == ' ') {
Pass::call(design, vector<string>({command, filename}));
else if (command[0] == ' ') {
auto argv = split_tokens("read" + command); auto argv = split_tokens("read" + command);
argv.push_back(filename); argv.push_back(filename);
Pass::call(design, argv); Pass::call(design, argv);
} else } else
Frontend::frontend_call(design, NULL, filename, command); Frontend::frontend_call(design, NULL, filename, command);
design->check();
}
void run_frontend(std::string filename, std::string command, RTLIL::Design *design) design->check();
{ return false;
run_frontend(filename, command, nullptr, nullptr, design);
} }
void run_pass(std::string command, RTLIL::Design *design) void run_pass(std::string command, RTLIL::Design *design)
@ -1395,7 +1392,7 @@ struct ScriptCmdPass : public Pass {
else if (args.size() == 2) else if (args.size() == 2)
run_frontend(args[1], "script", design); run_frontend(args[1], "script", design);
else if (args.size() == 3) else if (args.size() == 3)
run_frontend(args[1], "script", NULL, &args[2], design); run_frontend(args[1], "script", design, &args[2]);
else else
extra_args(args, 2, design, false); extra_args(args, 2, design, false);
} }

View File

@ -347,8 +347,7 @@ std::vector<std::string> glob_filename(const std::string &filename_pattern);
void rewrite_filename(std::string &filename); void rewrite_filename(std::string &filename);
void run_pass(std::string command, RTLIL::Design *design = nullptr); void run_pass(std::string command, RTLIL::Design *design = nullptr);
void run_frontend(std::string filename, std::string command, std::string *backend_command, std::string *from_to_label = nullptr, RTLIL::Design *design = nullptr); bool run_frontend(std::string filename, std::string command, RTLIL::Design *design = nullptr, std::string *from_to_label = nullptr);
void run_frontend(std::string filename, std::string command, RTLIL::Design *design = nullptr);
void run_backend(std::string filename, std::string command, RTLIL::Design *design = nullptr); void run_backend(std::string filename, std::string command, RTLIL::Design *design = nullptr);
void shell(RTLIL::Design *design); void shell(RTLIL::Design *design);