diff --git a/eval_attrib.cc b/eval_attrib.cc index 2c0d7b3c7..527df43ad 100644 --- a/eval_attrib.cc +++ b/eval_attrib.cc @@ -21,6 +21,7 @@ # include "util.h" # include "PExpr.h" # include "netlist.h" +# include "netmisc.h" # include # include @@ -52,23 +53,25 @@ attrib_list_t* evaluate_attributes(const map&att, /* If the attribute value is given in the source, then evaluate it as a constant. If the value is not given, then assume the value is 1. */ - verinum*tmp = 0; if (exp) { - tmp = exp->eval_const(des, scope); - if (tmp == 0) { + NetExpr *tmp = elab_and_eval(des, scope, exp, -1, true); + if (!tmp) + continue; + + if (NetEConst *ce = dynamic_cast(tmp)) { + table[idx].val = ce->value(); + } else if (NetECReal *cer = dynamic_cast(tmp)) { + table[idx].val = verinum(cer->value().as_long()); + } else { cerr << exp->get_fileline() << ": error: ``" << *exp << "'' is not a constant expression." << endl; des->errors += 1; - } - } - if (tmp == 0) - tmp = new verinum(1); - - assert(tmp); - - table[idx].val = *tmp; - delete tmp; + } + delete tmp; + } else { + table[idx].val = verinum(1); + } } assert(idx == natt);