mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Add TCL interactive shell mode
This commit is contained in:
		
							parent
							
								
									c55c514cdb
								
							
						
					
					
						commit
						2450e6be22
					
				
					 2 changed files with 34 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -202,6 +202,11 @@ extern char *yosys_argv0;
 | 
			
		|||
extern char yosys_path[PATH_MAX];
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef YOSYS_ENABLE_TCL
 | 
			
		||||
namespace Yosys {
 | 
			
		||||
	extern int yosys_tcl_iterp_init(Tcl_Interp *interp);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -221,6 +226,7 @@ int main(int argc, char **argv)
 | 
			
		|||
	bool call_abort = false;
 | 
			
		||||
	bool timing_details = false;
 | 
			
		||||
	bool run_shell = true;
 | 
			
		||||
	bool run_tcl_shell = false;
 | 
			
		||||
	bool mode_v = false;
 | 
			
		||||
	bool mode_q = false;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -284,6 +290,9 @@ int main(int argc, char **argv)
 | 
			
		|||
		printf("\n");
 | 
			
		||||
		printf("    -c tcl_scriptfile\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
 | 
			
		||||
		printf("\n");
 | 
			
		||||
		printf("    -p command\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -358,7 +367,7 @@ int main(int argc, char **argv)
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	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)
 | 
			
		||||
		{
 | 
			
		||||
| 
						 | 
				
			
			@ -496,6 +505,9 @@ int main(int argc, char **argv)
 | 
			
		|||
		case 'B':
 | 
			
		||||
			perffile = optarg;
 | 
			
		||||
			break;
 | 
			
		||||
		case 'C':
 | 
			
		||||
			run_tcl_shell = true;
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			fprintf(stderr, "Run '%s -h' for help.\n", argv[0]);
 | 
			
		||||
			exit(1);
 | 
			
		||||
| 
						 | 
				
			
			@ -570,10 +582,18 @@ int main(int argc, char **argv)
 | 
			
		|||
	for (auto it = passes_commands.begin(); it != passes_commands.end(); it++)
 | 
			
		||||
		run_pass(*it);
 | 
			
		||||
 | 
			
		||||
	if (run_tcl_shell) {
 | 
			
		||||
#ifdef YOSYS_ENABLE_TCL
 | 
			
		||||
		Tcl_Main(argc, argv, yosys_tcl_iterp_init);
 | 
			
		||||
#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();
 | 
			
		||||
	for (auto it : saved_designs)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -740,13 +740,19 @@ static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *a
 | 
			
		|||
	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()
 | 
			
		||||
{
 | 
			
		||||
	if (yosys_tcl_interp == NULL) {
 | 
			
		||||
		yosys_tcl_interp = Tcl_CreateInterp();
 | 
			
		||||
		if (Tcl_Init(yosys_tcl_interp)!=TCL_OK)
 | 
			
		||||
			log_warning("Tcl_Init() call failed - %s\n",Tcl_ErrnoMsg(Tcl_GetErrno()));
 | 
			
		||||
		Tcl_CreateCommand(yosys_tcl_interp, "yosys", tcl_yosys_cmd, NULL, NULL);
 | 
			
		||||
		yosys_tcl_iterp_init(yosys_tcl_interp);
 | 
			
		||||
	}
 | 
			
		||||
	return yosys_tcl_interp;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue