Improve determinism of IdString DB for similar scripts
[yosys.git] / kernel / register.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
5 *
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.
9 *
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.
17 *
18 */
19
20 #include "kernel/yosys.h"
21 #include "kernel/satgen.h"
22
23 #include <string.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <errno.h>
27
28 YOSYS_NAMESPACE_BEGIN
29
30 #define MAX_REG_COUNT 1000
31
32 bool echo_mode = false;
33 Pass *first_queued_pass;
34 Pass *current_pass;
35
36 std::map<std::string, Frontend*> frontend_register;
37 std::map<std::string, Pass*> pass_register;
38 std::map<std::string, Backend*> backend_register;
39
40 std::vector<std::string> Frontend::next_args;
41
42 Pass::Pass(std::string name, std::string short_help) : pass_name(name), short_help(short_help)
43 {
44 next_queued_pass = first_queued_pass;
45 first_queued_pass = this;
46 call_counter = 0;
47 runtime_ns = 0;
48 }
49
50 void Pass::run_register()
51 {
52 log_assert(pass_register.count(pass_name) == 0);
53 pass_register[pass_name] = this;
54 }
55
56 void Pass::init_register()
57 {
58 while (first_queued_pass) {
59 first_queued_pass->run_register();
60 first_queued_pass = first_queued_pass->next_queued_pass;
61 }
62 }
63
64 void Pass::done_register()
65 {
66 frontend_register.clear();
67 pass_register.clear();
68 backend_register.clear();
69 log_assert(first_queued_pass == NULL);
70 }
71
72 Pass::~Pass()
73 {
74 }
75
76 Pass::pre_post_exec_state_t Pass::pre_execute()
77 {
78 pre_post_exec_state_t state;
79 call_counter++;
80 state.begin_ns = PerformanceTimer::query();
81 state.parent_pass = current_pass;
82 current_pass = this;
83 clear_flags();
84 return state;
85 }
86
87 void Pass::post_execute(Pass::pre_post_exec_state_t state)
88 {
89 IdString::checkpoint();
90
91 int64_t time_ns = PerformanceTimer::query() - state.begin_ns;
92 runtime_ns += time_ns;
93 current_pass = state.parent_pass;
94 if (current_pass)
95 current_pass->runtime_ns -= time_ns;
96 }
97
98 void Pass::help()
99 {
100 log("\n");
101 log("No help message for command `%s'.\n", pass_name.c_str());
102 log("\n");
103 }
104
105 void Pass::clear_flags()
106 {
107 }
108
109 void Pass::cmd_log_args(const std::vector<std::string> &args)
110 {
111 if (args.size() <= 1)
112 return;
113 log("Full command line:");
114 for (size_t i = 0; i < args.size(); i++)
115 log(" %s", args[i].c_str());
116 log("\n");
117 }
118
119 void Pass::cmd_error(const std::vector<std::string> &args, size_t argidx, std::string msg)
120 {
121 std::string command_text;
122 int error_pos = 0;
123
124 for (size_t i = 0; i < args.size(); i++) {
125 if (i < argidx)
126 error_pos += args[i].size() + 1;
127 command_text = command_text + (command_text.empty() ? "" : " ") + args[i];
128 }
129
130 log("\nSyntax error in command `%s':\n", command_text.c_str());
131 help();
132
133 log_cmd_error("Command syntax error: %s\n> %s\n> %*s^\n",
134 msg.c_str(), command_text.c_str(), error_pos, "");
135 }
136
137 void Pass::extra_args(std::vector<std::string> args, size_t argidx, RTLIL::Design *design, bool select)
138 {
139 for (; argidx < args.size(); argidx++)
140 {
141 std::string arg = args[argidx];
142
143 if (arg.substr(0, 1) == "-")
144 cmd_error(args, argidx, "Unknown option or option in arguments.");
145
146 if (!select)
147 cmd_error(args, argidx, "Extra argument.");
148
149 handle_extra_select_args(this, args, argidx, args.size(), design);
150 break;
151 }
152 // cmd_log_args(args);
153 }
154
155 void Pass::call(RTLIL::Design *design, std::string command)
156 {
157 std::vector<std::string> args;
158
159 std::string cmd_buf = command;
160 std::string tok = next_token(cmd_buf, " \t\r\n", true);
161
162 if (tok.empty())
163 return;
164
165 if (tok[0] == '!') {
166 cmd_buf = command.substr(command.find('!') + 1);
167 while (!cmd_buf.empty() && (cmd_buf.back() == ' ' || cmd_buf.back() == '\t' ||
168 cmd_buf.back() == '\r' || cmd_buf.back() == '\n'))
169 cmd_buf.resize(cmd_buf.size()-1);
170 log_header(design, "Shell command: %s\n", cmd_buf.c_str());
171 int retCode = run_command(cmd_buf);
172 if (retCode != 0)
173 log_cmd_error("Shell command returned error code %d.\n", retCode);
174 return;
175 }
176
177 while (!tok.empty()) {
178 if (tok[0] == '#') {
179 int stop;
180 for (stop = 0; stop < GetSize(cmd_buf); stop++)
181 if (cmd_buf[stop] == '\r' || cmd_buf[stop] == '\n')
182 break;
183 cmd_buf = cmd_buf.substr(stop);
184 } else
185 if (tok.back() == ';') {
186 int num_semikolon = 0;
187 while (!tok.empty() && tok.back() == ';')
188 tok.resize(tok.size()-1), num_semikolon++;
189 if (!tok.empty())
190 args.push_back(tok);
191 call(design, args);
192 args.clear();
193 if (num_semikolon == 2)
194 call(design, "clean");
195 if (num_semikolon == 3)
196 call(design, "clean -purge");
197 } else
198 args.push_back(tok);
199 bool found_nl = false;
200 for (auto c : cmd_buf) {
201 if (c == ' ' || c == '\t')
202 continue;
203 if (c == '\r' || c == '\n')
204 found_nl = true;
205 break;
206 }
207 if (found_nl) {
208 call(design, args);
209 args.clear();
210 }
211 tok = next_token(cmd_buf, " \t\r\n", true);
212 }
213
214 call(design, args);
215 }
216
217 void Pass::call(RTLIL::Design *design, std::vector<std::string> args)
218 {
219 if (args.size() == 0 || args[0][0] == '#' || args[0][0] == ':')
220 return;
221
222 if (echo_mode) {
223 log("%s", create_prompt(design, 0));
224 for (size_t i = 0; i < args.size(); i++)
225 log("%s%s", i ? " " : "", args[i].c_str());
226 log("\n");
227 }
228
229 if (pass_register.count(args[0]) == 0)
230 log_cmd_error("No such command: %s (type 'help' for a command overview)\n", args[0].c_str());
231
232 size_t orig_sel_stack_pos = design->selection_stack.size();
233 auto state = pass_register[args[0]]->pre_execute();
234 pass_register[args[0]]->execute(args, design);
235 pass_register[args[0]]->post_execute(state);
236 while (design->selection_stack.size() > orig_sel_stack_pos)
237 design->selection_stack.pop_back();
238
239 design->check();
240 }
241
242 void Pass::call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::string command)
243 {
244 std::string backup_selected_active_module = design->selected_active_module;
245 design->selected_active_module.clear();
246 design->selection_stack.push_back(selection);
247
248 Pass::call(design, command);
249
250 design->selection_stack.pop_back();
251 design->selected_active_module = backup_selected_active_module;
252 }
253
254 void Pass::call_on_selection(RTLIL::Design *design, const RTLIL::Selection &selection, std::vector<std::string> args)
255 {
256 std::string backup_selected_active_module = design->selected_active_module;
257 design->selected_active_module.clear();
258 design->selection_stack.push_back(selection);
259
260 Pass::call(design, args);
261
262 design->selection_stack.pop_back();
263 design->selected_active_module = backup_selected_active_module;
264 }
265
266 void Pass::call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::string command)
267 {
268 std::string backup_selected_active_module = design->selected_active_module;
269 design->selected_active_module = module->name.str();
270 design->selection_stack.push_back(RTLIL::Selection(false));
271 design->selection_stack.back().select(module);
272
273 Pass::call(design, command);
274
275 design->selection_stack.pop_back();
276 design->selected_active_module = backup_selected_active_module;
277 }
278
279 void Pass::call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::vector<std::string> args)
280 {
281 std::string backup_selected_active_module = design->selected_active_module;
282 design->selected_active_module = module->name.str();
283 design->selection_stack.push_back(RTLIL::Selection(false));
284 design->selection_stack.back().select(module);
285
286 Pass::call(design, args);
287
288 design->selection_stack.pop_back();
289 design->selected_active_module = backup_selected_active_module;
290 }
291
292 bool ScriptPass::check_label(std::string label, std::string info)
293 {
294 if (active_design == nullptr) {
295 log("\n");
296 if (info.empty())
297 log(" %s:\n", label.c_str());
298 else
299 log(" %s: %s\n", label.c_str(), info.c_str());
300 return true;
301 } else {
302 if (!active_run_from.empty() && active_run_from == active_run_to) {
303 block_active = (label == active_run_from);
304 } else {
305 if (label == active_run_from)
306 block_active = true;
307 if (label == active_run_to)
308 block_active = false;
309 }
310 return block_active;
311 }
312 }
313
314 void ScriptPass::run(std::string command, std::string info)
315 {
316 if (active_design == nullptr) {
317 if (info.empty())
318 log(" %s\n", command.c_str());
319 else
320 log(" %s %s\n", command.c_str(), info.c_str());
321 } else
322 Pass::call(active_design, command);
323 }
324
325 void ScriptPass::run_script(RTLIL::Design *design, std::string run_from, std::string run_to)
326 {
327 help_mode = false;
328 active_design = design;
329 block_active = run_from.empty();
330 active_run_from = run_from;
331 active_run_to = run_to;
332 script();
333 }
334
335 void ScriptPass::help_script()
336 {
337 clear_flags();
338 help_mode = true;
339 active_design = nullptr;
340 block_active = true;
341 active_run_from.clear();
342 active_run_to.clear();
343 script();
344 }
345
346 Frontend::Frontend(std::string name, std::string short_help) :
347 Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "read_" + name, short_help),
348 frontend_name(name.rfind("=", 0) == 0 ? name.substr(1) : name)
349 {
350 }
351
352 void Frontend::run_register()
353 {
354 log_assert(pass_register.count(pass_name) == 0);
355 pass_register[pass_name] = this;
356
357 log_assert(frontend_register.count(frontend_name) == 0);
358 frontend_register[frontend_name] = this;
359 }
360
361 Frontend::~Frontend()
362 {
363 }
364
365 void Frontend::execute(std::vector<std::string> args, RTLIL::Design *design)
366 {
367 log_assert(next_args.empty());
368 do {
369 std::istream *f = NULL;
370 next_args.clear();
371 auto state = pre_execute();
372 execute(f, std::string(), args, design);
373 post_execute(state);
374 args = next_args;
375 delete f;
376 } while (!args.empty());
377 }
378
379 FILE *Frontend::current_script_file = NULL;
380 std::string Frontend::last_here_document;
381
382 void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<std::string> args, size_t argidx)
383 {
384 bool called_with_fp = f != NULL;
385
386 next_args.clear();
387
388 if (argidx < args.size())
389 {
390 std::string arg = args[argidx];
391
392 if (arg.substr(0, 1) == "-")
393 cmd_error(args, argidx, "Unknown option or option in arguments.");
394 if (f != NULL)
395 cmd_error(args, argidx, "Extra filename argument in direct file mode.");
396
397 filename = arg;
398 if (filename == "<<" && argidx+1 < args.size())
399 filename += args[++argidx];
400 if (filename.substr(0, 2) == "<<") {
401 if (Frontend::current_script_file == NULL)
402 log_error("Unexpected here document '%s' outside of script!\n", filename.c_str());
403 if (filename.size() <= 2)
404 log_error("Missing EOT marker in here document!\n");
405 std::string eot_marker = filename.substr(2);
406 last_here_document.clear();
407 while (1) {
408 std::string buffer;
409 char block[4096];
410 while (1) {
411 if (fgets(block, 4096, Frontend::current_script_file) == NULL)
412 log_error("Unexpected end of file in here document '%s'!\n", filename.c_str());
413 buffer += block;
414 if (buffer.size() > 0 && (buffer[buffer.size() - 1] == '\n' || buffer[buffer.size() - 1] == '\r'))
415 break;
416 }
417 size_t indent = buffer.find_first_not_of(" \t\r\n");
418 if (indent != std::string::npos && buffer.substr(indent, eot_marker.size()) == eot_marker)
419 break;
420 last_here_document += buffer;
421 }
422 f = new std::istringstream(last_here_document);
423 } else {
424 rewrite_filename(filename);
425 vector<string> filenames = glob_filename(filename);
426 filename = filenames.front();
427 if (GetSize(filenames) > 1) {
428 next_args.insert(next_args.end(), args.begin(), args.begin()+argidx);
429 next_args.insert(next_args.end(), filenames.begin()+1, filenames.end());
430 }
431 std::ifstream *ff = new std::ifstream;
432 ff->open(filename.c_str());
433 yosys_input_files.insert(filename);
434 if (ff->fail())
435 delete ff;
436 else
437 f = ff;
438 }
439 if (f == NULL)
440 log_cmd_error("Can't open input file `%s' for reading: %s\n", filename.c_str(), strerror(errno));
441
442 for (size_t i = argidx+1; i < args.size(); i++)
443 if (args[i].substr(0, 1) == "-")
444 cmd_error(args, i, "Found option, expected arguments.");
445
446 if (argidx+1 < args.size()) {
447 if (next_args.empty())
448 next_args.insert(next_args.end(), args.begin(), args.begin()+argidx);
449 next_args.insert(next_args.end(), args.begin()+argidx+1, args.end());
450 args.erase(args.begin()+argidx+1, args.end());
451 }
452 }
453
454 if (f == NULL)
455 cmd_error(args, argidx, "No filename given.");
456
457 if (called_with_fp)
458 args.push_back(filename);
459 args[0] = pass_name;
460 // cmd_log_args(args);
461 }
462
463 void Frontend::frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command)
464 {
465 std::vector<std::string> args;
466 char *s = strdup(command.c_str());
467 for (char *p = strtok(s, " \t\r\n"); p; p = strtok(NULL, " \t\r\n"))
468 args.push_back(p);
469 free(s);
470 frontend_call(design, f, filename, args);
471 }
472
473 void Frontend::frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::vector<std::string> args)
474 {
475 if (args.size() == 0)
476 return;
477 if (frontend_register.count(args[0]) == 0)
478 log_cmd_error("No such frontend: %s\n", args[0].c_str());
479
480 if (f != NULL) {
481 auto state = frontend_register[args[0]]->pre_execute();
482 frontend_register[args[0]]->execute(f, filename, args, design);
483 frontend_register[args[0]]->post_execute(state);
484 } else if (filename == "-") {
485 std::istream *f_cin = &std::cin;
486 auto state = frontend_register[args[0]]->pre_execute();
487 frontend_register[args[0]]->execute(f_cin, "<stdin>", args, design);
488 frontend_register[args[0]]->post_execute(state);
489 } else {
490 if (!filename.empty())
491 args.push_back(filename);
492 frontend_register[args[0]]->execute(args, design);
493 }
494
495 design->check();
496 }
497
498 Backend::Backend(std::string name, std::string short_help) :
499 Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "write_" + name, short_help),
500 backend_name(name.rfind("=", 0) == 0 ? name.substr(1) : name)
501 {
502 }
503
504 void Backend::run_register()
505 {
506 log_assert(pass_register.count(pass_name) == 0);
507 pass_register[pass_name] = this;
508
509 log_assert(backend_register.count(backend_name) == 0);
510 backend_register[backend_name] = this;
511 }
512
513 Backend::~Backend()
514 {
515 }
516
517 void Backend::execute(std::vector<std::string> args, RTLIL::Design *design)
518 {
519 std::ostream *f = NULL;
520 auto state = pre_execute();
521 execute(f, std::string(), args, design);
522 post_execute(state);
523 if (f != &std::cout)
524 delete f;
525 }
526
527 void Backend::extra_args(std::ostream *&f, std::string &filename, std::vector<std::string> args, size_t argidx)
528 {
529 bool called_with_fp = f != NULL;
530
531 for (; argidx < args.size(); argidx++)
532 {
533 std::string arg = args[argidx];
534
535 if (arg.substr(0, 1) == "-" && arg != "-")
536 cmd_error(args, argidx, "Unknown option or option in arguments.");
537 if (f != NULL)
538 cmd_error(args, argidx, "Extra filename argument in direct file mode.");
539
540 if (arg == "-") {
541 filename = "<stdout>";
542 f = &std::cout;
543 continue;
544 }
545
546 filename = arg;
547 std::ofstream *ff = new std::ofstream;
548 ff->open(filename.c_str(), std::ofstream::trunc);
549 yosys_output_files.insert(filename);
550 if (ff->fail()) {
551 delete ff;
552 log_cmd_error("Can't open output file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
553 }
554 f = ff;
555 }
556
557 if (called_with_fp)
558 args.push_back(filename);
559 args[0] = pass_name;
560 // cmd_log_args(args);
561
562 if (f == NULL) {
563 filename = "<stdout>";
564 f = &std::cout;
565 }
566 }
567
568 void Backend::backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command)
569 {
570 std::vector<std::string> args;
571 char *s = strdup(command.c_str());
572 for (char *p = strtok(s, " \t\r\n"); p; p = strtok(NULL, " \t\r\n"))
573 args.push_back(p);
574 free(s);
575 backend_call(design, f, filename, args);
576 }
577
578 void Backend::backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::vector<std::string> args)
579 {
580 if (args.size() == 0)
581 return;
582 if (backend_register.count(args[0]) == 0)
583 log_cmd_error("No such backend: %s\n", args[0].c_str());
584
585 size_t orig_sel_stack_pos = design->selection_stack.size();
586
587 if (f != NULL) {
588 auto state = backend_register[args[0]]->pre_execute();
589 backend_register[args[0]]->execute(f, filename, args, design);
590 backend_register[args[0]]->post_execute(state);
591 } else if (filename == "-") {
592 std::ostream *f_cout = &std::cout;
593 auto state = backend_register[args[0]]->pre_execute();
594 backend_register[args[0]]->execute(f_cout, "<stdout>", args, design);
595 backend_register[args[0]]->post_execute(state);
596 } else {
597 if (!filename.empty())
598 args.push_back(filename);
599 backend_register[args[0]]->execute(args, design);
600 }
601
602 while (design->selection_stack.size() > orig_sel_stack_pos)
603 design->selection_stack.pop_back();
604
605 design->check();
606 }
607
608 static struct CellHelpMessages {
609 dict<string, string> cell_help, cell_code;
610 CellHelpMessages() {
611 #include "techlibs/common/simlib_help.inc"
612 #include "techlibs/common/simcells_help.inc"
613 cell_help.sort();
614 cell_code.sort();
615 }
616 } cell_help_messages;
617
618 struct HelpPass : public Pass {
619 HelpPass() : Pass("help", "display help messages") { }
620 void help() YS_OVERRIDE
621 {
622 log("\n");
623 log(" help ................ list all commands\n");
624 log(" help <command> ...... print help message for given command\n");
625 log(" help -all ........... print complete command reference\n");
626 log("\n");
627 log(" help -cells .......... list all cell types\n");
628 log(" help <celltype> ..... print help message for given cell type\n");
629 log(" help <celltype>+ .... print verilog code for given cell type\n");
630 log("\n");
631 }
632 void escape_tex(std::string &tex)
633 {
634 for (size_t pos = 0; (pos = tex.find('_', pos)) != std::string::npos; pos += 2)
635 tex.replace(pos, 1, "\\_");
636 for (size_t pos = 0; (pos = tex.find('$', pos)) != std::string::npos; pos += 2)
637 tex.replace(pos, 1, "\\$");
638 }
639 void write_tex(FILE *f, std::string cmd, std::string title, std::string text)
640 {
641 size_t begin = text.find_first_not_of("\n"), end = text.find_last_not_of("\n");
642 if (begin != std::string::npos && end != std::string::npos && begin < end)
643 text = text.substr(begin, end-begin+1);
644 std::string cmd_unescaped = cmd;
645 escape_tex(cmd);
646 escape_tex(title);
647 fprintf(f, "\\section{%s -- %s}\n", cmd.c_str(), title.c_str());
648 fprintf(f, "\\label{cmd:%s}\n", cmd_unescaped.c_str());
649 fprintf(f, "\\begin{lstlisting}[numbers=left,frame=single]\n");
650 fprintf(f, "%s\n\\end{lstlisting}\n\n", text.c_str());
651 }
652 void escape_html(std::string &html)
653 {
654 size_t pos = 0;
655 while ((pos = html.find_first_of("<>&", pos)) != std::string::npos)
656 switch (html[pos]) {
657 case '<':
658 html.replace(pos, 1, "&lt;");
659 pos += 4;
660 break;
661 case '>':
662 html.replace(pos, 1, "&gt;");
663 pos += 4;
664 break;
665 case '&':
666 html.replace(pos, 1, "&amp;");
667 pos += 5;
668 break;
669 }
670 }
671 void write_html(FILE *idxf, std::string cmd, std::string title, std::string text)
672 {
673 FILE *f = fopen(stringf("cmd_%s.in", cmd.c_str()).c_str(), "wt");
674 fprintf(idxf, "<li><a href=\"cmd_%s.html\"> ", cmd.c_str());
675
676 escape_html(cmd);
677 escape_html(title);
678 escape_html(text);
679
680 fprintf(idxf, "%s</a> <span>%s</span></a>\n", cmd.c_str(), title.c_str());
681
682 fprintf(f, "@cmd_header %s@\n", cmd.c_str());
683 fprintf(f, "<h1>%s - %s</h1>\n", cmd.c_str(), title.c_str());
684 fprintf(f, "<pre>%s</pre>\n", text.c_str());
685 fprintf(f, "@footer@\n");
686
687 fclose(f);
688 }
689 void execute(std::vector<std::string> args, RTLIL::Design*) YS_OVERRIDE
690 {
691 if (args.size() == 1) {
692 log("\n");
693 for (auto &it : pass_register)
694 log(" %-20s %s\n", it.first.c_str(), it.second->short_help.c_str());
695 log("\n");
696 log("Type 'help <command>' for more information on a command.\n");
697 log("Type 'help -cells' for a list of all cell types.\n");
698 log("\n");
699 return;
700 }
701
702 if (args.size() == 2) {
703 if (args[1] == "-all") {
704 for (auto &it : pass_register) {
705 log("\n\n");
706 log("%s -- %s\n", it.first.c_str(), it.second->short_help.c_str());
707 for (size_t i = 0; i < it.first.size() + it.second->short_help.size() + 6; i++)
708 log("=");
709 log("\n");
710 it.second->help();
711 }
712 }
713 else if (args[1] == "-cells") {
714 log("\n");
715 for (auto &it : cell_help_messages.cell_help) {
716 string line = split_tokens(it.second, "\n").at(0);
717 string cell_name = next_token(line);
718 log(" %-15s %s\n", cell_name.c_str(), line.c_str());
719 }
720 log("\n");
721 log("Type 'help <cell_type>' for more information on a cell type.\n");
722 log("\n");
723 return;
724 }
725 // this option is undocumented as it is for internal use only
726 else if (args[1] == "-write-tex-command-reference-manual") {
727 FILE *f = fopen("command-reference-manual.tex", "wt");
728 fprintf(f, "%% Generated using the yosys 'help -write-tex-command-reference-manual' command.\n\n");
729 for (auto &it : pass_register) {
730 std::ostringstream buf;
731 log_streams.push_back(&buf);
732 it.second->help();
733 log_streams.pop_back();
734 write_tex(f, it.first, it.second->short_help, buf.str());
735 }
736 fclose(f);
737 }
738 // this option is undocumented as it is for internal use only
739 else if (args[1] == "-write-web-command-reference-manual") {
740 FILE *f = fopen("templates/cmd_index.in", "wt");
741 for (auto &it : pass_register) {
742 std::ostringstream buf;
743 log_streams.push_back(&buf);
744 it.second->help();
745 log_streams.pop_back();
746 write_html(f, it.first, it.second->short_help, buf.str());
747 }
748 fclose(f);
749 }
750 else if (pass_register.count(args[1])) {
751 pass_register.at(args[1])->help();
752 }
753 else if (cell_help_messages.cell_help.count(args[1])) {
754 log("%s", cell_help_messages.cell_help.at(args[1]).c_str());
755 log("Run 'help %s+' to display the Verilog model for this cell type.\n", args[1].c_str());
756 log("\n");
757 }
758 else if (cell_help_messages.cell_code.count(args[1])) {
759 log("\n");
760 log("%s", cell_help_messages.cell_code.at(args[1]).c_str());
761 }
762 else
763 log("No such command or cell type: %s\n", args[1].c_str());
764 return;
765 }
766
767 help();
768 }
769 } HelpPass;
770
771 struct EchoPass : public Pass {
772 EchoPass() : Pass("echo", "turning echoing back of commands on and off") { }
773 void help() YS_OVERRIDE
774 {
775 log("\n");
776 log(" echo on\n");
777 log("\n");
778 log("Print all commands to log before executing them.\n");
779 log("\n");
780 log("\n");
781 log(" echo off\n");
782 log("\n");
783 log("Do not print all commands to log before executing them. (default)\n");
784 log("\n");
785 }
786 void execute(std::vector<std::string> args, RTLIL::Design*) YS_OVERRIDE
787 {
788 if (args.size() > 2)
789 cmd_error(args, 2, "Unexpected argument.");
790
791 if (args.size() == 2) {
792 if (args[1] == "on")
793 echo_mode = true;
794 else if (args[1] == "off")
795 echo_mode = false;
796 else
797 cmd_error(args, 1, "Unexpected argument.");
798 }
799
800 log("echo %s\n", echo_mode ? "on" : "off");
801 }
802 } EchoPass;
803
804 SatSolver *yosys_satsolver_list;
805 SatSolver *yosys_satsolver;
806
807 struct MinisatSatSolver : public SatSolver {
808 MinisatSatSolver() : SatSolver("minisat") {
809 yosys_satsolver = this;
810 }
811 ezSAT *create() YS_OVERRIDE {
812 return new ezMiniSAT();
813 }
814 } MinisatSatSolver;
815
816 YOSYS_NAMESPACE_END