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.
20 #include "kernel/yosys.h"
21 #include "kernel/celltypes.h"
23 #ifdef YOSYS_ENABLE_READLINE
24 # include <readline/readline.h>
25 # include <readline/history.h>
28 #ifdef YOSYS_ENABLE_PLUGINS
35 #elif defined(__APPLE__)
36 # include <mach-o/dyld.h>
39 # include <sys/stat.h>
43 # include <sys/types.h>
44 # include <sys/stat.h>
54 RTLIL::Design
*yosys_design
= NULL
;
55 CellTypes yosys_celltypes
;
57 #ifdef YOSYS_ENABLE_TCL
58 Tcl_Interp
*yosys_tcl_interp
= NULL
;
61 bool memhasher_active
= false;
62 uint32_t memhasher_rng
= 123456;
63 std::vector
<void*> memhasher_store
;
68 memhasher_rng
+= time(NULL
) << 16 ^ getpid();
70 memhasher_store
.resize(0x10000);
71 memhasher_active
= true;
76 for (auto p
: memhasher_store
)
78 memhasher_store
.clear();
79 memhasher_active
= false;
84 memhasher_rng
^= memhasher_rng
<< 13;
85 memhasher_rng
^= memhasher_rng
>> 17;
86 memhasher_rng
^= memhasher_rng
<< 5;
88 int size
, index
= (memhasher_rng
>> 4) & 0xffff;
89 switch (memhasher_rng
& 7) {
90 case 0: size
= 16; break;
91 case 1: size
= 256; break;
92 case 2: size
= 1024; break;
93 case 3: size
= 4096; break;
96 if (index
< 16) size
*= 16;
97 memhasher_store
[index
] = realloc(memhasher_store
[index
], size
);
100 std::string
stringf(const char *fmt
, ...)
106 string
= vstringf(fmt
, ap
);
112 std::string
vstringf(const char *fmt
, va_list ap
)
122 str
= (char*)realloc(str
, sz
);
123 rc
= vsnprintf(str
, sz
, fmt
, apc
);
125 if (rc
>= 0 && rc
< sz
)
130 if (vasprintf(&str
, fmt
, ap
) < 0)
142 int readsome(std::istream
&f
, char *s
, int n
)
144 int rc
= f
.readsome(s
, n
);
146 // f.readsome() sometimes returns 0 on a non-empty stream..
158 std::string
next_token(std::string
&text
, const char *sep
)
160 size_t pos_begin
= text
.find_first_not_of(sep
);
162 if (pos_begin
== std::string::npos
)
163 pos_begin
= text
.size();
165 size_t pos_end
= text
.find_first_of(sep
, pos_begin
);
167 if (pos_end
== std::string::npos
)
168 pos_end
= text
.size();
170 std::string token
= text
.substr(pos_begin
, pos_end
-pos_begin
);
171 text
= text
.substr(pos_end
);
175 // this is very similar to fnmatch(). the exact rules used by this
178 // ? matches any character except
179 // * matches any sequence of characters
180 // [...] matches any of the characters in the list
181 // [!..] matches any of the characters not in the list
183 // a backslash may be used to escape the next characters in the
184 // pattern. each special character can also simply match itself.
186 bool patmatch(const char *pattern
, const char *string
)
191 if (*pattern
== '\\') {
192 if (pattern
[1] == string
[0] && patmatch(pattern
+2, string
+1))
196 if (*pattern
== '?') {
199 return patmatch(pattern
+1, string
+1);
202 if (*pattern
== '*') {
204 if (patmatch(pattern
+1, string
++))
207 return pattern
[1] == 0;
210 if (*pattern
== '[') {
211 bool found_match
= false;
212 bool inverted_list
= pattern
[1] == '!';
213 const char *p
= pattern
+ (inverted_list
? 1 : 0);
217 if (found_match
!= inverted_list
&& patmatch(p
+1, string
+1))
231 if (*pattern
== *string
)
232 return patmatch(pattern
+1, string
+1);
237 int run_command(const std::string
&command
, std::function
<void(const std::string
&)> process_line
)
240 return system(command
.c_str());
242 FILE *f
= popen(command
.c_str(), "r");
248 while (fgets(logbuf
, 128, f
) != NULL
) {
250 if (!line
.empty() && line
.back() == '\n')
251 process_line(line
), line
.clear();
262 return WEXITSTATUS(ret
);
266 std::string
make_temp_file(std::string template_str
)
269 if (template_str
.rfind("/tmp/", 0) == 0) {
271 char longpath
[MAX_PATH
+ 1];
272 char shortpath
[MAX_PATH
+ 1];
274 WCHAR longpath
[MAX_PATH
+ 1];
275 TCHAR shortpath
[MAX_PATH
+ 1];
277 if (!GetTempPath(MAX_PATH
+1, longpath
))
278 log_error("GetTempPath() failed.\n");
279 if (!GetShortPathName(longpath
, shortpath
, MAX_PATH
+ 1))
280 log_error("GetShortPathName() failed.\n");
282 for (int i
= 0; shortpath
[i
]; i
++)
283 path
+= char(shortpath
[i
]);
284 template_str
= stringf("%s\\%s", path
.c_str(), template_str
.c_str() + 5);
287 size_t pos
= template_str
.rfind("XXXXXX");
288 log_assert(pos
!= std::string::npos
);
291 for (int i
= 0; i
< 6; i
++) {
292 static std::string y
= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
293 static uint32_t x
= 314159265 ^ uint32_t(time(NULL
));
294 x
^= x
<< 13, x
^= x
>> 17, x
^= x
<< 5;
295 template_str
[pos
+i
] = y
[x
% y
.size()];
297 if (_access(template_str
.c_str(), 0) != 0)
301 size_t pos
= template_str
.rfind("XXXXXX");
302 log_assert(pos
!= std::string::npos
);
304 int suffixlen
= GetSize(template_str
) - pos
- 6;
306 char *p
= strdup(template_str
.c_str());
307 close(mkstemps(p
, suffixlen
));
315 std::string
make_temp_dir(std::string template_str
)
318 template_str
= make_temp_file(template_str
);
319 mkdir(template_str
.c_str());
322 size_t pos
= template_str
.rfind("XXXXXX");
323 log_assert(pos
!= std::string::npos
);
325 int suffixlen
= GetSize(template_str
) - pos
- 6;
326 log_assert(suffixlen
== 0);
328 char *p
= strdup(template_str
.c_str());
330 log_assert(p
!= NULL
);
339 bool check_file_exists(std::string filename
, bool)
341 return _access(filename
.c_str(), 0) == 0;
344 bool check_file_exists(std::string filename
, bool is_exec
)
346 return access(filename
.c_str(), is_exec
? X_OK
: F_OK
) == 0;
350 void remove_directory(std::string dirname
)
353 run_command(stringf("rmdir /s /q \"%s\"", dirname
.c_str()));
356 struct dirent
**namelist
;
357 int n
= scandir(dirname
.c_str(), &namelist
, nullptr, alphasort
);
359 for (int i
= 0; i
< n
; i
++) {
360 if (strcmp(namelist
[i
]->d_name
, ".") && strcmp(namelist
[i
]->d_name
, "..")) {
361 std::string buffer
= stringf("%s/%s", dirname
.c_str(), namelist
[i
]->d_name
);
362 if (!stat(buffer
.c_str(), &stbuf
) && S_ISREG(stbuf
.st_mode
)) {
363 log("Removing `%s'.\n", buffer
.c_str());
364 remove(buffer
.c_str());
366 remove_directory(buffer
);
371 log("Removing `%s'.\n", dirname
.c_str());
372 rmdir(dirname
.c_str());
376 int GetSize(RTLIL::Wire
*wire
)
383 // if there are already IdString objects then we have a global initialization order bug
385 log_assert(empty_id
.index_
== 0);
386 IdString::get_reference(empty_id
.index_
);
388 Pass::init_register();
389 yosys_design
= new RTLIL::Design
;
390 yosys_celltypes
.setup();
394 void yosys_shutdown()
401 for (auto f
: log_files
)
407 Pass::done_register();
408 yosys_celltypes
.clear();
410 #ifdef YOSYS_ENABLE_TCL
411 if (yosys_tcl_interp
!= NULL
) {
412 Tcl_DeleteInterp(yosys_tcl_interp
);
414 yosys_tcl_interp
= NULL
;
418 #ifdef YOSYS_ENABLE_PLUGINS
419 for (auto &it
: loaded_plugins
)
422 loaded_plugins
.clear();
423 loaded_plugin_aliases
.clear();
427 RTLIL::IdString
new_id(std::string file
, int line
, std::string func
)
430 size_t pos
= file
.find_last_of("/\\");
432 size_t pos
= file
.find_last_of('/');
434 if (pos
!= std::string::npos
)
435 file
= file
.substr(pos
+1);
437 pos
= func
.find_last_of(':');
438 if (pos
!= std::string::npos
)
439 func
= func
.substr(pos
+1);
441 return stringf("$auto$%s:%d:%s$%d", file
.c_str(), line
, func
.c_str(), autoidx
++);
444 RTLIL::Design
*yosys_get_design()
449 const char *create_prompt(RTLIL::Design
*design
, int recursion_counter
)
451 static char buffer
[100];
452 std::string str
= "\n";
453 if (recursion_counter
> 1)
454 str
+= stringf("(%d) ", recursion_counter
);
456 if (!design
->selected_active_module
.empty())
457 str
+= stringf(" [%s]", RTLIL::unescape_id(design
->selected_active_module
).c_str());
458 if (!design
->selection_stack
.empty() && !design
->selection_stack
.back().full_selection
) {
459 if (design
->selected_active_module
.empty())
461 else if (design
->selection_stack
.back().selected_modules
.size() != 1 || design
->selection_stack
.back().selected_members
.size() != 0 ||
462 design
->selection_stack
.back().selected_modules
.count(design
->selected_active_module
) == 0)
465 snprintf(buffer
, 100, "%s> ", str
.c_str());
469 #ifdef YOSYS_ENABLE_TCL
470 static int tcl_yosys_cmd(ClientData
, Tcl_Interp
*interp
, int argc
, const char *argv
[])
472 std::vector
<std::string
> args
;
473 for (int i
= 1; i
< argc
; i
++)
474 args
.push_back(argv
[i
]);
476 if (args
.size() >= 1 && args
[0] == "-import") {
477 for (auto &it
: pass_register
) {
478 std::string tcl_command_name
= it
.first
;
479 if (tcl_command_name
== "proc")
480 tcl_command_name
= "procs";
482 if (Tcl_GetCommandInfo(interp
, tcl_command_name
.c_str(), &info
) != 0) {
483 log("[TCL: yosys -import] Command name collision: found pre-existing command `%s' -> skip.\n", it
.first
.c_str());
485 std::string tcl_script
= stringf("proc %s args { yosys %s {*}$args }", tcl_command_name
.c_str(), it
.first
.c_str());
486 Tcl_Eval(interp
, tcl_script
.c_str());
492 if (args
.size() == 1) {
493 Pass::call(yosys_get_design(), args
[0]);
497 Pass::call(yosys_get_design(), args
);
501 extern Tcl_Interp
*yosys_get_tcl_interp()
503 if (yosys_tcl_interp
== NULL
) {
504 yosys_tcl_interp
= Tcl_CreateInterp();
505 Tcl_CreateCommand(yosys_tcl_interp
, "yosys", tcl_yosys_cmd
, NULL
, NULL
);
507 return yosys_tcl_interp
;
510 struct TclPass
: public Pass
{
511 TclPass() : Pass("tcl", "execute a TCL script file") { }
512 virtual void help() {
514 log(" tcl <filename>\n");
516 log("This command executes the tcl commands in the specified file.\n");
517 log("Use 'yosys cmd' to run the yosys command 'cmd' from tcl.\n");
519 log("The tcl command 'yosys -import' can be used to import all yosys\n");
520 log("commands directly as tcl commands to the tcl shell. The yosys\n");
521 log("command 'proc' is wrapped using the tcl command 'procs' in order\n");
522 log("to avoid a name collision with the tcl builting command 'proc'.\n");
525 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
527 log_cmd_error("Missing script file.\n");
529 extra_args(args
, 1, design
, false);
530 if (Tcl_EvalFile(yosys_get_tcl_interp(), args
[1].c_str()) != TCL_OK
)
531 log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_get_tcl_interp()));
536 #if defined(__linux__)
537 std::string
proc_self_dirname()
540 ssize_t buflen
= readlink("/proc/self/exe", path
, sizeof(path
));
542 log_error("readlink(\"/proc/self/exe\") failed: %s\n", strerror(errno
));
544 while (buflen
> 0 && path
[buflen
-1] != '/')
546 return std::string(path
, buflen
);
548 #elif defined(__APPLE__)
549 std::string
proc_self_dirname()
553 while (_NSGetExecutablePath(path
, &buflen
) != 0)
554 path
= (char *) realloc((void *) path
, buflen
);
555 while (buflen
> 0 && path
[buflen
-1] != '/')
557 return std::string(path
, buflen
);
559 #elif defined(_WIN32)
560 std::string
proc_self_dirname()
564 char longpath
[MAX_PATH
+ 1];
565 char shortpath
[MAX_PATH
+ 1];
567 WCHAR longpath
[MAX_PATH
+ 1];
568 TCHAR shortpath
[MAX_PATH
+ 1];
570 if (!GetModuleFileName(0, longpath
, MAX_PATH
+1))
571 log_error("GetModuleFileName() failed.\n");
572 if (!GetShortPathName(longpath
, shortpath
, MAX_PATH
+1))
573 log_error("GetShortPathName() failed.\n");
574 while (shortpath
[i
] != 0)
576 while (i
> 0 && shortpath
[i
-1] != '/' && shortpath
[i
-1] != '\\')
579 for (i
= 0; shortpath
[i
]; i
++)
580 path
+= char(shortpath
[i
]);
583 #elif defined(EMSCRIPTEN)
584 std::string
proc_self_dirname()
589 #error Dont know how to determine process executable base path!
592 std::string
proc_share_dirname()
594 std::string proc_self_path
= proc_self_dirname();
596 std::string proc_share_path
= proc_self_path
+ "share\\";
597 if (check_file_exists(proc_share_path
, true))
598 return proc_share_path
;
599 proc_share_path
= proc_self_path
+ "..\\share\\";
600 if (check_file_exists(proc_share_path
, true))
601 return proc_share_path
;
603 std::string proc_share_path
= proc_self_path
+ "share/";
604 if (check_file_exists(proc_share_path
, true))
605 return proc_share_path
;
606 proc_share_path
= proc_self_path
+ "../share/yosys/";
607 if (check_file_exists(proc_share_path
, true))
608 return proc_share_path
;
610 log_error("proc_share_dirname: unable to determine share/ directory!\n");
613 bool fgetline(FILE *f
, std::string
&buffer
)
618 if (fgets(block
, 4096, f
) == NULL
)
621 if (buffer
.size() > 0 && (buffer
[buffer
.size()-1] == '\n' || buffer
[buffer
.size()-1] == '\r')) {
622 while (buffer
.size() > 0 && (buffer
[buffer
.size()-1] == '\n' || buffer
[buffer
.size()-1] == '\r'))
623 buffer
.resize(buffer
.size()-1);
629 static void handle_label(std::string
&command
, bool &from_to_active
, const std::string
&run_from
, const std::string
&run_to
)
634 while (pos
< GetSize(command
) && (command
[pos
] == ' ' || command
[pos
] == '\t'))
637 while (pos
< GetSize(command
) && command
[pos
] != ' ' && command
[pos
] != '\t' && command
[pos
] != '\r' && command
[pos
] != '\n')
638 label
+= command
[pos
++];
640 if (label
.back() == ':' && GetSize(label
) > 1)
642 label
= label
.substr(0, GetSize(label
)-1);
643 command
= command
.substr(pos
);
645 if (label
== run_from
)
646 from_to_active
= true;
647 else if (label
== run_to
|| (run_from
== run_to
&& !run_from
.empty()))
648 from_to_active
= false;
652 void run_frontend(std::string filename
, std::string command
, RTLIL::Design
*design
, std::string
*backend_command
, std::string
*from_to_label
)
654 if (command
== "auto") {
655 if (filename
.size() > 2 && filename
.substr(filename
.size()-2) == ".v")
657 else if (filename
.size() > 2 && filename
.substr(filename
.size()-3) == ".sv")
658 command
= "verilog -sv";
659 else if (filename
.size() > 3 && filename
.substr(filename
.size()-3) == ".il")
661 else if (filename
.size() > 3 && filename
.substr(filename
.size()-3) == ".ys")
663 else if (filename
== "-")
666 log_error("Can't guess frontend for input file `%s' (missing -f option)!\n", filename
.c_str());
669 if (command
== "script")
671 std::string run_from
, run_to
;
672 bool from_to_active
= true;
674 if (from_to_label
!= NULL
) {
675 size_t pos
= from_to_label
->find(':');
676 if (pos
== std::string::npos
) {
677 run_from
= *from_to_label
;
678 run_to
= *from_to_label
;
680 run_from
= from_to_label
->substr(0, pos
);
681 run_to
= from_to_label
->substr(pos
+1);
683 from_to_active
= run_from
.empty();
686 log("\n-- Executing script file `%s' --\n", filename
.c_str());
691 f
= fopen(filename
.c_str(), "r");
694 log_error("Can't open script file `%s' for reading: %s\n", filename
.c_str(), strerror(errno
));
696 FILE *backup_script_file
= Frontend::current_script_file
;
697 Frontend::current_script_file
= f
;
701 while (fgetline(f
, command
)) {
702 while (!command
.empty() && command
[command
.size()-1] == '\\') {
703 std::string next_line
;
704 if (!fgetline(f
, next_line
))
706 command
.resize(command
.size()-1);
707 command
+= next_line
;
709 handle_label(command
, from_to_active
, run_from
, run_to
);
711 Pass::call(design
, command
);
714 if (!command
.empty()) {
715 handle_label(command
, from_to_active
, run_from
, run_to
);
717 Pass::call(design
, command
);
720 catch (log_cmd_error_exception
) {
721 Frontend::current_script_file
= backup_script_file
;
722 throw log_cmd_error_exception();
725 Frontend::current_script_file
= backup_script_file
;
730 if (backend_command
!= NULL
&& *backend_command
== "auto")
731 *backend_command
= "";
736 if (filename
== "-") {
737 log("\n-- Parsing stdin using frontend `%s' --\n", command
.c_str());
739 log("\n-- Parsing `%s' using frontend `%s' --\n", filename
.c_str(), command
.c_str());
742 Frontend::frontend_call(design
, NULL
, filename
, command
);
745 void run_pass(std::string command
, RTLIL::Design
*design
)
747 log("\n-- Running pass `%s' --\n", command
.c_str());
749 Pass::call(design
, command
);
752 void run_backend(std::string filename
, std::string command
, RTLIL::Design
*design
)
754 if (command
== "auto") {
755 if (filename
.size() > 2 && filename
.substr(filename
.size()-2) == ".v")
757 else if (filename
.size() > 3 && filename
.substr(filename
.size()-3) == ".il")
759 else if (filename
.size() > 5 && filename
.substr(filename
.size()-5) == ".blif")
761 else if (filename
== "-")
763 else if (filename
.empty())
766 log_error("Can't guess backend for output file `%s' (missing -b option)!\n", filename
.c_str());
769 if (filename
.empty())
772 if (filename
== "-") {
773 log("\n-- Writing to stdout using backend `%s' --\n", command
.c_str());
775 log("\n-- Writing to `%s' using backend `%s' --\n", filename
.c_str(), command
.c_str());
778 Backend::backend_call(design
, NULL
, filename
, command
);
781 #ifdef YOSYS_ENABLE_READLINE
782 static char *readline_cmd_generator(const char *text
, int state
)
784 static std::map
<std::string
, Pass
*>::iterator it
;
788 it
= pass_register
.begin();
792 for (; it
!= pass_register
.end(); it
++) {
793 if (it
->first
.substr(0, len
) == text
)
794 return strdup((it
++)->first
.c_str());
799 static char *readline_obj_generator(const char *text
, int state
)
801 static std::vector
<char*> obj_names
;
809 RTLIL::Design
*design
= yosys_get_design();
810 int len
= strlen(text
);
812 if (design
->selected_active_module
.empty())
814 for (auto &it
: design
->modules_
)
815 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
816 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
)));
819 if (design
->modules_
.count(design
->selected_active_module
) > 0)
821 RTLIL::Module
*module
= design
->modules_
.at(design
->selected_active_module
);
823 for (auto &it
: module
->wires_
)
824 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
825 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
)));
827 for (auto &it
: module
->memories
)
828 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
829 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
)));
831 for (auto &it
: module
->cells_
)
832 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
833 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
)));
835 for (auto &it
: module
->processes
)
836 if (RTLIL::unescape_id(it
.first
).substr(0, len
) == text
)
837 obj_names
.push_back(strdup(RTLIL::id2cstr(it
.first
)));
840 std::sort(obj_names
.begin(), obj_names
.end());
843 if (idx
< obj_names
.size())
844 return strdup(obj_names
[idx
++]);
851 static char **readline_completion(const char *text
, int start
, int)
854 return rl_completion_matches(text
, readline_cmd_generator
);
855 if (strncmp(rl_line_buffer
, "read_", 5) && strncmp(rl_line_buffer
, "write_", 6))
856 return rl_completion_matches(text
, readline_obj_generator
);
861 void shell(RTLIL::Design
*design
)
863 static int recursion_counter
= 0;
866 log_cmd_error_throw
= true;
868 #ifdef YOSYS_ENABLE_READLINE
869 rl_readline_name
= "yosys";
870 rl_attempted_completion_function
= readline_completion
;
871 rl_basic_word_break_characters
= " \t\n";
874 char *command
= NULL
;
875 #ifdef YOSYS_ENABLE_READLINE
876 while ((command
= readline(create_prompt(design
, recursion_counter
))) != NULL
)
879 char command_buffer
[4096];
882 fputs(create_prompt(design
, recursion_counter
), stdout
);
884 if ((command
= fgets(command_buffer
, 4096, stdin
)) == NULL
)
887 if (command
[strspn(command
, " \t\r\n")] == 0)
889 #ifdef YOSYS_ENABLE_READLINE
890 add_history(command
);
893 char *p
= command
+ strspn(command
, " \t\r\n");
894 if (!strncmp(p
, "exit", 4)) {
896 p
+= strspn(p
, " \t\r\n");
902 log_assert(design
->selection_stack
.size() == 1);
903 Pass::call(design
, command
);
904 } catch (log_cmd_error_exception
) {
905 while (design
->selection_stack
.size() > 1)
906 design
->selection_stack
.pop_back();
914 log_cmd_error_throw
= false;
917 struct ShellPass
: public Pass
{
918 ShellPass() : Pass("shell", "enter interactive command mode") { }
919 virtual void help() {
923 log("This command enters the interactive command mode. This can be useful\n");
924 log("in a script to interrupt the script at a certain point and allow for\n");
925 log("interactive inspection or manual synthesis of the design at this point.\n");
927 log("The command prompt of the interactive shell indicates the current\n");
928 log("selection (see 'help select'):\n");
931 log(" the entire design is selected\n");
934 log(" only part of the design is selected\n");
936 log(" yosys [modname]>\n");
937 log(" the entire module 'modname' is selected using 'select -module modname'\n");
939 log(" yosys [modname]*>\n");
940 log(" only part of current module 'modname' is selected\n");
942 log("When in interactive shell, some errors (e.g. invalid command arguments)\n");
943 log("do not terminate yosys but return to the command prompt.\n");
945 log("This command is the default action if nothing else has been specified\n");
946 log("on the command line.\n");
948 log("Press Ctrl-D or type 'exit' to leave the interactive shell.\n");
951 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
952 extra_args(args
, 1, design
, false);
957 #ifdef YOSYS_ENABLE_READLINE
958 struct HistoryPass
: public Pass
{
959 HistoryPass() : Pass("history", "show last interactive commands") { }
960 virtual void help() {
964 log("This command prints all commands in the shell history buffer. This are\n");
965 log("all commands executed in an interactive session, but not the commands\n");
966 log("from executed scripts.\n");
969 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
970 extra_args(args
, 1, design
, false);
971 for(HIST_ENTRY
**list
= history_list(); *list
!= NULL
; list
++)
972 log("%s\n", (*list
)->line
);
977 struct ScriptPass
: public Pass
{
978 ScriptPass() : Pass("script", "execute commands from script file") { }
979 virtual void help() {
981 log(" script <filename> [<from_label>:<to_label>]\n");
983 log("This command executes the yosys commands in the specified file.\n");
985 log("The 2nd argument can be used to only execute the section of the\n");
986 log("file between the specified labels. An empty from label is synonymous\n");
987 log("for the beginning of the file and an empty to label is synonymous\n");
988 log("for the end of the file.\n");
990 log("If only one label is specified (without ':') then only the block\n");
991 log("marked with that label (until the next label) is executed.\n");
994 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) {
996 log_cmd_error("Missing script file.\n");
997 else if (args
.size() == 2)
998 run_frontend(args
[1], "script", design
, NULL
, NULL
);
999 else if (args
.size() == 3)
1000 run_frontend(args
[1], "script", design
, NULL
, &args
[2]);
1002 extra_args(args
, 2, design
, false);