From: Clifford Wolf Date: Sat, 9 Nov 2013 11:02:27 +0000 (+0100) Subject: Improved user-friendliness of "sat" and "eval" expression parsing X-Git-Tag: yosys-0.2.0~375 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=223892ac286b1dd0d09bf2449cd8953b1029ae68;p=yosys.git Improved user-friendliness of "sat" and "eval" expression parsing --- diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index d03fb0448..a65f0bb24 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -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++) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 7628bf0a8..952cb5944 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -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 { diff --git a/passes/sat/eval.cc b/passes/sat/eval.cc index 54cb60d21..473cb41c5 100644 --- a/passes/sat/eval.cc +++ b/passes/sat/eval.cc @@ -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)); - else - log("Eval result: %s = %s.\n", log_signal(show_signal), log_signal(show_value)); + 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(signal), log_signal(value)); + } } } EvalPass; diff --git a/passes/sat/sat.cc b/passes/sat/sat.cc index 31808503e..c1e41eff3 100644 --- a/passes/sat/sat.cc +++ b/passes/sat/sat.cc @@ -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));