Added proc_self_dirname() for win32
[yosys.git] / kernel / yosys.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
22 #ifdef YOSYS_ENABLE_READLINE
23 # include <readline/readline.h>
24 # include <readline/history.h>
25 #endif
26
27 #ifdef YOSYS_ENABLE_PLUGINS
28 # include <dlfcn.h>
29 #endif
30
31 #ifdef _WIN32
32 # include <windows.h>
33 #endif
34
35 #include <unistd.h>
36 #include <limits.h>
37 #include <errno.h>
38
39 YOSYS_NAMESPACE_BEGIN
40
41 int autoidx = 1;
42 RTLIL::Design *yosys_design = NULL;
43
44 #ifdef YOSYS_ENABLE_TCL
45 Tcl_Interp *yosys_tcl_interp = NULL;
46 #endif
47
48 std::string stringf(const char *fmt, ...)
49 {
50 std::string string;
51 va_list ap;
52
53 va_start(ap, fmt);
54 string = vstringf(fmt, ap);
55 va_end(ap);
56
57 return string;
58 }
59
60 std::string vstringf(const char *fmt, va_list ap)
61 {
62 std::string string;
63 char *str = NULL;
64
65 #ifdef _WIN32
66 int sz = 64, rc;
67 while (1) {
68 va_list apc;
69 va_copy(apc, ap);
70 str = (char*)realloc(str, sz);
71 rc = vsnprintf(str, sz, fmt, apc);
72 va_end(apc);
73 if (rc >= 0 && rc < sz)
74 break;
75 sz *= 2;
76 }
77 #else
78 if (vasprintf(&str, fmt, ap) < 0)
79 str = NULL;
80 #endif
81
82 if (str != NULL) {
83 string = str;
84 free(str);
85 }
86
87 return string;
88 }
89
90 std::string next_token(std::string &text, const char *sep)
91 {
92 size_t pos_begin = text.find_first_not_of(sep);
93
94 if (pos_begin == std::string::npos)
95 pos_begin = text.size();
96
97 size_t pos_end = text.find_first_of(sep, pos_begin);
98
99 if (pos_end == std::string::npos)
100 pos_end = text.size();
101
102 std::string token = text.substr(pos_begin, pos_end-pos_begin);
103 text = text.substr(pos_end);
104 return token;
105 }
106
107 // this is very similar to fnmatch(). the exact rules used by this
108 // function are:
109 //
110 // ? matches any character except
111 // * matches any sequence of characters
112 // [...] matches any of the characters in the list
113 // [!..] matches any of the characters not in the list
114 //
115 // a backslash may be used to escape the next characters in the
116 // pattern. each special character can also simply match itself.
117 //
118 bool patmatch(const char *pattern, const char *string)
119 {
120 if (*pattern == 0)
121 return *string == 0;
122
123 if (*pattern == '\\') {
124 if (pattern[1] == string[0] && patmatch(pattern+2, string+1))
125 return true;
126 }
127
128 if (*pattern == '?') {
129 if (*string == 0)
130 return false;
131 return patmatch(pattern+1, string+1);
132 }
133
134 if (*pattern == '*') {
135 while (*string) {
136 if (patmatch(pattern+1, string++))
137 return true;
138 }
139 return pattern[1] == 0;
140 }
141
142 if (*pattern == '[') {
143 bool found_match = false;
144 bool inverted_list = pattern[1] == '!';
145 const char *p = pattern + (inverted_list ? 1 : 0);
146
147 while (*++p) {
148 if (*p == ']') {
149 if (found_match != inverted_list && patmatch(p+1, string+1))
150 return true;
151 break;
152 }
153
154 if (*p == '\\') {
155 if (*++p == *string)
156 found_match = true;
157 } else
158 if (*p == *string)
159 found_match = true;
160 }
161 }
162
163 if (*pattern == *string)
164 return patmatch(pattern+1, string+1);
165
166 return false;
167 }
168
169 int GetSize(RTLIL::Wire *wire)
170 {
171 return wire->width;
172 }
173
174 void yosys_setup()
175 {
176 Pass::init_register();
177 yosys_design = new RTLIL::Design;
178 log_push();
179 }
180
181 void yosys_shutdown()
182 {
183 log_pop();
184
185 delete yosys_design;
186 yosys_design = NULL;
187
188 for (auto f : log_files)
189 if (f != stderr)
190 fclose(f);
191 log_errfile = NULL;
192 log_files.clear();
193
194 Pass::done_register();
195
196 #ifdef YOSYS_ENABLE_TCL
197 if (yosys_tcl_interp != NULL) {
198 Tcl_DeleteInterp(yosys_tcl_interp);
199 Tcl_Finalize();
200 yosys_tcl_interp = NULL;
201 }
202 #endif
203
204 #ifdef YOSYS_ENABLE_PLUGINS
205 for (auto &it : loaded_plugins)
206 dlclose(it.second);
207 #endif
208
209 loaded_plugins.clear();
210 loaded_plugin_aliases.clear();
211 }
212
213 RTLIL::IdString new_id(std::string file, int line, std::string func)
214 {
215 std::string str = "$auto$";
216 size_t pos = file.find_last_of('/');
217 str += pos != std::string::npos ? file.substr(pos+1) : file;
218 str += stringf(":%d:%s$%d", line, func.c_str(), autoidx++);
219 return str;
220 }
221
222 RTLIL::Design *yosys_get_design()
223 {
224 return yosys_design;
225 }
226
227 const char *create_prompt(RTLIL::Design *design, int recursion_counter)
228 {
229 static char buffer[100];
230 std::string str = "\n";
231 if (recursion_counter > 1)
232 str += stringf("(%d) ", recursion_counter);
233 str += "yosys";
234 if (!design->selected_active_module.empty())
235 str += stringf(" [%s]", RTLIL::unescape_id(design->selected_active_module).c_str());
236 if (!design->selection_stack.empty() && !design->selection_stack.back().full_selection) {
237 if (design->selected_active_module.empty())
238 str += "*";
239 else if (design->selection_stack.back().selected_modules.size() != 1 || design->selection_stack.back().selected_members.size() != 0 ||
240 design->selection_stack.back().selected_modules.count(design->selected_active_module) == 0)
241 str += "*";
242 }
243 snprintf(buffer, 100, "%s> ", str.c_str());
244 return buffer;
245 }
246
247 #ifdef YOSYS_ENABLE_TCL
248 static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
249 {
250 std::vector<std::string> args;
251 for (int i = 1; i < argc; i++)
252 args.push_back(argv[i]);
253
254 if (args.size() >= 1 && args[0] == "-import") {
255 for (auto &it : pass_register) {
256 std::string tcl_command_name = it.first;
257 if (tcl_command_name == "proc")
258 tcl_command_name = "procs";
259 Tcl_CmdInfo info;
260 if (Tcl_GetCommandInfo(interp, tcl_command_name.c_str(), &info) != 0) {
261 log("[TCL: yosys -import] Command name collision: found pre-existing command `%s' -> skip.\n", it.first.c_str());
262 } else {
263 std::string tcl_script = stringf("proc %s args { yosys %s {*}$args }", tcl_command_name.c_str(), it.first.c_str());
264 Tcl_Eval(interp, tcl_script.c_str());
265 }
266 }
267 return TCL_OK;
268 }
269
270 if (args.size() == 1) {
271 Pass::call(yosys_get_design(), args[0]);
272 return TCL_OK;
273 }
274
275 Pass::call(yosys_get_design(), args);
276 return TCL_OK;
277 }
278
279 extern Tcl_Interp *yosys_get_tcl_interp()
280 {
281 if (yosys_tcl_interp == NULL) {
282 yosys_tcl_interp = Tcl_CreateInterp();
283 Tcl_CreateCommand(yosys_tcl_interp, "yosys", tcl_yosys_cmd, NULL, NULL);
284 }
285 return yosys_tcl_interp;
286 }
287
288 struct TclPass : public Pass {
289 TclPass() : Pass("tcl", "execute a TCL script file") { }
290 virtual void help() {
291 log("\n");
292 log(" tcl <filename>\n");
293 log("\n");
294 log("This command executes the tcl commands in the specified file.\n");
295 log("Use 'yosys cmd' to run the yosys command 'cmd' from tcl.\n");
296 log("\n");
297 log("The tcl command 'yosys -import' can be used to import all yosys\n");
298 log("commands directly as tcl commands to the tcl shell. The yosys\n");
299 log("command 'proc' is wrapped using the tcl command 'procs' in order\n");
300 log("to avoid a name collision with the tcl builting command 'proc'.\n");
301 log("\n");
302 }
303 virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
304 if (args.size() < 2)
305 log_cmd_error("Missing script file.\n");
306 if (args.size() > 2)
307 extra_args(args, 1, design, false);
308 if (Tcl_EvalFile(yosys_get_tcl_interp(), args[1].c_str()) != TCL_OK)
309 log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_get_tcl_interp()));
310 }
311 } TclPass;
312 #endif
313
314 #if defined(__linux__)
315 std::string proc_self_dirname()
316 {
317 char path[PATH_MAX];
318 ssize_t buflen = readlink("/proc/self/exe", path, sizeof(path));
319 if (buflen < 0) {
320 log_error("readlink(\"/proc/self/exe\") failed: %s\n", strerror(errno));
321 }
322 while (buflen > 0 && path[buflen-1] != '/')
323 buflen--;
324 return std::string(path, buflen);
325 }
326 #elif defined(__APPLE__)
327 #include <mach-o/dyld.h>
328 std::string proc_self_dirname()
329 {
330 char *path = NULL;
331 uint32_t buflen = 0;
332 while (_NSGetExecutablePath(path, &buflen) != 0)
333 path = (char *) realloc((void *) path, buflen);
334 while (buflen > 0 && path[buflen-1] != '/')
335 buflen--;
336 return std::string(path, buflen);
337 }
338 #elif defined(_WIN32)
339 std::string proc_self_dirname()
340 {
341 char path[MAX_PATH+1];
342 if (!GetModuleFileName(0, path, MAX_PATH+1))
343 log_error("GetModuleFileName() failed.\n");
344 for (int i = strlen(path)-1; i >= 0 && path[i] != '/' && path[i] != '\\' ; i--)
345 path[i] = 0;
346 return std::string(path);
347 }
348 #elif defined(EMSCRIPTEN)
349 std::string proc_self_dirname()
350 {
351 return "/";
352 }
353 #else
354 #error Dont know how to determine process executable base path!
355 #endif
356
357 std::string proc_share_dirname()
358 {
359 std::string proc_self_path = proc_self_dirname();
360 std::string proc_share_path = proc_self_path + "share/";
361 if (access(proc_share_path.c_str(), X_OK) == 0)
362 return proc_share_path;
363 proc_share_path = proc_self_path + "../share/yosys/";
364 if (access(proc_share_path.c_str(), X_OK) == 0)
365 return proc_share_path;
366 log_error("proc_share_dirname: unable to determine share/ directory!\n");
367 }
368
369 bool fgetline(FILE *f, std::string &buffer)
370 {
371 buffer = "";
372 char block[4096];
373 while (1) {
374 if (fgets(block, 4096, f) == NULL)
375 return false;
376 buffer += block;
377 if (buffer.size() > 0 && (buffer[buffer.size()-1] == '\n' || buffer[buffer.size()-1] == '\r')) {
378 while (buffer.size() > 0 && (buffer[buffer.size()-1] == '\n' || buffer[buffer.size()-1] == '\r'))
379 buffer.resize(buffer.size()-1);
380 return true;
381 }
382 }
383 }
384
385 static void handle_label(std::string &command, bool &from_to_active, const std::string &run_from, const std::string &run_to)
386 {
387 int pos = 0;
388 std::string label;
389
390 while (pos < GetSize(command) && (command[pos] == ' ' || command[pos] == '\t'))
391 pos++;
392
393 while (pos < GetSize(command) && command[pos] != ' ' && command[pos] != '\t' && command[pos] != '\r' && command[pos] != '\n')
394 label += command[pos++];
395
396 if (label.back() == ':' && GetSize(label) > 1)
397 {
398 label = label.substr(0, GetSize(label)-1);
399 command = command.substr(pos);
400
401 if (label == run_from)
402 from_to_active = true;
403 else if (label == run_to || (run_from == run_to && !run_from.empty()))
404 from_to_active = false;
405 }
406 }
407
408 void run_frontend(std::string filename, std::string command, RTLIL::Design *design, std::string *backend_command, std::string *from_to_label)
409 {
410 if (command == "auto") {
411 if (filename.size() > 2 && filename.substr(filename.size()-2) == ".v")
412 command = "verilog";
413 else if (filename.size() > 2 && filename.substr(filename.size()-3) == ".sv")
414 command = "verilog -sv";
415 else if (filename.size() > 3 && filename.substr(filename.size()-3) == ".il")
416 command = "ilang";
417 else if (filename.size() > 3 && filename.substr(filename.size()-3) == ".ys")
418 command = "script";
419 else if (filename == "-")
420 command = "script";
421 else
422 log_error("Can't guess frontend for input file `%s' (missing -f option)!\n", filename.c_str());
423 }
424
425 if (command == "script")
426 {
427 std::string run_from, run_to;
428 bool from_to_active = true;
429
430 if (from_to_label != NULL) {
431 size_t pos = from_to_label->find(':');
432 if (pos == std::string::npos) {
433 run_from = *from_to_label;
434 run_to = *from_to_label;
435 } else {
436 run_from = from_to_label->substr(0, pos);
437 run_to = from_to_label->substr(pos+1);
438 }
439 from_to_active = run_from.empty();
440 }
441
442 log("\n-- Executing script file `%s' --\n", filename.c_str());
443
444 FILE *f = stdin;
445
446 if (filename != "-")
447 f = fopen(filename.c_str(), "r");
448
449 if (f == NULL)
450 log_error("Can't open script file `%s' for reading: %s\n", filename.c_str(), strerror(errno));
451
452 FILE *backup_script_file = Frontend::current_script_file;
453 Frontend::current_script_file = f;
454
455 try {
456 std::string command;
457 while (fgetline(f, command)) {
458 while (!command.empty() && command[command.size()-1] == '\\') {
459 std::string next_line;
460 if (!fgetline(f, next_line))
461 break;
462 command.resize(command.size()-1);
463 command += next_line;
464 }
465 handle_label(command, from_to_active, run_from, run_to);
466 if (from_to_active)
467 Pass::call(design, command);
468 }
469
470 if (!command.empty()) {
471 handle_label(command, from_to_active, run_from, run_to);
472 if (from_to_active)
473 Pass::call(design, command);
474 }
475 }
476 catch (log_cmd_error_expection) {
477 Frontend::current_script_file = backup_script_file;
478 throw log_cmd_error_expection();
479 }
480
481 Frontend::current_script_file = backup_script_file;
482
483 if (filename != "-")
484 fclose(f);
485
486 if (backend_command != NULL && *backend_command == "auto")
487 *backend_command = "";
488
489 return;
490 }
491
492 if (filename == "-") {
493 log("\n-- Parsing stdin using frontend `%s' --\n", command.c_str());
494 } else {
495 log("\n-- Parsing `%s' using frontend `%s' --\n", filename.c_str(), command.c_str());
496 }
497
498 Frontend::frontend_call(design, NULL, filename, command);
499 }
500
501 void run_pass(std::string command, RTLIL::Design *design)
502 {
503 log("\n-- Running pass `%s' --\n", command.c_str());
504
505 Pass::call(design, command);
506 }
507
508 void run_backend(std::string filename, std::string command, RTLIL::Design *design)
509 {
510 if (command == "auto") {
511 if (filename.size() > 2 && filename.substr(filename.size()-2) == ".v")
512 command = "verilog";
513 else if (filename.size() > 3 && filename.substr(filename.size()-3) == ".il")
514 command = "ilang";
515 else if (filename.size() > 5 && filename.substr(filename.size()-5) == ".blif")
516 command = "blif";
517 else if (filename == "-")
518 command = "ilang";
519 else if (filename.empty())
520 return;
521 else
522 log_error("Can't guess backend for output file `%s' (missing -b option)!\n", filename.c_str());
523 }
524
525 if (filename.empty())
526 filename = "-";
527
528 if (filename == "-") {
529 log("\n-- Writing to stdout using backend `%s' --\n", command.c_str());
530 } else {
531 log("\n-- Writing to `%s' using backend `%s' --\n", filename.c_str(), command.c_str());
532 }
533
534 Backend::backend_call(design, NULL, filename, command);
535 }
536
537 #ifdef YOSYS_ENABLE_READLINE
538 static char *readline_cmd_generator(const char *text, int state)
539 {
540 static std::map<std::string, Pass*>::iterator it;
541 static int len;
542
543 if (!state) {
544 it = pass_register.begin();
545 len = strlen(text);
546 }
547
548 for (; it != pass_register.end(); it++) {
549 if (it->first.substr(0, len) == text)
550 return strdup((it++)->first.c_str());
551 }
552 return NULL;
553 }
554
555 static char *readline_obj_generator(const char *text, int state)
556 {
557 static std::vector<char*> obj_names;
558 static size_t idx;
559
560 if (!state)
561 {
562 idx = 0;
563 obj_names.clear();
564
565 RTLIL::Design *design = yosys_get_design();
566 int len = strlen(text);
567
568 if (design->selected_active_module.empty())
569 {
570 for (auto &it : design->modules_)
571 if (RTLIL::unescape_id(it.first).substr(0, len) == text)
572 obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
573 }
574 else
575 if (design->modules_.count(design->selected_active_module) > 0)
576 {
577 RTLIL::Module *module = design->modules_.at(design->selected_active_module);
578
579 for (auto &it : module->wires_)
580 if (RTLIL::unescape_id(it.first).substr(0, len) == text)
581 obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
582
583 for (auto &it : module->memories)
584 if (RTLIL::unescape_id(it.first).substr(0, len) == text)
585 obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
586
587 for (auto &it : module->cells_)
588 if (RTLIL::unescape_id(it.first).substr(0, len) == text)
589 obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
590
591 for (auto &it : module->processes)
592 if (RTLIL::unescape_id(it.first).substr(0, len) == text)
593 obj_names.push_back(strdup(RTLIL::id2cstr(it.first)));
594 }
595
596 std::sort(obj_names.begin(), obj_names.end());
597 }
598
599 if (idx < obj_names.size())
600 return strdup(obj_names[idx++]);
601
602 idx = 0;
603 obj_names.clear();
604 return NULL;
605 }
606
607 static char **readline_completion(const char *text, int start, int)
608 {
609 if (start == 0)
610 return rl_completion_matches(text, readline_cmd_generator);
611 if (strncmp(rl_line_buffer, "read_", 5) && strncmp(rl_line_buffer, "write_", 6))
612 return rl_completion_matches(text, readline_obj_generator);
613 return NULL;
614 }
615 #endif
616
617 void shell(RTLIL::Design *design)
618 {
619 static int recursion_counter = 0;
620
621 recursion_counter++;
622 log_cmd_error_throw = true;
623
624 #ifdef YOSYS_ENABLE_READLINE
625 rl_readline_name = "yosys";
626 rl_attempted_completion_function = readline_completion;
627 rl_basic_word_break_characters = " \t\n";
628 #endif
629
630 char *command = NULL;
631 #ifdef YOSYS_ENABLE_READLINE
632 while ((command = readline(create_prompt(design, recursion_counter))) != NULL)
633 #else
634 char command_buffer[4096];
635 while ((command = fgets(command_buffer, 4096, stdin)) != NULL)
636 #endif
637 {
638 if (command[strspn(command, " \t\r\n")] == 0)
639 continue;
640 #ifdef YOSYS_ENABLE_READLINE
641 add_history(command);
642 #endif
643
644 char *p = command + strspn(command, " \t\r\n");
645 if (!strncmp(p, "exit", 4)) {
646 p += 4;
647 p += strspn(p, " \t\r\n");
648 if (*p == 0)
649 break;
650 }
651
652 try {
653 log_assert(design->selection_stack.size() == 1);
654 Pass::call(design, command);
655 } catch (log_cmd_error_expection) {
656 while (design->selection_stack.size() > 1)
657 design->selection_stack.pop_back();
658 log_reset_stack();
659 }
660 }
661 if (command == NULL)
662 printf("exit\n");
663
664 recursion_counter--;
665 log_cmd_error_throw = false;
666 }
667
668 struct ShellPass : public Pass {
669 ShellPass() : Pass("shell", "enter interactive command mode") { }
670 virtual void help() {
671 log("\n");
672 log(" shell\n");
673 log("\n");
674 log("This command enters the interactive command mode. This can be useful\n");
675 log("in a script to interrupt the script at a certain point and allow for\n");
676 log("interactive inspection or manual synthesis of the design at this point.\n");
677 log("\n");
678 log("The command prompt of the interactive shell indicates the current\n");
679 log("selection (see 'help select'):\n");
680 log("\n");
681 log(" yosys>\n");
682 log(" the entire design is selected\n");
683 log("\n");
684 log(" yosys*>\n");
685 log(" only part of the design is selected\n");
686 log("\n");
687 log(" yosys [modname]>\n");
688 log(" the entire module 'modname' is selected using 'select -module modname'\n");
689 log("\n");
690 log(" yosys [modname]*>\n");
691 log(" only part of current module 'modname' is selected\n");
692 log("\n");
693 log("When in interactive shell, some errors (e.g. invalid command arguments)\n");
694 log("do not terminate yosys but return to the command prompt.\n");
695 log("\n");
696 log("This command is the default action if nothing else has been specified\n");
697 log("on the command line.\n");
698 log("\n");
699 log("Press Ctrl-D or type 'exit' to leave the interactive shell.\n");
700 log("\n");
701 }
702 virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
703 extra_args(args, 1, design, false);
704 shell(design);
705 }
706 } ShellPass;
707
708 #ifdef YOSYS_ENABLE_READLINE
709 struct HistoryPass : public Pass {
710 HistoryPass() : Pass("history", "show last interactive commands") { }
711 virtual void help() {
712 log("\n");
713 log(" history\n");
714 log("\n");
715 log("This command prints all commands in the shell history buffer. This are\n");
716 log("all commands executed in an interactive session, but not the commands\n");
717 log("from executed scripts.\n");
718 log("\n");
719 }
720 virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
721 extra_args(args, 1, design, false);
722 for(HIST_ENTRY **list = history_list(); *list != NULL; list++)
723 log("%s\n", (*list)->line);
724 }
725 } HistoryPass;
726 #endif
727
728 struct ScriptPass : public Pass {
729 ScriptPass() : Pass("script", "execute commands from script file") { }
730 virtual void help() {
731 log("\n");
732 log(" script <filename> [<from_label>:<to_label>]\n");
733 log("\n");
734 log("This command executes the yosys commands in the specified file.\n");
735 log("\n");
736 log("The 2nd argument can be used to only execute the section of the\n");
737 log("file between the specified labels. An empty from label is synonymous\n");
738 log("for the beginning of the file and an empty to label is synonymous\n");
739 log("for the end of the file.\n");
740 log("\n");
741 log("If only one label is specified (without ':') then only the block\n");
742 log("marked with that label (until the next label) is executed.\n");
743 log("\n");
744 }
745 virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
746 if (args.size() < 2)
747 log_cmd_error("Missing script file.\n");
748 else if (args.size() == 2)
749 run_frontend(args[1], "script", design, NULL, NULL);
750 else if (args.size() == 3)
751 run_frontend(args[1], "script", design, NULL, &args[2]);
752 else
753 extra_args(args, 2, design, false);
754 }
755 } ScriptPass;
756
757 YOSYS_NAMESPACE_END
758