Fix implicit casts in assignments (part 6).

IVL_VT_NO_TYPE is now used to signal an untyped LHS in a parameter
declaration. The parser function that handles specparam declarations
needs to do this too. Also, although it should never happen, make
sure we don't set the expression width in a NetECast object to a
negative number. Make constant evaluation of NetECast objects
observe the expression width.
This commit is contained in:
Martin Whitaker 2013-03-06 18:24:11 +00:00 committed by Stephen Williams
parent 6da610fe1e
commit e437321ea7
3 changed files with 10 additions and 5 deletions

View File

@ -1597,7 +1597,7 @@ NetExpr* NetECast::eval_arguments_(const NetExpr*ex) const
switch (op_) {
case 'r':
if (const NetEConst*val = dynamic_cast<const NetEConst*>(ex)) {
verireal res_val = verireal(val->value().as_double());
verireal res_val(val->value().as_double());
res = new NetECReal(res_val);
}
break;
@ -1605,11 +1605,15 @@ NetExpr* NetECast::eval_arguments_(const NetExpr*ex) const
if (const NetEConst*val = dynamic_cast<const NetEConst*>(ex)) {
verinum res_val(val->value());
res_val.cast_to_int2();
if (expr_width() > 0)
res_val = cast_to_width(res_val, expr_width());
res = new NetEConst(res_val);
}
case 'v':
if (const NetECReal*val = dynamic_cast<const NetECReal*>(ex)) {
verinum res_val = verinum(val->value().as_double(), false);
verinum res_val(val->value().as_double(), false);
if (expr_width() > 0)
res_val = cast_to_width(res_val, expr_width());
res = new NetEConst(res_val);
}
break;

View File

@ -803,10 +803,10 @@ NetExpr* elab_and_eval(Design*des, NetScope*scope, PExpr*pe,
tmp = cast_to_real(tmp);
break;
case IVL_VT_BOOL:
tmp = cast_to_int2(tmp, context_width);
tmp = cast_to_int2(tmp, context_width > 0 ? context_width : 0);
break;
case IVL_VT_LOGIC:
tmp = cast_to_int4(tmp, context_width);
tmp = cast_to_int4(tmp, context_width > 0 ? context_width : 0);
break;
default:
break;

View File

@ -2646,15 +2646,16 @@ void pform_set_specparam(const struct vlltype&loc, perm_string name,
parm.expr = expr;
parm.type = IVL_VT_LOGIC;
if (range) {
assert(range->size() == 1);
pform_range_t&rng = range->front();
assert(rng.first);
assert(rng.second);
parm.type = IVL_VT_LOGIC;
parm.msb = rng.first;
parm.lsb = rng.second;
} else {
parm.type = IVL_VT_NO_TYPE;
parm.msb = 0;
parm.lsb = 0;
}