From 6b0c62c9c48d7f588a5422733a2de4297bfddafd Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Tue, 17 Jul 2007 18:05:48 -0700 Subject: [PATCH] Minor improvements to $bits implementation Signed-off-by: Stephen Williams --- elab_expr.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index fa4577256..58251ec95 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -368,11 +368,20 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope) const << " Use $bits() instead." << endl; PExpr*expr = parms_[0]; - NetExpr*sub = expr->elaborate_expr(des, scope, -1, true); - verinum val (sub->expr_width(), 8*sizeof(unsigned)); - delete sub; + ivl_assert(*this, expr); - sub = new NetEConst(val); + /* Elaborate the sub-expression to get its + self-determined width, and save that width. Then + delete the expression because we don't really want + the expression itself. */ + long sub_expr_width = 0; + if (NetExpr*tmp = expr->elaborate_expr(des, scope, -1, true)) { + sub_expr_width = tmp->expr_width(); + delete tmp; + } + + verinum val (sub_expr_width, 8*sizeof(unsigned)); + NetEConst*sub = new NetEConst(val); sub->set_line(*this); return sub;