mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-03 21:09:12 +00:00 
			
		
		
		
	tcl: Don't exit repl on recoverable command errors
This commit is contained in:
		
							parent
							
								
									5524d5185d
								
							
						
					
					
						commit
						0f7b8b8d23
					
				
					 2 changed files with 36 additions and 4 deletions
				
			
		| 
						 | 
					@ -205,6 +205,7 @@ extern char yosys_path[PATH_MAX];
 | 
				
			||||||
#ifdef YOSYS_ENABLE_TCL
 | 
					#ifdef YOSYS_ENABLE_TCL
 | 
				
			||||||
namespace Yosys {
 | 
					namespace Yosys {
 | 
				
			||||||
	extern int yosys_tcl_iterp_init(Tcl_Interp *interp);
 | 
						extern int yosys_tcl_iterp_init(Tcl_Interp *interp);
 | 
				
			||||||
 | 
						extern void yosys_tcl_activate_repl();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -584,6 +585,7 @@ int main(int argc, char **argv)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (run_tcl_shell) {
 | 
						if (run_tcl_shell) {
 | 
				
			||||||
#ifdef YOSYS_ENABLE_TCL
 | 
					#ifdef YOSYS_ENABLE_TCL
 | 
				
			||||||
 | 
							yosys_tcl_activate_repl();
 | 
				
			||||||
		Tcl_Main(argc, argv, yosys_tcl_iterp_init);
 | 
							Tcl_Main(argc, argv, yosys_tcl_iterp_init);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
		log_error("Can't exectue TCL shell: this version of yosys is not built with TCL support enabled.\n");
 | 
							log_error("Can't exectue TCL shell: this version of yosys is not built with TCL support enabled.\n");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,6 +84,7 @@ CellTypes yosys_celltypes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef YOSYS_ENABLE_TCL
 | 
					#ifdef YOSYS_ENABLE_TCL
 | 
				
			||||||
Tcl_Interp *yosys_tcl_interp = NULL;
 | 
					Tcl_Interp *yosys_tcl_interp = NULL;
 | 
				
			||||||
 | 
					bool yosys_tcl_repl_active = false;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::set<std::string> yosys_input_files, yosys_output_files;
 | 
					std::set<std::string> yosys_input_files, yosys_output_files;
 | 
				
			||||||
| 
						 | 
					@ -773,12 +774,36 @@ static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	yosys_get_design()->scratchpad_unset("result.json");
 | 
						yosys_get_design()->scratchpad_unset("result.json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (args.size() == 1) {
 | 
						bool in_repl = yosys_tcl_repl_active;
 | 
				
			||||||
		Pass::call(yosys_get_design(), args[0]);
 | 
						bool restore_log_cmd_error_throw = log_cmd_error_throw;
 | 
				
			||||||
	} else {
 | 
					
 | 
				
			||||||
		Pass::call(yosys_get_design(), args);
 | 
						log_cmd_error_throw = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						try {
 | 
				
			||||||
 | 
							if (args.size() == 1) {
 | 
				
			||||||
 | 
								Pass::call(yosys_get_design(), args[0]);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								Pass::call(yosys_get_design(), args);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} catch (log_cmd_error_exception) {
 | 
				
			||||||
 | 
							if (in_repl) {
 | 
				
			||||||
 | 
								auto design = yosys_get_design();
 | 
				
			||||||
 | 
								while (design->selection_stack.size() > 1)
 | 
				
			||||||
 | 
									design->selection_stack.pop_back();
 | 
				
			||||||
 | 
								log_reset_stack();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							Tcl_SetResult(interp, (char *)"Yosys command produced an error", TCL_STATIC);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							yosys_tcl_repl_active = in_repl;
 | 
				
			||||||
 | 
							log_cmd_error_throw = restore_log_cmd_error_throw;
 | 
				
			||||||
 | 
							return TCL_ERROR;
 | 
				
			||||||
 | 
						} catch (...) {
 | 
				
			||||||
 | 
							log_error("uncaught exception during Yosys command invoked from TCL\n");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						yosys_tcl_repl_active = in_repl;
 | 
				
			||||||
 | 
						log_cmd_error_throw = restore_log_cmd_error_throw;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto &scratchpad = yosys_get_design()->scratchpad;
 | 
						auto &scratchpad = yosys_get_design()->scratchpad;
 | 
				
			||||||
	auto result = scratchpad.find("result.json");
 | 
						auto result = scratchpad.find("result.json");
 | 
				
			||||||
	if (result != scratchpad.end()) {
 | 
						if (result != scratchpad.end()) {
 | 
				
			||||||
| 
						 | 
					@ -805,6 +830,11 @@ int yosys_tcl_iterp_init(Tcl_Interp *interp)
 | 
				
			||||||
    return TCL_OK ;
 | 
					    return TCL_OK ;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void yosys_tcl_activate_repl()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						yosys_tcl_repl_active = true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern Tcl_Interp *yosys_get_tcl_interp()
 | 
					extern Tcl_Interp *yosys_get_tcl_interp()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (yosys_tcl_interp == NULL) {
 | 
						if (yosys_tcl_interp == NULL) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue