Skip to content

Commit 10efd31

Browse files
authored
Print available frontends and backends list when running synlig --help (#2688)
Fixes: #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 ```
2 parents 14d7572 + b653f92 commit 10efd31

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

Diff for: src/utils/main.cc

+63-2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,43 @@ void shell(RTLIL::Design *design)
275275
recursion_counter--;
276276
log_cmd_error_throw = false;
277277
}
278+
std::vector<std::string> format_help_msg(std::string text, int max_len)
279+
{
280+
std::vector<std::string> lines;
281+
std::string current_token = "", current_line = "";
282+
for (char c : text + " ") {
283+
if (c == ' ') {
284+
if (current_token == "")
285+
continue;
286+
if (current_line.size() + current_token.size() + 1 <= max_len) {
287+
if (current_line != "")
288+
current_line += " ";
289+
current_line += current_token;
290+
current_token = "";
291+
} else {
292+
if (current_line != "")
293+
lines.push_back(current_line);
294+
current_line = current_token;
295+
current_token = "";
296+
}
297+
} else {
298+
current_token += c;
299+
}
300+
}
301+
if (current_line != "")
302+
lines.push_back(current_line);
303+
return lines;
304+
}
305+
template <typename reg_type> std::string get_list_from_register(std::map<std::string, reg_type> reg)
306+
{
307+
string result = "";
308+
for (auto reg_item : reg) {
309+
if (reg_item != (*reg.begin()))
310+
result += ", ";
311+
result += reg_item.first;
312+
}
313+
return result;
314+
}
278315
}; // namespace Synlig
279316
int main(int argc, char **argv)
280317
{
@@ -334,9 +371,16 @@ int main(int argc, char **argv)
334371
printf("\n");
335372
printf(" -b backend\n");
336373
printf(" use this backend for the output file specified on the command line\n");
374+
Pass::init_register();
375+
std::string backend_text = "list of available backends: " + Synlig::get_list_from_register<Backend *>(backend_register);
376+
for (auto line : Synlig::format_help_msg(backend_text, 70))
377+
printf(" %s\n", line.c_str());
337378
printf("\n");
338379
printf(" -f frontend\n");
339380
printf(" use the specified frontend for the input files on the command line\n");
381+
std::string frontend_text = "list of available frontends: " + Synlig::get_list_from_register<Frontend *>(frontend_register);
382+
for (auto line : Synlig::format_help_msg(frontend_text, 70))
383+
printf(" %s\n", line.c_str());
340384
printf("\n");
341385
printf(" -H\n");
342386
printf(" print the command list\n");
@@ -635,7 +679,16 @@ int main(int argc, char **argv)
635679
frontend_files.push_back(argv[i]);
636680
}
637681

682+
if (frontend_files.size() != 0 && frontend_register.count(frontend_command) == 0 && frontend_command != "auto") {
683+
std::string frontend_text = "list of available frontends: " + Synlig::get_list_from_register<Frontend *>(frontend_register);
684+
for (auto line : Synlig::format_help_msg(frontend_text, 80))
685+
printf("%s\n", line.c_str());
686+
printf("\n");
687+
log_error(("No such frontend: " + frontend_command + "\n").c_str());
688+
}
689+
638690
for (auto it = frontend_files.begin(); it != frontend_files.end(); ++it) {
691+
639692
if (run_frontend((*it).c_str(), frontend_command))
640693
run_shell = false;
641694
}
@@ -675,10 +728,18 @@ int main(int argc, char **argv)
675728
log_error("Can't exectue TCL shell: this version of yosys is not built with TCL support enabled.\n");
676729
#endif
677730
} else {
678-
if (run_shell)
731+
if (run_shell) {
679732
Synlig::shell(yosys_design);
680-
else
733+
} else {
734+
if (backend_register.count(backend_command) == 0 && backend_command != "auto") {
735+
std::string backend_text = "list of available backends: " + Synlig::get_list_from_register<Backend *>(backend_register);
736+
for (auto line : Synlig::format_help_msg(backend_text, 80))
737+
printf("%s\n", line.c_str());
738+
printf("\n");
739+
log_error(("No such backend: " + backend_command + "\n").c_str());
740+
}
681741
run_backend(output_filename, backend_command);
742+
}
682743
}
683744

684745
yosys_design->check();

0 commit comments

Comments
 (0)