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.
This commit is contained in:
Cary R 2010-09-28 22:24:09 -07:00 committed by Stephen Williams
parent 6388430661
commit ea01130ed8
1 changed files with 13 additions and 0 deletions

View File

@ -1248,6 +1248,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<NetEConst*>(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<NetEConst*>(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);