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