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