diff --git a/elaborate.cc b/elaborate.cc index 6c09679bf..f13ea42c5 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: elaborate.cc,v 1.127 1999/11/21 17:35:37 steve Exp $" +#ident "$Id: elaborate.cc,v 1.128 1999/11/21 20:03:24 steve Exp $" #endif /* @@ -1067,9 +1067,21 @@ NetProc* PAssign::elaborate(Design*des, const string&path) const /* Elaborate the r-value expression. */ assert(rval()); - NetExpr*rv = rval()->elaborate_expr(des, path); - if (rv == 0) + + NetExpr*rv; + + if (verinum*val = rval()->eval_const(des,path)) { + rv = new NetEConst(*val); + delete val; + + } else if (rv = rval()->elaborate_expr(des, path)) { + + /* OK, go on. */ + + } else { + /* Unable to elaborate expression. Retreat. */ return 0; + } assert(rv); @@ -2133,6 +2145,9 @@ Design* elaborate(const map&modules, /* * $Log: elaborate.cc,v $ + * Revision 1.128 1999/11/21 20:03:24 steve + * Handle multiply in constant expressions. + * * Revision 1.127 1999/11/21 17:35:37 steve * Memory name lookup handles scopes. * diff --git a/eval.cc b/eval.cc index 3fcba5fd2..5ad4f3962 100644 --- a/eval.cc +++ b/eval.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: eval.cc,v 1.9 1999/10/08 17:48:09 steve Exp $" +#ident "$Id: eval.cc,v 1.10 1999/11/21 20:03:24 steve Exp $" #endif # include "PExpr.h" @@ -42,17 +42,45 @@ verinum* PEBinary::eval_const(const Design*des, const string&path) const switch (op_) { case '+': { + assert(l->is_defined()); + assert(r->is_defined()); long lv = l->as_long(); long rv = r->as_long(); res = new verinum(lv+rv, l->len()); break; } case '-': { + assert(l->is_defined()); + assert(r->is_defined()); long lv = l->as_long(); long rv = r->as_long(); res = new verinum(lv-rv, l->len()); break; } + case '*': { + assert(l->is_defined()); + assert(r->is_defined()); + long lv = l->as_long(); + long rv = r->as_long(); + res = new verinum(lv * rv, l->len()); + break; + } + case '/': { + assert(l->is_defined()); + assert(r->is_defined()); + long lv = l->as_long(); + long rv = r->as_long(); + res = new verinum(lv / rv, l->len()); + break; + } + case '%': { + assert(l->is_defined()); + assert(r->is_defined()); + long lv = l->as_long(); + long rv = r->as_long(); + res = new verinum(lv % rv, l->len()); + break; + } default: delete l; delete r; @@ -98,6 +126,9 @@ verinum* PETernary::eval_const(const Design*, const string&) const /* * $Log: eval.cc,v $ + * Revision 1.10 1999/11/21 20:03:24 steve + * Handle multiply in constant expressions. + * * Revision 1.9 1999/10/08 17:48:09 steve * Support + in constant expressions. *