Fix unary convert of real to bool
Sometimes real values are converted to BOOL values, and the NetECast needs to handle it properly.
This commit is contained in:
parent
e2932cb6b5
commit
4989555646
10
netmisc.cc
10
netmisc.cc
|
|
@ -184,7 +184,15 @@ NetNet* cast_to_real(Design*des, NetScope*scope, NetNet*src)
|
||||||
|
|
||||||
NetExpr* cast_to_int2(NetExpr*expr)
|
NetExpr* cast_to_int2(NetExpr*expr)
|
||||||
{
|
{
|
||||||
NetECast*cast = new NetECast('2', expr, expr->expr_width(),
|
// Special case: The expression is alreadt BOOL
|
||||||
|
if (expr->expr_type() == IVL_VT_BOOL)
|
||||||
|
return expr;
|
||||||
|
|
||||||
|
unsigned use_width = expr->expr_width();
|
||||||
|
if (expr->expr_type() == IVL_VT_REAL)
|
||||||
|
use_width = 64;
|
||||||
|
|
||||||
|
NetECast*cast = new NetECast('2', expr, use_width,
|
||||||
expr->has_sign());
|
expr->has_sign());
|
||||||
cast->set_line(*expr);
|
cast->set_line(*expr);
|
||||||
return cast;
|
return cast;
|
||||||
|
|
|
||||||
|
|
@ -3118,19 +3118,37 @@ static struct vector_info draw_unary_expr(ivl_expr_t expr, unsigned wid)
|
||||||
local_count += 1;
|
local_count += 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '2': /* Cast logic to bool */
|
case '2': /* Cast expression to bool */
|
||||||
assert(ivl_expr_value(sub) == IVL_VT_LOGIC);
|
switch (ivl_expr_value(sub)) {
|
||||||
res = draw_eval_expr_wid(sub, wid, 0);
|
case IVL_VT_BOOL:
|
||||||
|
res = draw_eval_expr_wid(sub, wid, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
/* Handle special case that value is 0 or 1. */
|
case IVL_VT_LOGIC:
|
||||||
if (res.base == 0 || res.base == 1)
|
res = draw_eval_expr_wid(sub, wid, 0);
|
||||||
|
|
||||||
|
/* Handle special case that value is 0 or 1. */
|
||||||
|
if (res.base == 0 || res.base == 1)
|
||||||
|
break;
|
||||||
|
if (res.base == 2 || res.base == 2) {
|
||||||
|
res.base = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(vvp_out, " %%cast2 %d, %d, %u;\n", res.base, res.base, res.wid);
|
||||||
break;
|
break;
|
||||||
if (res.base == 2 || res.base == 2) {
|
|
||||||
res.base = 0;
|
case IVL_VT_REAL:
|
||||||
|
word = draw_eval_real(sub);
|
||||||
|
res.base = allocate_vector(wid);
|
||||||
|
res.wid = wid;
|
||||||
|
fprintf(vvp_out, " %%cvt/vr %d, %d, %u;\n", res.base, word, wid);
|
||||||
|
clr_word(word);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(vvp_out, " %%cast2 %d, %d, %u;\n", res.base, res.base, res.wid);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i': /* Cast a real value to an integer. */
|
case 'i': /* Cast a real value to an integer. */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue