Skip to content

Commit

Permalink
Print available frontends and backends list when running synlig --help (
Browse files Browse the repository at this point in the history
chipsalliance#2688)

Fixes: chipsalliance#2669

Fragment of help message:

```
    -L logfile
        like -l but open log file in line buffered mode

    -o outfile
        write the design to the specified file on exit

    -b backend
        use this backend for the output file specified on the command line
        list of available backends: aiger, blif, btor, cxxrtl, edif, firrtl,
        ilang, intersynth, jny, json, rtlil, simplec, smt2, smv, spice, table,
        test_autotb, verilog, xaiger

    -f frontend
        use the specified frontend for the input files on the command line
        list of available frontends: aiger, blif, ilang, json, liberty, rtlil,
        systemverilog, uhdm, verilog, verilog_with_uhdm, write_file, xaiger2

    -H
        print the command list

    -h command
        print the help message for the specified command

    -s scriptfile
        execute the commands in the script file

    -c tcl_scriptfile
        execute the commands in the tcl script file (see 'help tcl' for details)
```
Message on frontend not found error:

```
list of available frontends: aiger, blif, ilang, json, liberty, rtlil,
systemverilog, uhdm, verilog, verilog_with_uhdm, write_file, xaiger2

ERROR: No such frontend: xxx
```
Message on backend not found error:

```
list of available backends: aiger, blif, btor, cxxrtl, edif, firrtl, ilang,
intersynth, jny, json, rtlil, simplec, smt2, smv, spice, table, test_autotb,
verilog, xaiger

ERROR: No such backend: xxx
```
  • Loading branch information
tgorochowik authored Nov 29, 2024
2 parents 14d7572 + b653f92 commit 10efd31
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions src/utils/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,43 @@ void shell(RTLIL::Design *design)
recursion_counter--;
log_cmd_error_throw = false;
}
std::vector<std::string> format_help_msg(std::string text, int max_len)
{
std::vector<std::string> lines;
std::string current_token = "", current_line = "";
for (char c : text + " ") {
if (c == ' ') {
if (current_token == "")
continue;
if (current_line.size() + current_token.size() + 1 <= max_len) {
if (current_line != "")
current_line += " ";
current_line += current_token;
current_token = "";
} else {
if (current_line != "")
lines.push_back(current_line);
current_line = current_token;
current_token = "";
}
} else {
current_token += c;
}
}
if (current_line != "")
lines.push_back(current_line);
return lines;
}
template <typename reg_type> std::string get_list_from_register(std::map<std::string, reg_type> reg)
{
string result = "";
for (auto reg_item : reg) {
if (reg_item != (*reg.begin()))
result += ", ";
result += reg_item.first;
}
return result;
}
}; // namespace Synlig
int main(int argc, char **argv)
{
Expand Down Expand Up @@ -334,9 +371,16 @@ int main(int argc, char **argv)
printf("\n");
printf(" -b backend\n");
printf(" use this backend for the output file specified on the command line\n");
Pass::init_register();
std::string backend_text = "list of available backends: " + Synlig::get_list_from_register<Backend *>(backend_register);
for (auto line : Synlig::format_help_msg(backend_text, 70))
printf(" %s\n", line.c_str());
printf("\n");
printf(" -f frontend\n");
printf(" use the specified frontend for the input files on the command line\n");
std::string frontend_text = "list of available frontends: " + Synlig::get_list_from_register<Frontend *>(frontend_register);
for (auto line : Synlig::format_help_msg(frontend_text, 70))
printf(" %s\n", line.c_str());
printf("\n");
printf(" -H\n");
printf(" print the command list\n");
Expand Down Expand Up @@ -635,7 +679,16 @@ int main(int argc, char **argv)
frontend_files.push_back(argv[i]);
}

if (frontend_files.size() != 0 && frontend_register.count(frontend_command) == 0 && frontend_command != "auto") {
std::string frontend_text = "list of available frontends: " + Synlig::get_list_from_register<Frontend *>(frontend_register);
for (auto line : Synlig::format_help_msg(frontend_text, 80))
printf("%s\n", line.c_str());
printf("\n");
log_error(("No such frontend: " + frontend_command + "\n").c_str());
}

for (auto it = frontend_files.begin(); it != frontend_files.end(); ++it) {

if (run_frontend((*it).c_str(), frontend_command))
run_shell = false;
}
Expand Down Expand Up @@ -675,10 +728,18 @@ int main(int argc, char **argv)
log_error("Can't exectue TCL shell: this version of yosys is not built with TCL support enabled.\n");
#endif
} else {
if (run_shell)
if (run_shell) {
Synlig::shell(yosys_design);
else
} else {
if (backend_register.count(backend_command) == 0 && backend_command != "auto") {
std::string backend_text = "list of available backends: " + Synlig::get_list_from_register<Backend *>(backend_register);
for (auto line : Synlig::format_help_msg(backend_text, 80))
printf("%s\n", line.c_str());
printf("\n");
log_error(("No such backend: " + backend_command + "\n").c_str());
}
run_backend(output_filename, backend_command);
}
}

yosys_design->check();
Expand Down

0 comments on commit 10efd31

Please sign in to comment.