From 87cd9a89e0a9466b7d55fc73aaf3302de3d0ca4d Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 28 Sep 2010 22:27:17 -0700 Subject: [PATCH] V0.9: Resize an unsized signed constant if it is less than integer_width. An unsized signed constant that is smaller than integer_width needs to be resized up to either the integer_width or the expression width whichever is smaller. --- elab_expr.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/elab_expr.cc b/elab_expr.cc index bdd1a6468..15715372a 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1238,6 +1238,19 @@ NetExpr*PECallFunction::cast_to_width_(NetExpr*expr, int wid, bool signed_flag) /* If the expression is a const, then replace it with a new const. This is a more efficient result. */ if (NetEConst*tmp = dynamic_cast(expr)) { + /* If this is an unsized signed constant then we may need + * to extend it up to integer_width. */ + if (! tmp->has_width() && tmp->has_sign() && (wid > 0)) { + unsigned pwidth = tmp->expr_width(); + if ((unsigned)wid > integer_width) { + if (integer_width > pwidth) pwidth = integer_width; + } else { + if ((unsigned)wid > pwidth) pwidth = wid; + } + tmp = dynamic_cast(pad_to_width(tmp, pwidth, + *expr)); + assert(tmp); + } tmp->cast_signed(signed_flag); if (wid > (int)(tmp->expr_width())) { verinum oval = pad_to_width(tmp->value(), wid);