From acb55916dad1cfe7ede5fc18852bf3572a3944d2 Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 13 Sep 2010 15:45:19 -0700 Subject: [PATCH] Resize constants in eval_expr when needed. If we are given an unsized constant that is smaller then the requested width then resize the constant to fit. --- netmisc.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/netmisc.cc b/netmisc.cc index f2644cc56..8bde89a53 100644 --- a/netmisc.cc +++ b/netmisc.cc @@ -289,8 +289,15 @@ NetExpr* elab_and_eval(Design*des, NetScope*scope, void eval_expr(NetExpr*&expr, int prune_width) { assert(expr); - if (dynamic_cast(expr)) return; if (dynamic_cast(expr)) return; + /* Resize a constant if allowed and needed. */ + if (NetEConst *tmp = dynamic_cast(expr)) { + if (prune_width <= 0) return; + if (tmp->has_width()) return; + if ((unsigned)prune_width <= tmp->expr_width()) return; + expr = pad_to_width(expr, (unsigned)prune_width, *expr); + return; + } NetExpr*tmp = expr->eval_tree(prune_width); if (tmp != 0) {