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