Support + in constant expressions.

This commit is contained in:
steve 1999-10-08 17:48:08 +00:00
parent 0f919ab5f3
commit 29abc5a69e
2 changed files with 32 additions and 3 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: elaborate.cc,v 1.112 1999/10/08 17:27:23 steve Exp $" #ident "$Id: elaborate.cc,v 1.113 1999/10/08 17:48:08 steve Exp $"
#endif #endif
/* /*
@ -945,8 +945,25 @@ NetNet* PEIdent::elaborate_net(Design*des, const string&path,
if (msb_ && lsb_) { if (msb_ && lsb_) {
verinum*mval = msb_->eval_const(des, path); verinum*mval = msb_->eval_const(des, path);
assert(mval); if (mval == 0) {
cerr << msb_->get_line() << ": error: unable to "
"evaluate constant expression: " << *msb_ <<
endl;
des->errors += 1;
return 0;
}
verinum*lval = lsb_->eval_const(des, path); verinum*lval = lsb_->eval_const(des, path);
if (lval == 0) {
cerr << lsb_->get_line() << ": error: unable to "
"evaluate constant expression: " << *lsb_ <<
endl;
delete mval;
des->errors += 1;
return 0;
}
assert(mval);
assert(lval); assert(lval);
unsigned midx = sig->sb_to_idx(mval->as_long()); unsigned midx = sig->sb_to_idx(mval->as_long());
unsigned lidx = sig->sb_to_idx(lval->as_long()); unsigned lidx = sig->sb_to_idx(lval->as_long());
@ -2570,6 +2587,9 @@ Design* elaborate(const map<string,Module*>&modules,
/* /*
* $Log: elaborate.cc,v $ * $Log: elaborate.cc,v $
* Revision 1.113 1999/10/08 17:48:08 steve
* Support + in constant expressions.
*
* Revision 1.112 1999/10/08 17:27:23 steve * Revision 1.112 1999/10/08 17:27:23 steve
* Accept adder parameters with different widths, * Accept adder parameters with different widths,
* and simplify continuous assign construction. * and simplify continuous assign construction.

11
eval.cc
View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: eval.cc,v 1.8 1999/09/20 02:21:10 steve Exp $" #ident "$Id: eval.cc,v 1.9 1999/10/08 17:48:09 steve Exp $"
#endif #endif
# include "PExpr.h" # include "PExpr.h"
@ -41,6 +41,12 @@ verinum* PEBinary::eval_const(const Design*des, const string&path) const
verinum*res; verinum*res;
switch (op_) { switch (op_) {
case '+': {
long lv = l->as_long();
long rv = r->as_long();
res = new verinum(lv+rv, l->len());
break;
}
case '-': { case '-': {
long lv = l->as_long(); long lv = l->as_long();
long rv = r->as_long(); long rv = r->as_long();
@ -92,6 +98,9 @@ verinum* PETernary::eval_const(const Design*, const string&) const
/* /*
* $Log: eval.cc,v $ * $Log: eval.cc,v $
* Revision 1.9 1999/10/08 17:48:09 steve
* Support + in constant expressions.
*
* Revision 1.8 1999/09/20 02:21:10 steve * Revision 1.8 1999/09/20 02:21:10 steve
* Elaborate parameters in phases. * Elaborate parameters in phases.
* *