From d46465845c40e55dd11515630516252be34e3af3 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 29 Sep 2001 01:53:22 +0000 Subject: [PATCH] Fix the size of unsized constant operants to compare (PR#274) --- netlist.cc | 38 +++++++++++++++++++++++++++++++++++++- tgt-vvp/eval_expr.c | 10 +++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/netlist.cc b/netlist.cc index 40de3ef11..0799b06ee 100644 --- a/netlist.cc +++ b/netlist.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: netlist.cc,v 1.170 2001/08/25 23:50:03 steve Exp $" +#ident "$Id: netlist.cc,v 1.171 2001/09/29 01:53:22 steve Exp $" #endif # include "config.h" @@ -1878,9 +1878,42 @@ NetEBBits* NetEBBits::dup_expr() const return result; } +/* + * Create a comparison operator with two sub-expressions. + * + * Handle the special case of an unsized constant on the left or right + * side by resizing the number to match the other + * expression. Otherwise, the netlist will have to allow the + * expressions to have different widths. + */ NetEBComp::NetEBComp(char op, NetExpr*l, NetExpr*r) : NetEBinary(op, l, r) { + if (NetEConst*tmp = dynamic_cast(r)) do { + + if (tmp->has_width()) + break; + + if (tmp->expr_width() == l->expr_width()) + break; + + tmp->set_width(l->expr_width()); + + } while (0); + + if (NetEConst*tmp = dynamic_cast(l)) do { + + if (tmp->has_width()) + break; + + if (tmp->expr_width() == r->expr_width()) + break; + + tmp->set_width(r->expr_width()); + + } while (0); + + expr_width(1); } @@ -2391,6 +2424,9 @@ const NetProc*NetTaskDef::proc() const /* * $Log: netlist.cc,v $ + * Revision 1.171 2001/09/29 01:53:22 steve + * Fix the size of unsized constant operants to compare (PR#274) + * * Revision 1.170 2001/08/25 23:50:03 steve * Change the NetAssign_ class to refer to the signal * instead of link into the netlist. This is faster diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index a7ca19fc8..eb0ee96c4 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: eval_expr.c,v 1.45 2001/09/20 03:46:38 steve Exp $" +#ident "$Id: eval_expr.c,v 1.46 2001/09/29 01:53:22 steve Exp $" #endif # include "vvp_priv.h" @@ -122,6 +122,11 @@ static struct vector_info draw_binary_expr_eq(ivl_expr_t exp) break; case 'e': /* == */ + if (lv.wid != rv.wid) { + fprintf(stderr,"internal error: operands of == " + " have different widths: %u vs %u\n", + lv.wid, rv.wid); + } assert(lv.wid == rv.wid); fprintf(vvp_out, " %%cmp/u %u, %u, %u;\n", lv.base, rv.base, lv.wid); @@ -1223,6 +1228,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp) /* * $Log: eval_expr.c,v $ + * Revision 1.46 2001/09/29 01:53:22 steve + * Fix the size of unsized constant operants to compare (PR#274) + * * Revision 1.45 2001/09/20 03:46:38 steve * Handle short l-values to concatenation. *