Add TCL interactive shell mode

This commit is contained in:
Miodrag Milanovic 2022-11-25 16:18:02 +01:00
parent c55c514cdb
commit 2450e6be22
2 changed files with 34 additions and 8 deletions

View File

@ -202,6 +202,11 @@ extern char *yosys_argv0;
extern char yosys_path[PATH_MAX]; extern char yosys_path[PATH_MAX];
}; };
#endif #endif
#ifdef YOSYS_ENABLE_TCL
namespace Yosys {
extern int yosys_tcl_iterp_init(Tcl_Interp *interp);
};
#endif
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -221,6 +226,7 @@ int main(int argc, char **argv)
bool call_abort = false; bool call_abort = false;
bool timing_details = false; bool timing_details = false;
bool run_shell = true; bool run_shell = true;
bool run_tcl_shell = false;
bool mode_v = false; bool mode_v = false;
bool mode_q = false; bool mode_q = false;
@ -284,6 +290,9 @@ int main(int argc, char **argv)
printf("\n"); printf("\n");
printf(" -c tcl_scriptfile\n"); printf(" -c tcl_scriptfile\n");
printf(" execute the commands in the tcl script file (see 'help tcl' for details)\n"); printf(" execute the commands in the tcl script file (see 'help tcl' for details)\n");
printf("\n");
printf(" -C\n");
printf(" enters TCL interatcive shell mode\n");
#endif #endif
printf("\n"); printf("\n");
printf(" -p command\n"); printf(" -p command\n");
@ -358,7 +367,7 @@ int main(int argc, char **argv)
} }
int opt; int opt;
while ((opt = getopt(argc, argv, "MXAQTVSgm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:e:r:D:P:E:x:B:")) != -1) while ((opt = getopt(argc, argv, "MXAQTVCSgm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:e:r:D:P:E:x:B:")) != -1)
{ {
switch (opt) switch (opt)
{ {
@ -496,6 +505,9 @@ int main(int argc, char **argv)
case 'B': case 'B':
perffile = optarg; perffile = optarg;
break; break;
case 'C':
run_tcl_shell = true;
break;
default: default:
fprintf(stderr, "Run '%s -h' for help.\n", argv[0]); fprintf(stderr, "Run '%s -h' for help.\n", argv[0]);
exit(1); exit(1);
@ -570,10 +582,18 @@ int main(int argc, char **argv)
for (auto it = passes_commands.begin(); it != passes_commands.end(); it++) for (auto it = passes_commands.begin(); it != passes_commands.end(); it++)
run_pass(*it); run_pass(*it);
if (run_shell) if (run_tcl_shell) {
shell(yosys_design); #ifdef YOSYS_ENABLE_TCL
else Tcl_Main(argc, argv, yosys_tcl_iterp_init);
run_backend(output_filename, backend_command); #else
log_error("Can't exectue TCL shell: this version of yosys is not built with TCL support enabled.\n");
#endif
} else {
if (run_shell)
shell(yosys_design);
else
run_backend(output_filename, backend_command);
}
yosys_design->check(); yosys_design->check();
for (auto it : saved_designs) for (auto it : saved_designs)

View File

@ -740,13 +740,19 @@ static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *a
return TCL_OK; return TCL_OK;
} }
int yosys_tcl_iterp_init(Tcl_Interp *interp)
{
if (Tcl_Init(interp)!=TCL_OK)
log_warning("Tcl_Init() call failed - %s\n",Tcl_ErrnoMsg(Tcl_GetErrno()));
Tcl_CreateCommand(interp, "yosys", tcl_yosys_cmd, NULL, NULL);
return TCL_OK ;
}
extern Tcl_Interp *yosys_get_tcl_interp() extern Tcl_Interp *yosys_get_tcl_interp()
{ {
if (yosys_tcl_interp == NULL) { if (yosys_tcl_interp == NULL) {
yosys_tcl_interp = Tcl_CreateInterp(); yosys_tcl_interp = Tcl_CreateInterp();
if (Tcl_Init(yosys_tcl_interp)!=TCL_OK) yosys_tcl_iterp_init(yosys_tcl_interp);
log_warning("Tcl_Init() call failed - %s\n",Tcl_ErrnoMsg(Tcl_GetErrno()));
Tcl_CreateCommand(yosys_tcl_interp, "yosys", tcl_yosys_cmd, NULL, NULL);
} }
return yosys_tcl_interp; return yosys_tcl_interp;
} }