Merge https://github.com/cliffordwolf/yosys
[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 == "#") {
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 for (; argidx < args.size(); argidx++)
386 {
387 std::string arg = args[argidx];
388
389 if (arg.substr(0, 1) == "-")
390 cmd_error(args, argidx, "Unknown option or option in arguments.");
391 if (f != NULL)
392 cmd_error(args, argidx, "Extra filename argument in direct file mode.");
393
394 filename = arg;
395 if (filename == "<<" && argidx+1 < args.size())
396 filename += args[++argidx];
397 if (filename.substr(0, 2) == "<<") {
398 if (Frontend::current_script_file == NULL)
399 log_error("Unexpected here document '%s' outside of script!\n", filename.c_str());
400 if (filename.size() <= 2)
401 log_error("Missing EOT marker in here document!\n");
402 std::string eot_marker = filename.substr(2);
403 last_here_document.clear();
404 while (1) {
405 std::string buffer;
406 char block[4096];
407 while (1) {
408 if (fgets(block, 4096, Frontend::current_script_file) == NULL)
409 log_error("Unexpected end of file in here document '%s'!\n", filename.c_str());
410 buffer += block;
411 if (buffer.size() > 0 && (buffer[buffer.size() - 1] == '\n' || buffer[buffer.size() - 1] == '\r'))
412 break;
413 }
414 size_t indent = buffer.find_first_not_of(" \t\r\n");
415 if (indent != std::string::npos && buffer.substr(indent, eot_marker.size()) == eot_marker)
416 break;
417 last_here_document += buffer;
418 }
419 f = new std::istringstream(last_here_document);
420 } else {
421 rewrite_filename(filename);
422 std::ifstream *ff = new std::ifstream;
423 ff->open(filename.c_str());
424 if (ff->fail())
425 delete ff;
426 else
427 f = ff;
428 }
429 if (f == NULL)
430 log_cmd_error("Can't open input file `%s' for reading: %s\n", filename.c_str(), strerror(errno));
431
432 for (size_t i = argidx+1; i < args.size(); i++)
433 if (args[i].substr(0, 1) == "-")
434 cmd_error(args, i, "Found option, expected arguments.");
435
436 if (argidx+1 < args.size()) {
437 next_args.insert(next_args.begin(), args.begin(), args.begin()+argidx);
438 next_args.insert(next_args.begin()+argidx, args.begin()+argidx+1, args.end());
439 args.erase(args.begin()+argidx+1, args.end());
440 }
441 break;
442 }
443 if (f == NULL)
444 cmd_error(args, argidx, "No filename given.");
445
446 if (called_with_fp)
447 args.push_back(filename);
448 args[0] = pass_name;
449 // cmd_log_args(args);
450 }
451
452 void Frontend::frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::string command)
453 {
454 std::vector<std::string> args;
455 char *s = strdup(command.c_str());
456 for (char *p = strtok(s, " \t\r\n"); p; p = strtok(NULL, " \t\r\n"))
457 args.push_back(p);
458 free(s);
459 frontend_call(design, f, filename, args);
460 }
461
462 void Frontend::frontend_call(RTLIL::Design *design, std::istream *f, std::string filename, std::vector<std::string> args)
463 {
464 if (args.size() == 0)
465 return;
466 if (frontend_register.count(args[0]) == 0)
467 log_cmd_error("No such frontend: %s\n", args[0].c_str());
468
469 if (f != NULL) {
470 auto state = frontend_register[args[0]]->pre_execute();
471 frontend_register[args[0]]->execute(f, filename, args, design);
472 frontend_register[args[0]]->post_execute(state);
473 } else if (filename == "-") {
474 std::istream *f_cin = &std::cin;
475 auto state = frontend_register[args[0]]->pre_execute();
476 frontend_register[args[0]]->execute(f_cin, "<stdin>", args, design);
477 frontend_register[args[0]]->post_execute(state);
478 } else {
479 if (!filename.empty())
480 args.push_back(filename);
481 frontend_register[args[0]]->execute(args, design);
482 }
483
484 design->check();
485 }
486
487 Backend::Backend(std::string name, std::string short_help) :
488 Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "write_" + name, short_help),
489 backend_name(name.rfind("=", 0) == 0 ? name.substr(1) : name)
490 {
491 }
492
493 void Backend::run_register()
494 {
495 log_assert(pass_register.count(pass_name) == 0);
496 pass_register[pass_name] = this;
497
498 log_assert(backend_register.count(backend_name) == 0);
499 backend_register[backend_name] = this;
500 }
501
502 Backend::~Backend()
503 {
504 }
505
506 void Backend::execute(std::vector<std::string> args, RTLIL::Design *design)
507 {
508 std::ostream *f = NULL;
509 auto state = pre_execute();
510 execute(f, std::string(), args, design);
511 post_execute(state);
512 if (f != &std::cout)
513 delete f;
514 }
515
516 void Backend::extra_args(std::ostream *&f, std::string &filename, std::vector<std::string> args, size_t argidx)
517 {
518 bool called_with_fp = f != NULL;
519
520 for (; argidx < args.size(); argidx++)
521 {
522 std::string arg = args[argidx];
523
524 if (arg.substr(0, 1) == "-" && arg != "-")
525 cmd_error(args, argidx, "Unknown option or option in arguments.");
526 if (f != NULL)
527 cmd_error(args, argidx, "Extra filename argument in direct file mode.");
528
529 if (arg == "-") {
530 filename = "<stdout>";
531 f = &std::cout;
532 continue;
533 }
534
535 filename = arg;
536 std::ofstream *ff = new std::ofstream;
537 ff->open(filename.c_str(), std::ofstream::trunc);
538 if (ff->fail()) {
539 delete ff;
540 log_cmd_error("Can't open output file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
541 }
542 f = ff;
543 }
544
545 if (called_with_fp)
546 args.push_back(filename);
547 args[0] = pass_name;
548 // cmd_log_args(args);
549
550 if (f == NULL) {
551 filename = "<stdout>";
552 f = &std::cout;
553 }
554 }
555
556 void Backend::backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::string command)
557 {
558 std::vector<std::string> args;
559 char *s = strdup(command.c_str());
560 for (char *p = strtok(s, " \t\r\n"); p; p = strtok(NULL, " \t\r\n"))
561 args.push_back(p);
562 free(s);
563 backend_call(design, f, filename, args);
564 }
565
566 void Backend::backend_call(RTLIL::Design *design, std::ostream *f, std::string filename, std::vector<std::string> args)
567 {
568 if (args.size() == 0)
569 return;
570 if (backend_register.count(args[0]) == 0)
571 log_cmd_error("No such backend: %s\n", args[0].c_str());
572
573 size_t orig_sel_stack_pos = design->selection_stack.size();
574
575 if (f != NULL) {
576 auto state = backend_register[args[0]]->pre_execute();
577 backend_register[args[0]]->execute(f, filename, args, design);
578 backend_register[args[0]]->post_execute(state);
579 } else if (filename == "-") {
580 std::ostream *f_cout = &std::cout;
581 auto state = backend_register[args[0]]->pre_execute();
582 backend_register[args[0]]->execute(f_cout, "<stdout>", args, design);
583 backend_register[args[0]]->post_execute(state);
584 } else {
585 if (!filename.empty())
586 args.push_back(filename);
587 backend_register[args[0]]->execute(args, design);
588 }
589
590 while (design->selection_stack.size() > orig_sel_stack_pos)
591 design->selection_stack.pop_back();
592
593 design->check();
594 }
595
596 static struct CellHelpMessages {
597 dict<string, string> cell_help, cell_code;
598 CellHelpMessages() {
599 #include "techlibs/common/simlib_help.inc"
600 #include "techlibs/common/simcells_help.inc"
601 cell_help.sort();
602 cell_code.sort();
603 }
604 } cell_help_messages;
605
606 struct HelpPass : public Pass {
607 HelpPass() : Pass("help", "display help messages") { }
608 virtual void help()
609 {
610 log("\n");
611 log(" help ................ list all commands\n");
612 log(" help <command> ...... print help message for given command\n");
613 log(" help -all ........... print complete command reference\n");
614 log("\n");
615 log(" help -cells .......... list all cell types\n");
616 log(" help <celltype> ..... print help message for given cell type\n");
617 log(" help <celltype>+ .... print verilog code for given cell type\n");
618 log("\n");
619 }
620 void escape_tex(std::string &tex)
621 {
622 for (size_t pos = 0; (pos = tex.find('_', pos)) != std::string::npos; pos += 2)
623 tex.replace(pos, 1, "\\_");
624 for (size_t pos = 0; (pos = tex.find('$', pos)) != std::string::npos; pos += 2)
625 tex.replace(pos, 1, "\\$");
626 }
627 void write_tex(FILE *f, std::string cmd, std::string title, std::string text)
628 {
629 size_t begin = text.find_first_not_of("\n"), end = text.find_last_not_of("\n");
630 if (begin != std::string::npos && end != std::string::npos && begin < end)
631 text = text.substr(begin, end-begin+1);
632 std::string cmd_unescaped = cmd;
633 escape_tex(cmd);
634 escape_tex(title);
635 fprintf(f, "\\section{%s -- %s}\n", cmd.c_str(), title.c_str());
636 fprintf(f, "\\label{cmd:%s}\n", cmd_unescaped.c_str());
637 fprintf(f, "\\begin{lstlisting}[numbers=left,frame=single]\n");
638 fprintf(f, "%s\n\\end{lstlisting}\n\n", text.c_str());
639 }
640 void escape_html(std::string &html)
641 {
642 size_t pos = 0;
643 while ((pos = html.find_first_of("<>&", pos)) != std::string::npos)
644 switch (html[pos]) {
645 case '<':
646 html.replace(pos, 1, "&lt;");
647 pos += 4;
648 break;
649 case '>':
650 html.replace(pos, 1, "&gt;");
651 pos += 4;
652 break;
653 case '&':
654 html.replace(pos, 1, "&amp;");
655 pos += 5;
656 break;
657 }
658 }
659 void write_html(FILE *idxf, std::string cmd, std::string title, std::string text)
660 {
661 FILE *f = fopen(stringf("cmd_%s.in", cmd.c_str()).c_str(), "wt");
662 fprintf(idxf, "<li><a href=\"cmd_%s.html\"> ", cmd.c_str());
663
664 escape_html(cmd);
665 escape_html(title);
666 escape_html(text);
667
668 fprintf(idxf, "%s</a> <span>%s</span></a>\n", cmd.c_str(), title.c_str());
669
670 fprintf(f, "@cmd_header %s@\n", cmd.c_str());
671 fprintf(f, "<h1>%s - %s</h1>\n", cmd.c_str(), title.c_str());
672 fprintf(f, "<pre>%s</pre>\n", text.c_str());
673 fprintf(f, "@footer@\n");
674
675 fclose(f);
676 }
677 virtual void execute(std::vector<std::string> args, RTLIL::Design*)
678 {
679 if (args.size() == 1) {
680 log("\n");
681 for (auto &it : pass_register)
682 log(" %-20s %s\n", it.first.c_str(), it.second->short_help.c_str());
683 log("\n");
684 log("Type 'help <command>' for more information on a command.\n");
685 log("Type 'help -cells' for a list of all cell types.\n");
686 log("\n");
687 return;
688 }
689
690 if (args.size() == 2) {
691 if (args[1] == "-all") {
692 for (auto &it : pass_register) {
693 log("\n\n");
694 log("%s -- %s\n", it.first.c_str(), it.second->short_help.c_str());
695 for (size_t i = 0; i < it.first.size() + it.second->short_help.size() + 6; i++)
696 log("=");
697 log("\n");
698 it.second->help();
699 }
700 }
701 else if (args[1] == "-cells") {
702 log("\n");
703 for (auto &it : cell_help_messages.cell_help) {
704 string line = split_tokens(it.second, "\n").at(0);
705 string cell_name = next_token(line);
706 log(" %-15s %s\n", cell_name.c_str(), line.c_str());
707 }
708 log("\n");
709 log("Type 'help <cell_type>' for more information on a cell type.\n");
710 log("\n");
711 return;
712 }
713 // this option is undocumented as it is for internal use only
714 else if (args[1] == "-write-tex-command-reference-manual") {
715 FILE *f = fopen("command-reference-manual.tex", "wt");
716 fprintf(f, "%% Generated using the yosys 'help -write-tex-command-reference-manual' command.\n\n");
717 for (auto &it : pass_register) {
718 std::ostringstream buf;
719 log_streams.push_back(&buf);
720 it.second->help();
721 log_streams.pop_back();
722 write_tex(f, it.first, it.second->short_help, buf.str());
723 }
724 fclose(f);
725 }
726 // this option is undocumented as it is for internal use only
727 else if (args[1] == "-write-web-command-reference-manual") {
728 FILE *f = fopen("templates/cmd_index.in", "wt");
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_html(f, it.first, it.second->short_help, buf.str());
735 }
736 fclose(f);
737 }
738 else if (pass_register.count(args[1])) {
739 pass_register.at(args[1])->help();
740 }
741 else if (cell_help_messages.cell_help.count(args[1])) {
742 log("%s", cell_help_messages.cell_help.at(args[1]).c_str());
743 log("Run 'help %s+' to display the Verilog model for this cell type.\n", args[1].c_str());
744 log("\n");
745 }
746 else if (cell_help_messages.cell_code.count(args[1])) {
747 log("\n");
748 log("%s", cell_help_messages.cell_code.at(args[1]).c_str());
749 }
750 else
751 log("No such command or cell type: %s\n", args[1].c_str());
752 return;
753 }
754
755 help();
756 }
757 } HelpPass;
758
759 struct EchoPass : public Pass {
760 EchoPass() : Pass("echo", "turning echoing back of commands on and off") { }
761 virtual void help()
762 {
763 log("\n");
764 log(" echo on\n");
765 log("\n");
766 log("Print all commands to log before executing them.\n");
767 log("\n");
768 log("\n");
769 log(" echo off\n");
770 log("\n");
771 log("Do not print all commands to log before executing them. (default)\n");
772 log("\n");
773 }
774 virtual void execute(std::vector<std::string> args, RTLIL::Design*)
775 {
776 if (args.size() > 2)
777 cmd_error(args, 2, "Unexpected argument.");
778
779 if (args.size() == 2) {
780 if (args[1] == "on")
781 echo_mode = true;
782 else if (args[1] == "off")
783 echo_mode = false;
784 else
785 cmd_error(args, 1, "Unexpected argument.");
786 }
787
788 log("echo %s\n", echo_mode ? "on" : "off");
789 }
790 } EchoPass;
791
792 SatSolver *yosys_satsolver_list;
793 SatSolver *yosys_satsolver;
794
795 struct MinisatSatSolver : public SatSolver {
796 MinisatSatSolver() : SatSolver("minisat") {
797 yosys_satsolver = this;
798 }
799 virtual ezSAT *create() YS_OVERRIDE {
800 return new ezMiniSAT();
801 }
802 } MinisatSatSolver;
803
804 YOSYS_NAMESPACE_END
805