2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "kernel/yosys.h"
21 #include "kernel/satgen.h"
28 #ifdef YOSYS_ENABLE_ZLIB
31 PRIVATE_NAMESPACE_BEGIN
32 #define GZ_BUFFER_SIZE 8192
33 void decompress_gzip(const std::string
&filename
, std::stringstream
&out
)
35 char buffer
[GZ_BUFFER_SIZE
];
37 gzFile gzf
= gzopen(filename
.c_str(), "rb");
39 bytes_read
= gzread(gzf
, reinterpret_cast<void *>(buffer
), GZ_BUFFER_SIZE
);
40 out
.write(buffer
, bytes_read
);
46 An output stream that uses a stringbuf to buffer data internally,
47 using zlib to write gzip-compressed data every time the stream is flushed.
49 class gzip_ostream
: public std::ostream
{
51 gzip_ostream() : std::ostream(nullptr)
55 bool open(const std::string
&filename
)
57 return outbuf
.open(filename
);
60 class gzip_streambuf
: public std::stringbuf
{
63 bool open(const std::string
&filename
)
65 gzf
= gzopen(filename
.c_str(), "wb");
66 return gzf
!= nullptr;
68 virtual int sync() override
70 gzwrite(gzf
, reinterpret_cast<const void *>(str().c_str()), unsigned(str().size()));
74 virtual ~gzip_streambuf()
89 #define MAX_REG_COUNT 1000
91 bool echo_mode
= false;
92 Pass
*first_queued_pass
;
95 std::map
<std::string
, Frontend
*> frontend_register
;
96 std::map
<std::string
, Pass
*> pass_register
;
97 std::map
<std::string
, Backend
*> backend_register
;
99 std::vector
<std::string
> Frontend::next_args
;
101 Pass::Pass(std::string name
, std::string short_help
) : pass_name(name
), short_help(short_help
)
103 next_queued_pass
= first_queued_pass
;
104 first_queued_pass
= this;
109 void Pass::run_register()
111 log_assert(pass_register
.count(pass_name
) == 0);
112 pass_register
[pass_name
] = this;
115 void Pass::init_register()
117 vector
<Pass
*> added_passes
;
118 while (first_queued_pass
) {
119 added_passes
.push_back(first_queued_pass
);
120 first_queued_pass
->run_register();
121 first_queued_pass
= first_queued_pass
->next_queued_pass
;
123 for (auto added_pass
: added_passes
)
124 added_pass
->on_register();
127 void Pass::done_register()
129 for (auto &it
: pass_register
)
130 it
.second
->on_shutdown();
132 frontend_register
.clear();
133 pass_register
.clear();
134 backend_register
.clear();
135 log_assert(first_queued_pass
== NULL
);
138 void Pass::on_register()
142 void Pass::on_shutdown()
150 Pass::pre_post_exec_state_t
Pass::pre_execute()
152 pre_post_exec_state_t state
;
154 state
.begin_ns
= PerformanceTimer::query();
155 state
.parent_pass
= current_pass
;
161 void Pass::post_execute(Pass::pre_post_exec_state_t state
)
163 IdString::checkpoint();
166 int64_t time_ns
= PerformanceTimer::query() - state
.begin_ns
;
167 runtime_ns
+= time_ns
;
168 current_pass
= state
.parent_pass
;
170 current_pass
->runtime_ns
-= time_ns
;
176 log("No help message for command `%s'.\n", pass_name
.c_str());
180 void Pass::clear_flags()
184 void Pass::cmd_log_args(const std::vector
<std::string
> &args
)
186 if (args
.size() <= 1)
188 log("Full command line:");
189 for (size_t i
= 0; i
< args
.size(); i
++)
190 log(" %s", args
[i
].c_str());
194 void Pass::cmd_error(const std::vector
<std::string
> &args
, size_t argidx
, std::string msg
)
196 std::string command_text
;
199 for (size_t i
= 0; i
< args
.size(); i
++) {
201 error_pos
+= args
[i
].size() + 1;
202 command_text
= command_text
+ (command_text
.empty() ? "" : " ") + args
[i
];
205 log("\nSyntax error in command `%s':\n", command_text
.c_str());
208 log_cmd_error("Command syntax error: %s\n> %s\n> %*s^\n",
209 msg
.c_str(), command_text
.c_str(), error_pos
, "");
212 void Pass::extra_args(std::vector
<std::string
> args
, size_t argidx
, RTLIL::Design
*design
, bool select
)
214 for (; argidx
< args
.size(); argidx
++)
216 std::string arg
= args
[argidx
];
218 if (arg
.compare(0, 1, "-") == 0)
219 cmd_error(args
, argidx
, "Unknown option or option in arguments.");
222 cmd_error(args
, argidx
, "Extra argument.");
224 handle_extra_select_args(this, args
, argidx
, args
.size(), design
);
227 // cmd_log_args(args);
230 void Pass::call(RTLIL::Design
*design
, std::string command
)
232 std::vector
<std::string
> args
;
234 std::string cmd_buf
= command
;
235 std::string tok
= next_token(cmd_buf
, " \t\r\n", true);
241 cmd_buf
= command
.substr(command
.find('!') + 1);
242 while (!cmd_buf
.empty() && (cmd_buf
.back() == ' ' || cmd_buf
.back() == '\t' ||
243 cmd_buf
.back() == '\r' || cmd_buf
.back() == '\n'))
244 cmd_buf
.resize(cmd_buf
.size()-1);
245 log_header(design
, "Shell command: %s\n", cmd_buf
.c_str());
246 int retCode
= run_command(cmd_buf
);
248 log_cmd_error("Shell command returned error code %d.\n", retCode
);
252 while (!tok
.empty()) {
255 for (stop
= 0; stop
< GetSize(cmd_buf
); stop
++)
256 if (cmd_buf
[stop
] == '\r' || cmd_buf
[stop
] == '\n')
258 cmd_buf
= cmd_buf
.substr(stop
);
260 if (tok
.back() == ';') {
261 int num_semikolon
= 0;
262 while (!tok
.empty() && tok
.back() == ';')
263 tok
.resize(tok
.size()-1), num_semikolon
++;
268 if (num_semikolon
== 2)
269 call(design
, "clean");
270 if (num_semikolon
== 3)
271 call(design
, "clean -purge");
274 bool found_nl
= false;
275 for (auto c
: cmd_buf
) {
276 if (c
== ' ' || c
== '\t')
278 if (c
== '\r' || c
== '\n')
286 tok
= next_token(cmd_buf
, " \t\r\n", true);
292 void Pass::call(RTLIL::Design
*design
, std::vector
<std::string
> args
)
294 if (args
.size() == 0 || args
[0][0] == '#' || args
[0][0] == ':')
298 log("%s", create_prompt(design
, 0));
299 for (size_t i
= 0; i
< args
.size(); i
++)
300 log("%s%s", i
? " " : "", args
[i
].c_str());
304 if (pass_register
.count(args
[0]) == 0)
305 log_cmd_error("No such command: %s (type 'help' for a command overview)\n", args
[0].c_str());
307 if (pass_register
[args
[0]]->experimental_flag
)
308 log_experimental("%s", args
[0].c_str());
310 size_t orig_sel_stack_pos
= design
->selection_stack
.size();
311 auto state
= pass_register
[args
[0]]->pre_execute();
312 pass_register
[args
[0]]->execute(args
, design
);
313 pass_register
[args
[0]]->post_execute(state
);
314 while (design
->selection_stack
.size() > orig_sel_stack_pos
)
315 design
->selection_stack
.pop_back();
318 void Pass::call_on_selection(RTLIL::Design
*design
, const RTLIL::Selection
&selection
, std::string command
)
320 std::string backup_selected_active_module
= design
->selected_active_module
;
321 design
->selected_active_module
.clear();
322 design
->selection_stack
.push_back(selection
);
324 Pass::call(design
, command
);
326 design
->selection_stack
.pop_back();
327 design
->selected_active_module
= backup_selected_active_module
;
330 void Pass::call_on_selection(RTLIL::Design
*design
, const RTLIL::Selection
&selection
, std::vector
<std::string
> args
)
332 std::string backup_selected_active_module
= design
->selected_active_module
;
333 design
->selected_active_module
.clear();
334 design
->selection_stack
.push_back(selection
);
336 Pass::call(design
, args
);
338 design
->selection_stack
.pop_back();
339 design
->selected_active_module
= backup_selected_active_module
;
342 void Pass::call_on_module(RTLIL::Design
*design
, RTLIL::Module
*module
, std::string command
)
344 std::string backup_selected_active_module
= design
->selected_active_module
;
345 design
->selected_active_module
= module
->name
.str();
346 design
->selection_stack
.push_back(RTLIL::Selection(false));
347 design
->selection_stack
.back().select(module
);
349 Pass::call(design
, command
);
351 design
->selection_stack
.pop_back();
352 design
->selected_active_module
= backup_selected_active_module
;
355 void Pass::call_on_module(RTLIL::Design
*design
, RTLIL::Module
*module
, std::vector
<std::string
> args
)
357 std::string backup_selected_active_module
= design
->selected_active_module
;
358 design
->selected_active_module
= module
->name
.str();
359 design
->selection_stack
.push_back(RTLIL::Selection(false));
360 design
->selection_stack
.back().select(module
);
362 Pass::call(design
, args
);
364 design
->selection_stack
.pop_back();
365 design
->selected_active_module
= backup_selected_active_module
;
368 bool ScriptPass::check_label(std::string label
, std::string info
)
370 if (active_design
== nullptr) {
373 log(" %s:\n", label
.c_str());
375 log(" %s: %s\n", label
.c_str(), info
.c_str());
378 if (!active_run_from
.empty() && active_run_from
== active_run_to
) {
379 block_active
= (label
== active_run_from
);
381 if (label
== active_run_from
)
383 if (label
== active_run_to
)
384 block_active
= false;
390 void ScriptPass::run(std::string command
, std::string info
)
392 if (active_design
== nullptr) {
394 log(" %s\n", command
.c_str());
396 log(" %s %s\n", command
.c_str(), info
.c_str());
398 Pass::call(active_design
, command
);
399 active_design
->check();
403 void ScriptPass::run_nocheck(std::string command
, std::string info
)
405 if (active_design
== nullptr) {
407 log(" %s\n", command
.c_str());
409 log(" %s %s\n", command
.c_str(), info
.c_str());
411 Pass::call(active_design
, command
);
415 void ScriptPass::run_script(RTLIL::Design
*design
, std::string run_from
, std::string run_to
)
418 active_design
= design
;
419 block_active
= run_from
.empty();
420 active_run_from
= run_from
;
421 active_run_to
= run_to
;
425 void ScriptPass::help_script()
429 active_design
= nullptr;
431 active_run_from
.clear();
432 active_run_to
.clear();
436 Frontend::Frontend(std::string name
, std::string short_help
) :
437 Pass(name
.rfind("=", 0) == 0 ? name
.substr(1) : "read_" + name
, short_help
),
438 frontend_name(name
.rfind("=", 0) == 0 ? name
.substr(1) : name
)
442 void Frontend::run_register()
444 log_assert(pass_register
.count(pass_name
) == 0);
445 pass_register
[pass_name
] = this;
447 log_assert(frontend_register
.count(frontend_name
) == 0);
448 frontend_register
[frontend_name
] = this;
451 Frontend::~Frontend()
455 void Frontend::execute(std::vector
<std::string
> args
, RTLIL::Design
*design
)
457 log_assert(next_args
.empty());
459 std::istream
*f
= NULL
;
461 auto state
= pre_execute();
462 execute(f
, std::string(), args
, design
);
466 } while (!args
.empty());
469 FILE *Frontend::current_script_file
= NULL
;
470 std::string
Frontend::last_here_document
;
472 void Frontend::extra_args(std::istream
*&f
, std::string
&filename
, std::vector
<std::string
> args
, size_t argidx
, bool bin_input
)
474 bool called_with_fp
= f
!= NULL
;
478 if (argidx
< args
.size())
480 std::string arg
= args
[argidx
];
482 if (arg
.compare(0, 1, "-") == 0)
483 cmd_error(args
, argidx
, "Unknown option or option in arguments.");
485 cmd_error(args
, argidx
, "Extra filename argument in direct file mode.");
488 if (filename
== "<<" && argidx
+1 < args
.size())
489 filename
+= args
[++argidx
];
490 if (filename
.compare(0, 2, "<<") == 0) {
491 if (Frontend::current_script_file
== NULL
)
492 log_error("Unexpected here document '%s' outside of script!\n", filename
.c_str());
493 if (filename
.size() <= 2)
494 log_error("Missing EOT marker in here document!\n");
495 std::string eot_marker
= filename
.substr(2);
496 last_here_document
.clear();
501 if (fgets(block
, 4096, Frontend::current_script_file
) == NULL
)
502 log_error("Unexpected end of file in here document '%s'!\n", filename
.c_str());
504 if (buffer
.size() > 0 && (buffer
[buffer
.size() - 1] == '\n' || buffer
[buffer
.size() - 1] == '\r'))
507 size_t indent
= buffer
.find_first_not_of(" \t\r\n");
508 if (indent
!= std::string::npos
&& buffer
.compare(indent
, eot_marker
.size(), eot_marker
) == 0)
510 last_here_document
+= buffer
;
512 f
= new std::istringstream(last_here_document
);
514 rewrite_filename(filename
);
515 vector
<string
> filenames
= glob_filename(filename
);
516 filename
= filenames
.front();
517 if (GetSize(filenames
) > 1) {
518 next_args
.insert(next_args
.end(), args
.begin(), args
.begin()+argidx
);
519 next_args
.insert(next_args
.end(), filenames
.begin()+1, filenames
.end());
521 std::ifstream
*ff
= new std::ifstream
;
522 ff
->open(filename
.c_str(), bin_input
? std::ifstream::binary
: std::ifstream::in
);
523 yosys_input_files
.insert(filename
);
529 // Check for gzip magic
530 unsigned char magic
[3];
536 magic
[n
] = (unsigned char) c
;
540 if (n
== 3 && magic
[0] == 0x1f && magic
[1] == 0x8b) {
541 #ifdef YOSYS_ENABLE_ZLIB
542 log("Found gzip magic in file `%s', decompressing using zlib.\n", filename
.c_str());
544 log_cmd_error("gzip file `%s' uses unsupported compression type %02x\n",
545 filename
.c_str(), unsigned(magic
[2]));
547 std::stringstream
*df
= new std::stringstream();
548 decompress_gzip(filename
, *df
);
551 log_cmd_error("File `%s' is a gzip file, but Yosys is compiled without zlib.\n", filename
.c_str());
555 ff
->seekg(0, std::ios::beg
);
560 log_cmd_error("Can't open input file `%s' for reading: %s\n", filename
.c_str(), strerror(errno
));
562 for (size_t i
= argidx
+1; i
< args
.size(); i
++)
563 if (args
[i
].compare(0, 1, "-") == 0)
564 cmd_error(args
, i
, "Found option, expected arguments.");
566 if (argidx
+1 < args
.size()) {
567 if (next_args
.empty())
568 next_args
.insert(next_args
.end(), args
.begin(), args
.begin()+argidx
);
569 next_args
.insert(next_args
.end(), args
.begin()+argidx
+1, args
.end());
570 args
.erase(args
.begin()+argidx
+1, args
.end());
575 cmd_error(args
, argidx
, "No filename given.");
578 args
.push_back(filename
);
580 // cmd_log_args(args);
583 void Frontend::frontend_call(RTLIL::Design
*design
, std::istream
*f
, std::string filename
, std::string command
)
585 std::vector
<std::string
> args
;
586 char *s
= strdup(command
.c_str());
587 for (char *p
= strtok(s
, " \t\r\n"); p
; p
= strtok(NULL
, " \t\r\n"))
590 frontend_call(design
, f
, filename
, args
);
593 void Frontend::frontend_call(RTLIL::Design
*design
, std::istream
*f
, std::string filename
, std::vector
<std::string
> args
)
595 if (args
.size() == 0)
597 if (frontend_register
.count(args
[0]) == 0)
598 log_cmd_error("No such frontend: %s\n", args
[0].c_str());
601 auto state
= frontend_register
[args
[0]]->pre_execute();
602 frontend_register
[args
[0]]->execute(f
, filename
, args
, design
);
603 frontend_register
[args
[0]]->post_execute(state
);
604 } else if (filename
== "-") {
605 std::istream
*f_cin
= &std::cin
;
606 auto state
= frontend_register
[args
[0]]->pre_execute();
607 frontend_register
[args
[0]]->execute(f_cin
, "<stdin>", args
, design
);
608 frontend_register
[args
[0]]->post_execute(state
);
610 if (!filename
.empty())
611 args
.push_back(filename
);
612 frontend_register
[args
[0]]->execute(args
, design
);
616 Backend::Backend(std::string name
, std::string short_help
) :
617 Pass(name
.rfind("=", 0) == 0 ? name
.substr(1) : "write_" + name
, short_help
),
618 backend_name(name
.rfind("=", 0) == 0 ? name
.substr(1) : name
)
622 void Backend::run_register()
624 log_assert(pass_register
.count(pass_name
) == 0);
625 pass_register
[pass_name
] = this;
627 log_assert(backend_register
.count(backend_name
) == 0);
628 backend_register
[backend_name
] = this;
635 void Backend::execute(std::vector
<std::string
> args
, RTLIL::Design
*design
)
637 std::ostream
*f
= NULL
;
638 auto state
= pre_execute();
639 execute(f
, std::string(), args
, design
);
645 void Backend::extra_args(std::ostream
*&f
, std::string
&filename
, std::vector
<std::string
> args
, size_t argidx
, bool bin_output
)
647 bool called_with_fp
= f
!= NULL
;
649 for (; argidx
< args
.size(); argidx
++)
651 std::string arg
= args
[argidx
];
653 if (arg
.compare(0, 1, "-") == 0 && arg
!= "-")
654 cmd_error(args
, argidx
, "Unknown option or option in arguments.");
656 cmd_error(args
, argidx
, "Extra filename argument in direct file mode.");
659 filename
= "<stdout>";
665 rewrite_filename(filename
);
666 if (filename
.size() > 3 && filename
.compare(filename
.size()-3, std::string::npos
, ".gz") == 0) {
667 #ifdef YOSYS_ENABLE_ZLIB
668 gzip_ostream
*gf
= new gzip_ostream
;
669 if (!gf
->open(filename
)) {
671 log_cmd_error("Can't open output file `%s' for writing: %s\n", filename
.c_str(), strerror(errno
));
673 yosys_output_files
.insert(filename
);
676 log_cmd_error("Yosys is compiled without zlib support, unable to write gzip output.\n");
679 std::ofstream
*ff
= new std::ofstream
;
680 ff
->open(filename
.c_str(), bin_output
? (std::ofstream::trunc
| std::ofstream::binary
) : std::ofstream::trunc
);
681 yosys_output_files
.insert(filename
);
684 log_cmd_error("Can't open output file `%s' for writing: %s\n", filename
.c_str(), strerror(errno
));
691 args
.push_back(filename
);
693 // cmd_log_args(args);
696 filename
= "<stdout>";
701 void Backend::backend_call(RTLIL::Design
*design
, std::ostream
*f
, std::string filename
, std::string command
)
703 std::vector
<std::string
> args
;
704 char *s
= strdup(command
.c_str());
705 for (char *p
= strtok(s
, " \t\r\n"); p
; p
= strtok(NULL
, " \t\r\n"))
708 backend_call(design
, f
, filename
, args
);
711 void Backend::backend_call(RTLIL::Design
*design
, std::ostream
*f
, std::string filename
, std::vector
<std::string
> args
)
713 if (args
.size() == 0)
715 if (backend_register
.count(args
[0]) == 0)
716 log_cmd_error("No such backend: %s\n", args
[0].c_str());
718 size_t orig_sel_stack_pos
= design
->selection_stack
.size();
721 auto state
= backend_register
[args
[0]]->pre_execute();
722 backend_register
[args
[0]]->execute(f
, filename
, args
, design
);
723 backend_register
[args
[0]]->post_execute(state
);
724 } else if (filename
== "-") {
725 std::ostream
*f_cout
= &std::cout
;
726 auto state
= backend_register
[args
[0]]->pre_execute();
727 backend_register
[args
[0]]->execute(f_cout
, "<stdout>", args
, design
);
728 backend_register
[args
[0]]->post_execute(state
);
730 if (!filename
.empty())
731 args
.push_back(filename
);
732 backend_register
[args
[0]]->execute(args
, design
);
735 while (design
->selection_stack
.size() > orig_sel_stack_pos
)
736 design
->selection_stack
.pop_back();
739 static struct CellHelpMessages
{
740 dict
<string
, string
> cell_help
, cell_code
;
742 #include "techlibs/common/simlib_help.inc"
743 #include "techlibs/common/simcells_help.inc"
747 } cell_help_messages
;
749 struct HelpPass
: public Pass
{
750 HelpPass() : Pass("help", "display help messages") { }
751 void help() YS_OVERRIDE
754 log(" help ................ list all commands\n");
755 log(" help <command> ...... print help message for given command\n");
756 log(" help -all ........... print complete command reference\n");
758 log(" help -cells .......... list all cell types\n");
759 log(" help <celltype> ..... print help message for given cell type\n");
760 log(" help <celltype>+ .... print verilog code for given cell type\n");
763 void escape_tex(std::string
&tex
)
765 for (size_t pos
= 0; (pos
= tex
.find('_', pos
)) != std::string::npos
; pos
+= 2)
766 tex
.replace(pos
, 1, "\\_");
767 for (size_t pos
= 0; (pos
= tex
.find('$', pos
)) != std::string::npos
; pos
+= 2)
768 tex
.replace(pos
, 1, "\\$");
770 void write_tex(FILE *f
, std::string cmd
, std::string title
, std::string text
)
772 size_t begin
= text
.find_first_not_of("\n"), end
= text
.find_last_not_of("\n");
773 if (begin
!= std::string::npos
&& end
!= std::string::npos
&& begin
< end
)
774 text
= text
.substr(begin
, end
-begin
+1);
775 std::string cmd_unescaped
= cmd
;
778 fprintf(f
, "\\section{%s -- %s}\n", cmd
.c_str(), title
.c_str());
779 fprintf(f
, "\\label{cmd:%s}\n", cmd_unescaped
.c_str());
780 fprintf(f
, "\\begin{lstlisting}[numbers=left,frame=single]\n");
781 fprintf(f
, "%s\n\\end{lstlisting}\n\n", text
.c_str());
783 void escape_html(std::string
&html
)
786 while ((pos
= html
.find_first_of("<>&", pos
)) != std::string::npos
)
789 html
.replace(pos
, 1, "<");
793 html
.replace(pos
, 1, ">");
797 html
.replace(pos
, 1, "&");
802 void write_html(FILE *idxf
, std::string cmd
, std::string title
, std::string text
)
804 FILE *f
= fopen(stringf("cmd_%s.in", cmd
.c_str()).c_str(), "wt");
805 fprintf(idxf
, "<li><a href=\"cmd_%s.html\"> ", cmd
.c_str());
811 fprintf(idxf
, "%s</a> <span>%s</span></a>\n", cmd
.c_str(), title
.c_str());
813 fprintf(f
, "@cmd_header %s@\n", cmd
.c_str());
814 fprintf(f
, "<h1>%s - %s</h1>\n", cmd
.c_str(), title
.c_str());
815 fprintf(f
, "<pre>%s</pre>\n", text
.c_str());
816 fprintf(f
, "@footer@\n");
820 void execute(std::vector
<std::string
> args
, RTLIL::Design
*) YS_OVERRIDE
822 if (args
.size() == 1) {
824 for (auto &it
: pass_register
)
825 log(" %-20s %s\n", it
.first
.c_str(), it
.second
->short_help
.c_str());
827 log("Type 'help <command>' for more information on a command.\n");
828 log("Type 'help -cells' for a list of all cell types.\n");
833 if (args
.size() == 2) {
834 if (args
[1] == "-all") {
835 for (auto &it
: pass_register
) {
837 log("%s -- %s\n", it
.first
.c_str(), it
.second
->short_help
.c_str());
838 for (size_t i
= 0; i
< it
.first
.size() + it
.second
->short_help
.size() + 6; i
++)
842 if (it
.second
->experimental_flag
) {
844 log("WARNING: THE '%s' COMMAND IS EXPERIMENTAL.\n", it
.first
.c_str());
849 else if (args
[1] == "-cells") {
851 for (auto &it
: cell_help_messages
.cell_help
) {
852 string line
= split_tokens(it
.second
, "\n").at(0);
853 string cell_name
= next_token(line
);
854 log(" %-15s %s\n", cell_name
.c_str(), line
.c_str());
857 log("Type 'help <cell_type>' for more information on a cell type.\n");
861 // this option is undocumented as it is for internal use only
862 else if (args
[1] == "-write-tex-command-reference-manual") {
863 FILE *f
= fopen("command-reference-manual.tex", "wt");
864 fprintf(f
, "%% Generated using the yosys 'help -write-tex-command-reference-manual' command.\n\n");
865 for (auto &it
: pass_register
) {
866 std::ostringstream buf
;
867 log_streams
.push_back(&buf
);
869 if (it
.second
->experimental_flag
) {
871 log("WARNING: THE '%s' COMMAND IS EXPERIMENTAL.\n", it
.first
.c_str());
874 log_streams
.pop_back();
875 write_tex(f
, it
.first
, it
.second
->short_help
, buf
.str());
879 // this option is undocumented as it is for internal use only
880 else if (args
[1] == "-write-web-command-reference-manual") {
881 FILE *f
= fopen("templates/cmd_index.in", "wt");
882 for (auto &it
: pass_register
) {
883 std::ostringstream buf
;
884 log_streams
.push_back(&buf
);
886 if (it
.second
->experimental_flag
) {
888 log("WARNING: THE '%s' COMMAND IS EXPERIMENTAL.\n", it
.first
.c_str());
891 log_streams
.pop_back();
892 write_html(f
, it
.first
, it
.second
->short_help
, buf
.str());
896 else if (pass_register
.count(args
[1])) {
897 pass_register
.at(args
[1])->help();
898 if (pass_register
.at(args
[1])->experimental_flag
) {
900 log("WARNING: THE '%s' COMMAND IS EXPERIMENTAL.\n", args
[1].c_str());
904 else if (cell_help_messages
.cell_help
.count(args
[1])) {
905 log("%s", cell_help_messages
.cell_help
.at(args
[1]).c_str());
906 log("Run 'help %s+' to display the Verilog model for this cell type.\n", args
[1].c_str());
909 else if (cell_help_messages
.cell_code
.count(args
[1])) {
911 log("%s", cell_help_messages
.cell_code
.at(args
[1]).c_str());
914 log("No such command or cell type: %s\n", args
[1].c_str());
922 struct EchoPass
: public Pass
{
923 EchoPass() : Pass("echo", "turning echoing back of commands on and off") { }
924 void help() YS_OVERRIDE
929 log("Print all commands to log before executing them.\n");
934 log("Do not print all commands to log before executing them. (default)\n");
937 void execute(std::vector
<std::string
> args
, RTLIL::Design
*) YS_OVERRIDE
940 cmd_error(args
, 2, "Unexpected argument.");
942 if (args
.size() == 2) {
945 else if (args
[1] == "off")
948 cmd_error(args
, 1, "Unexpected argument.");
951 log("echo %s\n", echo_mode
? "on" : "off");
955 SatSolver
*yosys_satsolver_list
;
956 SatSolver
*yosys_satsolver
;
958 struct MinisatSatSolver
: public SatSolver
{
959 MinisatSatSolver() : SatSolver("minisat") {
960 yosys_satsolver
= this;
962 ezSAT
*create() YS_OVERRIDE
{
963 return new ezMiniSAT();