388 std::vector<std::pair<std::string, std::string>> sets;
389 std::vector<std::string> shows, tables;
390 bool set_undef =
false;
392 log_header(
"Executing EVAL pass (evaluate the circuit given an input).\n");
395 for (argidx = 1; argidx <
args.size(); argidx++) {
396 if (
args[argidx] ==
"-set" && argidx+2 <
args.size()) {
397 std::string lhs =
args[++argidx].c_str();
398 std::string rhs =
args[++argidx].c_str();
399 sets.push_back(std::pair<std::string, std::string>(lhs, rhs));
402 if (
args[argidx] ==
"-set-undef") {
406 if (
args[argidx] ==
"-show" && argidx+1 <
args.size()) {
407 shows.push_back(
args[++argidx]);
410 if (
args[argidx] ==
"-table" && argidx+1 <
args.size()) {
411 tables.push_back(
args[++argidx]);
414 if ((
args[argidx] ==
"-brute_force_equiv_checker" ||
args[argidx] ==
"-brute_force_equiv_checker_x") && argidx+3 ==
args.size()) {
418 if (design->
modules_.count(mod1_name) == 0)
419 log_error(
"Can't find module `%s'!\n", mod1_name.c_str());
420 if (design->
modules_.count(mod2_name) == 0)
421 log_error(
"Can't find module `%s'!\n", mod2_name.c_str());
423 if (checker.errors > 0)
425 log(
"Verified %s = %s (using brute-force check on %d cases).\n",
426 mod1_name.c_str(), mod2_name.c_str(), checker.counter);
429 if (
args[argidx] ==
"-vloghammer_report" && argidx+5 ==
args.size()) {
431 std::string module_prefix =
args[++argidx];
432 std::string module_list =
args[++argidx];
433 std::string input_list =
args[++argidx];
434 std::string pattern_list =
args[++argidx];
435 VlogHammerReporter reporter(design, module_prefix, module_list, input_list, pattern_list);
444 for (
auto &mod_it : design->
modules_)
445 if (design->
selected(mod_it.second)) {
447 log_cmd_error(
"Only one module must be selected for the EVAL pass! (selected: %s and %s)\n",
449 module = mod_it.second;
452 log_cmd_error(
"Can't perform EVAL on an empty selection!\n");
456 for (
auto &it : sets) {
459 log_cmd_error(
"Failed to parse lhs set expression `%s'.\n", it.first.c_str());
461 log_cmd_error(
"Failed to parse rhs set expression `%s'.\n", it.second.c_str());
463 log_cmd_error(
"Right-hand-side set expression `%s' is not constant.\n", it.second.c_str());
465 log_cmd_error(
"Set expression with different lhs and rhs sizes: %s (%s, %d bits) vs. %s (%s, %d bits)\n",
470 if (shows.size() == 0) {
471 for (
auto &it : module->
wires_)
472 if (it.second->port_output)
473 shows.push_back(it.second->name.str());
478 for (
auto &it : shows) {
481 log_cmd_error(
"Failed to parse show expression `%s'.\n", it.c_str());
484 while (!ce.eval(value, undef)) {
485 log(
"Failed to evaluate signal %s: Missing value for %s. -> setting to undef\n",
log_signal(signal),
log_signal(undef));
491 if (!ce.eval(value, undef))
501 std::vector<std::vector<std::string>> tab;
502 int tab_sep_colidx = 0;
504 for (
auto &it : shows) {
507 log_cmd_error(
"Failed to parse show expression `%s'.\n", it.c_str());
511 for (
auto &it : tables) {
514 log_cmd_error(
"Failed to parse table expression `%s'.\n", it.c_str());
518 std::vector<std::string> tab_line;
519 for (
auto &c : tabsigs.
chunks())
521 tab_sep_colidx = tab_line.size();
522 for (
auto &c : signal.
chunks())
524 tab.push_back(tab_line);
531 ce.set(tabsigs, tabvals);
535 while (!ce.eval(value, this_undef)) {
537 log(
"Failed to evaluate signal %s at %s = %s: Missing value for %s.\n",
log_signal(signal),
547 for (
auto &c : tabsigs.
chunks()) {
553 for (
auto &c : signal.
chunks()) {
558 tab.push_back(tab_line);
564 while (tabvals.as_bool());
566 std::vector<int> tab_column_width;
567 for (
auto &row : tab) {
568 if (tab_column_width.size() < row.size())
569 tab_column_width.resize(row.size());
570 for (
size_t i = 0; i < row.size(); i++)
571 tab_column_width[i] = std::max(tab_column_width[i],
int(row[i].size()));
576 for (
auto &row : tab) {
577 for (
size_t i = 0; i < row.size(); i++) {
578 int k = int(i) < tab_sep_colidx ? tab_sep_colidx - i - 1 : i;
579 log(
" %s%*s", k == tab_sep_colidx ?
"| " :
"", tab_column_width[k], row[k].c_str());
583 for (
size_t i = 0; i < row.size(); i++) {
584 int k = int(i) < tab_sep_colidx ? tab_sep_colidx - i - 1 : i;
585 log(
" %s", k == tab_sep_colidx ?
"| " :
"");
586 for (
int j = 0; j < tab_column_width[k]; j++)
595 if (undef.
size() > 0) {
597 log(
"Assumend undef (x) value for the following singals: %s\n\n",
log_signal(undef));
bool selected(T1 *module) const
static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str)
void log_header(const char *format,...)
RTLIL::Const as_const() const
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
void log_error(const char *format,...)
static std::string escape_id(std::string str)
bool is_fully_const() const
static const char * id2cstr(const RTLIL::IdString &str)
void log_cmd_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Module * > modules_
void log(const char *format,...)
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
std::vector< RTLIL::State > bits
void append(const RTLIL::SigSpec &signal)
RTLIL::Const const_add(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
const std::vector< RTLIL::SigChunk > & chunks() const