Improved user-friendliness of "sat" and "eval" expression parsing

This commit is contained in:
Clifford Wolf 2013-11-09 12:02:27 +01:00
parent 2864cb3b59
commit 223892ac28
4 changed files with 31 additions and 20 deletions

View File

@ -1216,6 +1216,20 @@ bool RTLIL::SigSpec::parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::stri
return true; 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() RTLIL::CaseRule::~CaseRule()
{ {
for (auto it = switches.begin(); it != switches.end(); it++) for (auto it = switches.begin(); it != switches.end(); it++)

View File

@ -357,6 +357,7 @@ struct RTLIL::SigSpec {
RTLIL::Const as_const() const; RTLIL::Const as_const() const;
bool match(std::string pattern) const; bool match(std::string pattern) const;
static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); 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 { struct RTLIL::CaseRule {

View File

@ -384,13 +384,12 @@ struct EvalPass : public Pass {
log_cmd_error("Can't perform EVAL on an empty selection!\n"); log_cmd_error("Can't perform EVAL on an empty selection!\n");
ConstEval ce(module); ConstEval ce(module);
RTLIL::SigSpec show_signal, show_value, undef_signal;
for (auto &it : sets) { for (auto &it : sets) {
RTLIL::SigSpec lhs, rhs; RTLIL::SigSpec lhs, rhs;
if (!RTLIL::SigSpec::parse(lhs, module, it.first)) if (!RTLIL::SigSpec::parse(lhs, module, it.first))
log_cmd_error("Failed to parse lhs set expression `%s'.\n", it.first.c_str()); 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()); log_cmd_error("Failed to parse rhs set expression `%s'.\n", it.second.c_str());
if (!rhs.is_fully_const()) if (!rhs.is_fully_const())
log_cmd_error("Right-hand-side set expression `%s' is not constant.\n", it.second.c_str()); 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()); 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) { if (shows.size() == 0) {
for (auto &it : module->wires) for (auto &it : module->wires)
if (it.second->port_output) if (it.second->port_output)
show_signal.append(it.second); shows.push_back(it.second->name);
} }
show_signal.optimize(); for (auto &it : shows) {
show_value = show_signal; RTLIL::SigSpec signal, value, undef;
if (!RTLIL::SigSpec::parse(signal, module, it))
if (!ce.eval(show_value, undef_signal)) log_cmd_error("Failed to parse lhs set expression `%s'.\n", it.c_str());
log("Failed to evaluate signal %s: Missing value for %s.\n", log_signal(show_signal), log_signal(undef_signal)); 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 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; } EvalPass;

View File

@ -81,7 +81,7 @@ struct SatHelper
if (!RTLIL::SigSpec::parse(lhs, module, s.first)) if (!RTLIL::SigSpec::parse(lhs, module, s.first))
log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.first.c_str()); 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()); 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(lhs));
show_signal_pool.add(sigmap(rhs)); show_signal_pool.add(sigmap(rhs));
@ -102,7 +102,7 @@ struct SatHelper
if (!RTLIL::SigSpec::parse(lhs, module, s.first)) if (!RTLIL::SigSpec::parse(lhs, module, s.first))
log_cmd_error("Failed to parse lhs set expression `%s'.\n", s.first.c_str()); 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()); 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(lhs));
show_signal_pool.add(sigmap(rhs)); show_signal_pool.add(sigmap(rhs));
@ -162,7 +162,7 @@ struct SatHelper
if (!RTLIL::SigSpec::parse(lhs, module, s.first)) if (!RTLIL::SigSpec::parse(lhs, module, s.first))
log_cmd_error("Failed to parse lhs proof expression `%s'.\n", s.first.c_str()); 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()); 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(lhs));
show_signal_pool.add(sigmap(rhs)); show_signal_pool.add(sigmap(rhs));