2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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.
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.
21 #include <readline/readline.h>
22 #include <readline/history.h>
32 #include "kernel/rtlil.h"
33 #include "kernel/register.h"
34 #include "kernel/log.h"
36 bool fgetline(FILE *f
, std::string
&buffer
)
41 if (fgets(block
, 4096, f
) == NULL
)
44 if (buffer
.size() > 0 && (buffer
[buffer
.size()-1] == '\n' || buffer
[buffer
.size()-1] == '\r')) {
45 while (buffer
.size() > 0 && (buffer
[buffer
.size()-1] == '\n' || buffer
[buffer
.size()-1] == '\r'))
46 buffer
.resize(buffer
.size()-1);
52 static void handle_label(std::string
&command
, bool &from_to_active
, const std::string
&run_from
, const std::string
&run_to
)
57 while (pos
< SIZE(command
) && (command
[pos
] == ' ' || command
[pos
] == '\t'))
60 while (pos
< SIZE(command
) && command
[pos
] != ' ' && command
[pos
] != '\t' && command
[pos
] != '\r' && command
[pos
] != '\n')
61 label
+= command
[pos
++];
63 if (label
.back() == ':' && SIZE(label
) > 1)
65 label
= label
.substr(0, SIZE(label
)-1);
66 command
= command
.substr(pos
);
68 if (label
== run_from
)
69 from_to_active
= true;
70 else if (label
== run_to
|| (run_from
== run_to
&& !run_from
.empty()))
71 from_to_active
= false;
75 static void run_frontend(std::string filename
, std::string command
, RTLIL::Design
*design
, std::string
*backend_command
, std::string
*from_to_label
)
77 if (command
== "auto") {
78 if (filename
.size() > 2 && filename
.substr(filename
.size()-2) == ".v")
80 else if (filename
.size() > 2 && filename
.substr(filename
.size()-3) == ".sv")
81 command
= "verilog -sv";
82 else if (filename
.size() > 3 && filename
.substr(filename
.size()-3) == ".il")
84 else if (filename
.size() > 3 && filename
.substr(filename
.size()-3) == ".ys")
86 else if (filename
== "-")
89 log_error("Can't guess frontend for input file `%s' (missing -f option)!\n", filename
.c_str());
92 if (command
== "script")
94 std::string run_from
, run_to
;
95 bool from_to_active
= true;
97 if (from_to_label
!= NULL
) {
98 size_t pos
= from_to_label
->find(':');
99 if (pos
== std::string::npos
) {
100 run_from
= *from_to_label
;
101 run_to
= *from_to_label
;
103 run_from
= from_to_label
->substr(0, pos
);
104 run_to
= from_to_label
->substr(pos
+1);
106 from_to_active
= run_from
.empty();
109 log("\n-- Executing script file `%s' --\n", filename
.c_str());
114 f
= fopen(filename
.c_str(), "r");
117 log_error("Can't open script file `%s' for reading: %s\n", filename
.c_str(), strerror(errno
));
120 while (fgetline(f
, command
)) {
121 while (!command
.empty() && command
[command
.size()-1] == '\\') {
122 std::string next_line
;
123 if (!fgetline(f
, next_line
))
125 command
.resize(command
.size()-1);
126 command
+= next_line
;
128 handle_label(command
, from_to_active
, run_from
, run_to
);
130 Pass::call(design
, command
);
133 if (!command
.empty()) {
134 handle_label(command
, from_to_active
, run_from
, run_to
);
136 Pass::call(design
, command
);
142 if (backend_command
!= NULL
&& *backend_command
== "auto")
143 *backend_command
= "";
148 if (filename
== "-") {
149 log("\n-- Parsing stdin using frontend `%s' --\n", command
.c_str());
151 log("\n-- Parsing `%s' using frontend `%s' --\n", filename
.c_str(), command
.c_str());
154 Frontend::frontend_call(design
, NULL
, filename
, command
);
157 static void run_pass(std::string command
, RTLIL::Design
*design
)
159 log("\n-- Running pass `%s' --\n", command
.c_str());
161 Pass::call(design
, command
);
164 static void run_backend(std::string filename
, std::string command
, RTLIL::Design
*design
)
166 if (command
== "auto") {
167 if (filename
.size() > 2 && filename
.substr(filename
.size()-2) == ".v")
169 else if (filename
.size() > 3 && filename
.substr(filename
.size()-3) == ".il")
171 else if (filename
.size() > 5 && filename
.substr(filename
.size()-5) == ".blif")
173 else if (filename
== "-")
175 else if (filename
.empty())
178 log_error("Can't guess backend for output file `%s' (missing -b option)!\n", filename
.c_str());
181 if (filename
.empty())
184 if (filename
== "-") {
185 log("\n-- Writing to stdout using backend `%s' --\n", command
.c_str());
187 log("\n-- Writing to `%s' using backend `%s' --\n", filename
.c_str(), command
.c_str());
190 Backend::backend_call(design
, NULL
, filename
, command
);
193 static char *readline_cmd_generator(const char *text
, int state
)
195 static std::map
<std::string
, Pass
*>::iterator it
;
199 it
= REGISTER_INTERN::pass_register
.begin();
203 for (; it
!= REGISTER_INTERN::pass_register
.end(); it
++) {
204 if (it
->first
.substr(0, len
) == text
)
205 return strdup((it
++)->first
.c_str());
210 static char *readline_obj_generator(const char *text
, int state
)
212 static std::vector
<char*> obj_names
;
220 RTLIL::Design
*design
= yosys_get_design();
221 int len
= strlen(text
);
223 if (design
->selected_active_module
.empty())
225 for (auto &it
: design
->modules
)
226 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
227 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
.c_str())));
230 if (design
->modules
.count(design
->selected_active_module
) > 0)
232 RTLIL::Module
*module
= design
->modules
.at(design
->selected_active_module
);
234 for (auto &it
: module
->wires
)
235 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
236 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
.c_str())));
238 for (auto &it
: module
->memories
)
239 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
240 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
.c_str())));
242 for (auto &it
: module
->cells
)
243 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
244 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
.c_str())));
246 for (auto &it
: module
->processes
)
247 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
248 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
.c_str())));
251 std::sort(obj_names
.begin(), obj_names
.end());
254 if (idx
< obj_names
.size())
255 return strdup(obj_names
[idx
++]);
262 static char **readline_completion(const char *text
, int start
, int)
265 return rl_completion_matches(text
, readline_cmd_generator
);
266 if (strncmp(rl_line_buffer
, "read_", 5) && strncmp(rl_line_buffer
, "write_", 6))
267 return rl_completion_matches(text
, readline_obj_generator
);
271 const char *create_prompt(RTLIL::Design
*design
, int recursion_counter
)
273 static char buffer
[100];
274 std::string str
= "\n";
275 if (recursion_counter
> 1)
276 str
+= stringf("(%d) ", recursion_counter
);
278 if (!design
->selected_active_module
.empty())
279 str
+= stringf(" [%s]", RTLIL::id2cstr(design
->selected_active_module
));
280 if (!design
->selection_stack
.back().full_selection
) {
281 if (design
->selected_active_module
.empty())
283 else if (design
->selection_stack
.back().selected_modules
.size() != 1 || design
->selection_stack
.back().selected_members
.size() != 0 ||
284 design
->selection_stack
.back().selected_modules
.count(design
->selected_active_module
) == 0)
287 snprintf(buffer
, 100, "%s> ", str
.c_str());
291 static void shell(RTLIL::Design
*design
)
293 static int recursion_counter
= 0;
296 log_cmd_error_throw
= true;
298 rl_readline_name
= "yosys";
299 rl_attempted_completion_function
= readline_completion
;
300 rl_basic_word_break_characters
= " \t\n";
302 char *command
= NULL
;
303 while ((command
= readline(create_prompt(design
, recursion_counter
))) != NULL
)
305 if (command
[strspn(command
, " \t\r\n")] == 0)
307 add_history(command
);
309 char *p
= command
+ strspn(command
, " \t\r\n");
310 if (!strncmp(p
, "exit", 4)) {
312 p
+= strspn(p
, " \t\r\n");
318 assert(design
->selection_stack
.size() == 1);
319 Pass::call(design
, command
);
321 while (design
->selection_stack
.size() > 1)
322 design
->selection_stack
.pop_back();
330 log_cmd_error_throw
= false;
333 struct ShellPass
: public Pass
{
334 ShellPass() : Pass("shell", "enter interactive command mode") { }
335 virtual void help() {
339 log("This command enters the interactive command mode. This can be useful\n");
340 log("in a script to interrupt the script at a certain point and allow for\n");
341 log("interactive inspection or manual synthesis of the design at this point.\n");
343 log("The command prompt of the interactive shell indicates the current\n");
344 log("selection (see 'help select'):\n");
347 log(" the entire design is selected\n");
350 log(" only part of the design is selected\n");
352 log(" yosys [modname]>\n");
353 log(" the entire module 'modname' is selected using 'select -module modname'\n");
355 log(" yosys [modname]*>\n");
356 log(" only part of current module 'modname' is selected\n");
358 log("When in interactive shell, some errors (e.g. invalid command arguments)\n");
359 log("do not terminate yosys but return to the command prompt.\n");
361 log("This command is the default action if nothing else has been specified\n");
362 log("on the command line.\n");
364 log("Press Ctrl-D or type 'exit' to leave the interactive shell.\n");
367 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
368 extra_args(args
, 1, design
, false);
373 struct HistoryPass
: public Pass
{
374 HistoryPass() : Pass("history", "show last interactive commands") { }
375 virtual void help() {
379 log("This command prints all commands in the shell history buffer. This are\n");
380 log("all commands executed in an interactive session, but not the commands\n");
381 log("from executed scripts.\n");
384 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
385 extra_args(args
, 1, design
, false);
386 for(HIST_ENTRY
**list
= history_list(); *list
!= NULL
; list
++)
387 log("%s\n", (*list
)->line
);
391 struct ScriptPass
: public Pass
{
392 ScriptPass() : Pass("script", "execute commands from script file") { }
393 virtual void help() {
395 log(" script <filename> [<from_label>:<to_label>]\n");
397 log("This command executes the yosys commands in the specified file.\n");
399 log("The 2nd argument can be used to only execute the section of the\n");
400 log("file between the specified labels. An empty from label is synonymous\n");
401 log("for the beginning of the file and an empty to label is synonymous\n");
402 log("for the end of the file.\n");
404 log("If only one label is specified (without ':') then only the block\n");
405 log("marked with that label (until the next label) is executed.\n");
408 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
410 log_cmd_error("Missing script file.\n");
411 else if (args
.size() == 2)
412 run_frontend(args
[1], "script", design
, NULL
, NULL
);
413 else if (args
.size() == 3)
414 run_frontend(args
[1], "script", design
, NULL
, &args
[2]);
416 extra_args(args
, 2, design
, false);
420 #ifdef YOSYS_ENABLE_TCL
421 static Tcl_Interp
*yosys_tcl_interp
= NULL
;
423 static int tcl_yosys_cmd(ClientData
, Tcl_Interp
*interp
, int argc
, const char *argv
[])
425 std::vector
<std::string
> args
;
426 for (int i
= 1; i
< argc
; i
++)
427 args
.push_back(argv
[i
]);
429 if (args
.size() >= 1 && args
[0] == "-import") {
430 for (auto &it
: REGISTER_INTERN::pass_register
) {
431 std::string tcl_command_name
= it
.first
;
432 if (tcl_command_name
== "proc")
433 tcl_command_name
= "procs";
435 if (Tcl_GetCommandInfo(interp
, tcl_command_name
.c_str(), &info
) != 0) {
436 log("[TCL: yosys -import] Command name collision: found pre-existing command `%s' -> skip.\n", it
.first
.c_str());
438 std::string tcl_script
= stringf("proc %s args { yosys %s {*}$args }", tcl_command_name
.c_str(), it
.first
.c_str());
439 Tcl_Eval(interp
, tcl_script
.c_str());
445 if (args
.size() == 1) {
446 Pass::call(yosys_get_design(), args
[0]);
450 Pass::call(yosys_get_design(), args
);
454 extern Tcl_Interp
*yosys_get_tcl_interp()
456 if (yosys_tcl_interp
== NULL
) {
457 yosys_tcl_interp
= Tcl_CreateInterp();
458 Tcl_CreateCommand(yosys_tcl_interp
, "yosys", tcl_yosys_cmd
, NULL
, NULL
);
460 return yosys_tcl_interp
;
463 struct TclPass
: public Pass
{
464 TclPass() : Pass("tcl", "execute a TCL script file") { }
465 virtual void help() {
467 log(" tcl <filename>\n");
469 log("This command executes the tcl commands in the specified file.\n");
470 log("Use 'yosys cmd' to run the yosys command 'cmd' from tcl.\n");
472 log("The tcl command 'yosys -import' can be used to import all yosys\n");
473 log("commands directly as tcl commands to the tcl shell. The yosys\n");
474 log("command 'proc' is wrapped using the tcl command 'procs' in order\n");
475 log("to avoid a name collision with the tcl builting command 'proc'.\n");
478 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
480 log_cmd_error("Missing script file.\n");
482 extra_args(args
, 1, design
, false);
483 if (Tcl_EvalFile(yosys_get_tcl_interp(), args
[1].c_str()) != TCL_OK
)
484 log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_get_tcl_interp()));
489 static RTLIL::Design
*yosys_design
= NULL
;
491 extern RTLIL::Design
*yosys_get_design()
496 #if defined(__linux__)
497 std::string
proc_self_dirname ()
499 char path
[PATH_MAX
];
500 ssize_t buflen
= readlink("/proc/self/exe", path
, sizeof(path
));
502 log_cmd_error("readlink(\"/proc/self/exe\") failed: %s", strerror(errno
));
505 while (buflen
> 0 && path
[buflen
-1] != '/')
507 return std::string(path
, buflen
);
509 #elif defined(__APPLE__)
510 #include <mach-o/dyld.h>
511 std::string
proc_self_dirname ()
515 while (_NSGetExecutablePath(path
, &buflen
) != 0)
516 path
= (char *) realloc((void *) path
, buflen
);
517 while (buflen
> 0 && path
[buflen
-1] != '/')
519 return std::string(path
, buflen
);
522 #error Dont know how to determine process executable base path!
525 std::string
proc_share_dirname ()
527 std::string proc_self_path
= proc_self_dirname();
528 std::string proc_share_path
= proc_self_path
+ "share/";
529 if (access(proc_share_path
.c_str(), X_OK
) == 0)
530 return proc_share_path
;
531 proc_share_path
= proc_self_path
+ "../share/yosys/";
532 if (access(proc_share_path
.c_str(), X_OK
) == 0)
533 return proc_share_path
;
534 log_cmd_error("proc_share_dirname: unable to determine share/ directory!");
538 int main(int argc
, char **argv
)
540 std::string frontend_command
= "auto";
541 std::string backend_command
= "auto";
542 std::vector
<std::string
> passes_commands
;
543 std::vector
<void*> loaded_modules
;
544 std::string output_filename
= "";
545 std::string scriptfile
= "";
546 bool scriptfile_tcl
= false;
547 bool got_output_filename
= false;
549 int history_offset
= 0;
550 std::string history_file
;
551 if (getenv("HOME") != NULL
) {
552 history_file
= stringf("%s/.yosys_history", getenv("HOME"));
553 read_history(history_file
.c_str());
554 history_offset
= where_history();
558 while ((opt
= getopt(argc
, argv
, "VSm:f:Hh:b:o:p:l:qv:ts:c:")) != -1)
563 printf("%s\n", yosys_version_str
);
566 passes_commands
.push_back("hierarchy");
567 passes_commands
.push_back("proc");
568 passes_commands
.push_back("opt");
569 passes_commands
.push_back("memory");
570 passes_commands
.push_back("opt");
571 passes_commands
.push_back("techmap");
572 passes_commands
.push_back("opt");
575 loaded_modules
.push_back(dlopen(optarg
, RTLD_LAZY
|RTLD_GLOBAL
));
576 if (loaded_modules
.back() == NULL
) {
577 fprintf(stderr
, "Can't load module `%s': %s\n", optarg
, dlerror());
582 frontend_command
= optarg
;
585 passes_commands
.push_back("help");
588 passes_commands
.push_back(stringf("help %s", optarg
));
591 backend_command
= optarg
;
594 passes_commands
.push_back(optarg
);
597 output_filename
= optarg
;
598 got_output_filename
= true;
601 log_files
.push_back(fopen(optarg
, "wt"));
602 if (log_files
.back() == NULL
) {
603 fprintf(stderr
, "Can't open log file `%s' for writing!\n", optarg
);
608 log_errfile
= stderr
;
611 log_errfile
= stderr
;
612 log_verbose_level
= atoi(optarg
);
619 scriptfile_tcl
= false;
623 scriptfile_tcl
= true;
626 fprintf(stderr
, "\n");
627 fprintf(stderr
, "Usage: %s [-V] [-S] [-q] [-v <level>[-t] [-l <logfile>] [-o <outfile>] [-f <frontend>] [-h cmd] \\\n", argv
[0]);
628 fprintf(stderr
, " %*s[{-s|-c} <scriptfile>] [-p <pass> [-p ..]] [-b <backend>] [-m <module_file>] [<infile> [..]]\n", int(strlen(argv
[0])+1), "");
629 fprintf(stderr
, "\n");
630 fprintf(stderr
, " -q\n");
631 fprintf(stderr
, " quiet operation. only write error messages to console\n");
632 fprintf(stderr
, "\n");
633 fprintf(stderr
, " -v <level>\n");
634 fprintf(stderr
, " print log headers up to level <level> to the console. (implies -q)\n");
635 fprintf(stderr
, "\n");
636 fprintf(stderr
, " -t\n");
637 fprintf(stderr
, " annotate all log messages with a time stamp\n");
638 fprintf(stderr
, "\n");
639 fprintf(stderr
, " -l logfile\n");
640 fprintf(stderr
, " write log messages to the specified file\n");
641 fprintf(stderr
, "\n");
642 fprintf(stderr
, " -o outfile\n");
643 fprintf(stderr
, " write the design to the specified file on exit\n");
644 fprintf(stderr
, "\n");
645 fprintf(stderr
, " -b backend\n");
646 fprintf(stderr
, " use this backend for the output file specified on the command line\n");
647 fprintf(stderr
, "\n");
648 fprintf(stderr
, " -f backend\n");
649 fprintf(stderr
, " use the specified front for the input files on the command line\n");
650 fprintf(stderr
, "\n");
651 fprintf(stderr
, " -H\n");
652 fprintf(stderr
, " print the command list\n");
653 fprintf(stderr
, "\n");
654 fprintf(stderr
, " -h command\n");
655 fprintf(stderr
, " print the help message for the specified command\n");
656 fprintf(stderr
, "\n");
657 fprintf(stderr
, " -s scriptfile\n");
658 fprintf(stderr
, " execute the commands in the script file\n");
659 fprintf(stderr
, "\n");
660 fprintf(stderr
, " -c tcl_scriptfile\n");
661 fprintf(stderr
, " execute the commands in the tcl script file (see 'help tcl' for details)\n");
662 fprintf(stderr
, "\n");
663 fprintf(stderr
, " -p command\n");
664 fprintf(stderr
, " execute the commands\n");
665 fprintf(stderr
, "\n");
666 fprintf(stderr
, " -m module_file\n");
667 fprintf(stderr
, " load the specified module (aka plugin)\n");
668 fprintf(stderr
, "\n");
669 fprintf(stderr
, " -V\n");
670 fprintf(stderr
, " print version information and exit\n");
671 fprintf(stderr
, "\n");
672 fprintf(stderr
, "The option -S is an alias for the following options that perform a simple\n");
673 fprintf(stderr
, "transformation of the input to a gate-level netlist.\n");
674 fprintf(stderr
, "\n");
675 fprintf(stderr
, " -p hierarchy -p proc -p opt -p memory -p opt -p techmap -p opt\n");
676 fprintf(stderr
, "\n");
677 fprintf(stderr
, "For more complex synthesis jobs it is recommended to use the read_* and write_*\n");
678 fprintf(stderr
, "commands in a script file instead of specifying input and output files on the\n");
679 fprintf(stderr
, "command line.\n");
680 fprintf(stderr
, "\n");
681 fprintf(stderr
, "When no commands, script files or input files are specified on the command\n");
682 fprintf(stderr
, "line, yosys automatically enters the interactive command mode. Use the 'help'\n");
683 fprintf(stderr
, "command to get information on the individual commands.\n");
684 fprintf(stderr
, "\n");
689 if (log_errfile
== NULL
)
690 log_files
.push_back(stderr
);
693 log(" /-----------------------------------------------------------------------------\\\n");
695 log(" | yosys -- Yosys Open SYnthesis Suite |\n");
697 log(" | Copyright (C) 2012 Clifford Wolf <clifford@clifford.at> |\n");
699 log(" | Permission to use, copy, modify, and/or distribute this software for any |\n");
700 log(" | purpose with or without fee is hereby granted, provided that the above |\n");
701 log(" | copyright notice and this permission notice appear in all copies. |\n");
703 log(" | THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |\n");
704 log(" | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |\n");
705 log(" | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |\n");
706 log(" | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |\n");
707 log(" | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |\n");
708 log(" | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |\n");
709 log(" | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |\n");
711 log(" \\-----------------------------------------------------------------------------/\n");
713 log(" %s\n", yosys_version_str
);
716 Pass::init_register();
718 yosys_design
= new RTLIL::Design
;
719 yosys_design
->selection_stack
.push_back(RTLIL::Selection());
722 if (optind
== argc
&& passes_commands
.size() == 0 && scriptfile
.empty()) {
723 if (!got_output_filename
)
724 backend_command
= "";
728 while (optind
< argc
)
729 run_frontend(argv
[optind
++], frontend_command
, yosys_design
, output_filename
== "-" ? &backend_command
: NULL
, NULL
);
731 if (!scriptfile
.empty()) {
732 if (scriptfile_tcl
) {
733 #ifdef YOSYS_ENABLE_TCL
734 if (Tcl_EvalFile(yosys_get_tcl_interp(), scriptfile
.c_str()) != TCL_OK
)
735 log_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_get_tcl_interp()));
737 log_error("Can't exectue TCL script: this version of yosys is not built with TCL support enabled.\n");
740 run_frontend(scriptfile
, "script", yosys_design
, output_filename
== "-" ? &backend_command
: NULL
, NULL
);
743 for (auto it
= passes_commands
.begin(); it
!= passes_commands
.end(); it
++)
744 run_pass(*it
, yosys_design
);
746 if (!backend_command
.empty())
747 run_backend(output_filename
, backend_command
, yosys_design
);
755 if (!history_file
.empty()) {
756 if (history_offset
> 0) {
757 history_truncate_file(history_file
.c_str(), 100);
758 append_history(where_history() - history_offset
, history_file
.c_str());
760 write_history(history_file
.c_str());
764 HIST_ENTRY
**hist_list
= history_list();
765 if (hist_list
!= NULL
)
768 for (auto f
: log_files
)
774 Pass::done_register();
776 for (auto mod
: loaded_modules
)
779 #ifdef YOSYS_ENABLE_TCL
780 if (yosys_tcl_interp
!= NULL
) {
781 Tcl_DeleteInterp(yosys_tcl_interp
);
783 yosys_tcl_interp
= NULL
;