From 2f8a40b15980c2ab71da47c59a4f80d754edf157 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 15 Feb 2004 04:23:48 +0000 Subject: [PATCH] Fix evaluation of compare to constant expression. --- elab_net.cc | 36 +++++++++++++++++++++++++++++++----- expr_synth.cc | 6 +++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/elab_net.cc b/elab_net.cc index 6c1cab176..d278747b7 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: elab_net.cc,v 1.122 2003/10/30 04:31:34 steve Exp $" +#ident "$Id: elab_net.cc,v 1.123 2004/02/15 04:23:48 steve Exp $" #endif # include "config.h" @@ -408,21 +408,44 @@ NetNet* PEBinary::elaborate_net_cmp_(Design*des, NetScope*scope, unsigned long fall, unsigned long decay) const { - NetNet*lsig = left_->elaborate_net(des, scope, 0, 0, 0, 0), - *rsig = right_->elaborate_net(des, scope, 0, 0, 0, 0); - if (lsig == 0) { + /* Elaborate the operands of the compare first as expressions + (so that the eval_tree method can reduce constant + expressions, including parameters) then turn those results + into synthesized nets. */ + NetExpr*lexp = left_->elaborate_expr(des, scope); + if (lexp == 0) { cerr << get_line() << ": error: Cannot elaborate "; left_->dump(cerr); cerr << endl; return 0; } - if (rsig == 0) { + + if (NetExpr*tmp = lexp->eval_tree()) { + delete lexp; + lexp = tmp; + } + + NetNet*lsig = lexp->synthesize(des); + assert(lsig); + delete lexp; + + NetExpr*rexp = right_->elaborate_expr(des, scope); + if (rexp == 0) { cerr << get_line() << ": error: Cannot elaborate "; right_->dump(cerr); cerr << endl; return 0; } + if (NetExpr*tmp = rexp->eval_tree()) { + delete rexp; + rexp = tmp; + } + + NetNet*rsig = rexp->synthesize(des); + assert(rsig); + delete rexp; + unsigned dwidth = lsig->pin_count(); if (rsig->pin_count() > dwidth) dwidth = rsig->pin_count(); @@ -2403,6 +2426,9 @@ NetNet* PEUnary::elaborate_net(Design*des, NetScope*scope, /* * $Log: elab_net.cc,v $ + * Revision 1.123 2004/02/15 04:23:48 steve + * Fix evaluation of compare to constant expression. + * * Revision 1.122 2003/10/30 04:31:34 steve * Catch real variables in net expressions. * diff --git a/expr_synth.cc b/expr_synth.cc index 848542ad0..6d4d82ef3 100644 --- a/expr_synth.cc +++ b/expr_synth.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: expr_synth.cc,v 1.52 2003/11/10 19:39:20 steve Exp $" +#ident "$Id: expr_synth.cc,v 1.53 2004/02/15 04:23:48 steve Exp $" #endif # include "config.h" @@ -584,6 +584,7 @@ NetNet* NetEConst::synthesize(Design*des) NetNet*osig = new NetNet(scope, path, NetNet::IMPLICIT, width); osig->local_flag(true); + osig->set_signed(has_sign()); NetConst*con = new NetConst(scope, scope->local_symbol(), value()); for (unsigned idx = 0 ; idx < width; idx += 1) connect(osig->pin(idx), con->pin(idx)); @@ -827,6 +828,9 @@ NetNet* NetESignal::synthesize(Design*des) /* * $Log: expr_synth.cc,v $ + * Revision 1.53 2004/02/15 04:23:48 steve + * Fix evaluation of compare to constant expression. + * * Revision 1.52 2003/11/10 19:39:20 steve * Remove redundant scope tokens. *