mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +00:00 
			
		
		
		
	Improved user-friendliness of "sat" and "eval" expression parsing
This commit is contained in:
		
							parent
							
								
									2864cb3b59
								
							
						
					
					
						commit
						223892ac28
					
				
					 4 changed files with 31 additions and 20 deletions
				
			
		|  | @ -1216,6 +1216,20 @@ bool RTLIL::SigSpec::parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::stri | |||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| bool RTLIL::SigSpec::parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str) | ||||
| { | ||||
| 	if (lhs.chunks.size() == 1) { | ||||
| 		char *p = (char*)str.c_str(), *endptr; | ||||
| 		long long int val = strtoll(p, &endptr, 10); | ||||
| 		if (endptr && endptr != p && *endptr == 0) { | ||||
| 			sig = RTLIL::SigSpec(val, lhs.width); | ||||
| 			return true; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return parse(sig, module, str); | ||||
| } | ||||
| 
 | ||||
| RTLIL::CaseRule::~CaseRule() | ||||
| { | ||||
| 	for (auto it = switches.begin(); it != switches.end(); it++) | ||||
|  |  | |||
|  | @ -357,6 +357,7 @@ struct RTLIL::SigSpec { | |||
| 	RTLIL::Const as_const() const; | ||||
| 	bool match(std::string pattern) const; | ||||
| 	static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); | ||||
| 	static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); | ||||
| }; | ||||
| 
 | ||||
| struct RTLIL::CaseRule { | ||||
|  |  | |||
|  | @ -384,13 +384,12 @@ struct EvalPass : public Pass { | |||
| 			log_cmd_error("Can't perform EVAL on an empty selection!\n"); | ||||
| 
 | ||||
| 		ConstEval ce(module); | ||||
| 		RTLIL::SigSpec show_signal, show_value, undef_signal; | ||||
| 
 | ||||
| 		for (auto &it : sets) { | ||||
| 			RTLIL::SigSpec lhs, rhs; | ||||
| 			if (!RTLIL::SigSpec::parse(lhs, module, it.first)) | ||||
| 				log_cmd_error("Failed to parse lhs set expression `%s'.\n", it.first.c_str()); | ||||
| 			if (!RTLIL::SigSpec::parse(rhs, module, it.second)) | ||||
| 			if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, it.second)) | ||||
| 				log_cmd_error("Failed to parse rhs set expression `%s'.\n", it.second.c_str()); | ||||
| 			if (!rhs.is_fully_const()) | ||||
| 				log_cmd_error("Right-hand-side set expression `%s' is not constant.\n", it.second.c_str()); | ||||
|  | @ -400,26 +399,23 @@ struct EvalPass : public Pass { | |||
| 			ce.set(lhs, rhs.as_const()); | ||||
| 		} | ||||
| 
 | ||||
| 		for (auto &it : shows) { | ||||
| 			RTLIL::SigSpec sig; | ||||
| 			if (!RTLIL::SigSpec::parse(sig, module, it)) | ||||
| 				log_cmd_error("Failed to parse lhs set expression `%s'.\n", it.c_str()); | ||||
| 			show_signal.append(sig); | ||||
| 		} | ||||
| 
 | ||||
| 		if (shows.size() == 0) { | ||||
| 			for (auto &it : module->wires) | ||||
| 				if (it.second->port_output) | ||||
| 					show_signal.append(it.second); | ||||
| 					shows.push_back(it.second->name); | ||||
| 		} | ||||
| 
 | ||||
| 		show_signal.optimize(); | ||||
| 		show_value = show_signal; | ||||
| 
 | ||||
| 		if (!ce.eval(show_value, undef_signal)) | ||||
| 			log("Failed to evaluate signal %s: Missing value for %s.\n", log_signal(show_signal), log_signal(undef_signal)); | ||||
| 		for (auto &it : shows) { | ||||
| 			RTLIL::SigSpec signal, value, undef; | ||||
| 			if (!RTLIL::SigSpec::parse(signal, module, it)) | ||||
| 				log_cmd_error("Failed to parse lhs set expression `%s'.\n", it.c_str()); | ||||
| 			signal.optimize(); | ||||
| 			value = signal; | ||||
| 			if (!ce.eval(value, undef)) | ||||
| 				log("Failed to evaluate signal %s: Missing value for %s.\n", log_signal(signal), log_signal(undef)); | ||||
| 			else | ||||
| 			log("Eval result: %s = %s.\n", log_signal(show_signal), log_signal(show_value)); | ||||
| 				log("Eval result: %s = %s.\n", log_signal(signal), log_signal(value)); | ||||
| 		} | ||||
| 	} | ||||
| } EvalPass; | ||||
|   | ||||
|  |  | |||
|  | @ -81,7 +81,7 @@ struct SatHelper | |||
| 
 | ||||
| 			if (!RTLIL::SigSpec::parse(lhs, module, s.first)) | ||||
| 				log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.first.c_str()); | ||||
| 			if (!RTLIL::SigSpec::parse(rhs, module, s.second)) | ||||
| 			if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second)) | ||||
| 				log_cmd_error("Failed to parse rhs set expression `%s'.\n", s.second.c_str()); | ||||
| 			show_signal_pool.add(sigmap(lhs)); | ||||
| 			show_signal_pool.add(sigmap(rhs)); | ||||
|  | @ -102,7 +102,7 @@ struct SatHelper | |||
| 
 | ||||
| 			if (!RTLIL::SigSpec::parse(lhs, module, s.first)) | ||||
| 				log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.first.c_str()); | ||||
| 			if (!RTLIL::SigSpec::parse(rhs, module, s.second)) | ||||
| 			if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second)) | ||||
| 				log_cmd_error("Failed to parse rhs set expression `%s'.\n", s.second.c_str()); | ||||
| 			show_signal_pool.add(sigmap(lhs)); | ||||
| 			show_signal_pool.add(sigmap(rhs)); | ||||
|  | @ -162,7 +162,7 @@ struct SatHelper | |||
| 
 | ||||
| 			if (!RTLIL::SigSpec::parse(lhs, module, s.first)) | ||||
| 				log_cmd_error("Failed to parse lhs proof expression `%s'.\n", s.first.c_str()); | ||||
| 			if (!RTLIL::SigSpec::parse(rhs, module, s.second)) | ||||
| 			if (!RTLIL::SigSpec::parse_rhs(lhs, rhs, module, s.second)) | ||||
| 				log_cmd_error("Failed to parse rhs proof expression `%s'.\n", s.second.c_str()); | ||||
| 			show_signal_pool.add(sigmap(lhs)); | ||||
| 			show_signal_pool.add(sigmap(rhs)); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue