Evaluate constant real EQ and NE constructs.

This patch adds code to evaluate constant == and != with real values.
This commit is contained in:
Cary R 2008-08-29 10:52:09 -07:00 committed by Stephen Williams
parent 2e97b28185
commit 0804eccfec
2 changed files with 65 additions and 15 deletions

View File

@ -340,19 +340,15 @@ NetEConst* NetEBComp::eval_leeq_real_(NetExpr*le, NetExpr*ri, bool eq_flag)
switch (le->expr_type()) { switch (le->expr_type()) {
case IVL_VT_REAL: case IVL_VT_REAL:
rtmp = dynamic_cast<NetECReal*> (le); rtmp = dynamic_cast<NetECReal*> (le);
if (rtmp == 0) if (rtmp == 0) return 0;
return 0;
lv = rtmp->value().as_double(); lv = rtmp->value().as_double();
break; break;
case IVL_VT_LOGIC: case IVL_VT_LOGIC:
case IVL_VT_BOOL: case IVL_VT_BOOL:
vtmp = dynamic_cast<NetEConst*> (le); vtmp = dynamic_cast<NetEConst*> (le);
if (vtmp == 0) if (vtmp == 0) return 0;
return 0; lv = vtmp->value().as_double();
lv = vtmp->value().as_long();
break; break;
default: default:
@ -361,23 +357,18 @@ NetEConst* NetEBComp::eval_leeq_real_(NetExpr*le, NetExpr*ri, bool eq_flag)
assert(0); assert(0);
} }
switch (ri->expr_type()) { switch (ri->expr_type()) {
case IVL_VT_REAL: case IVL_VT_REAL:
rtmp = dynamic_cast<NetECReal*> (ri); rtmp = dynamic_cast<NetECReal*> (ri);
if (rtmp == 0) if (rtmp == 0) return 0;
return 0;
rv = rtmp->value().as_double(); rv = rtmp->value().as_double();
break; break;
case IVL_VT_LOGIC: case IVL_VT_LOGIC:
case IVL_VT_BOOL: case IVL_VT_BOOL:
vtmp = dynamic_cast<NetEConst*> (ri); vtmp = dynamic_cast<NetEConst*> (ri);
if (vtmp == 0) if (vtmp == 0) return 0;
return 0; rv = vtmp->value().as_double();
rv = vtmp->value().as_long();
break; break;
default: default:
@ -563,8 +554,66 @@ NetEConst* NetEBComp::eval_gteq_()
} }
} }
NetEConst* NetEBComp::eval_eqeq_real_(NetExpr*le, NetExpr*ri, bool ne_flag)
{
NetEConst*vtmp;
NetECReal*rtmp;
double lv, rv;
switch (le->expr_type()) {
case IVL_VT_REAL:
rtmp = dynamic_cast<NetECReal*> (le);
if (rtmp == 0) return 0;
lv = rtmp->value().as_double();
break;
case IVL_VT_LOGIC:
case IVL_VT_BOOL:
vtmp = dynamic_cast<NetEConst*> (le);
if (vtmp == 0) return 0;
lv = vtmp->value().as_double();
break;
default:
cerr << get_fileline() << ": internal error: "
<< "Unexpected expression type? " << le->expr_type() << endl;
assert(0);
}
switch (ri->expr_type()) {
case IVL_VT_REAL:
rtmp = dynamic_cast<NetECReal*> (ri);
if (rtmp == 0) return 0;
rv = rtmp->value().as_double();
break;
case IVL_VT_LOGIC:
case IVL_VT_BOOL:
vtmp = dynamic_cast<NetEConst*> (ri);
if (vtmp == 0) return 0;
rv = vtmp->value().as_double();
break;
default:
cerr << get_fileline() << ": internal error: "
<< "Unexpected expression type? " << ri->expr_type() << endl;
assert(0);
}
verinum result((lv == rv ^ ne_flag) ? verinum::V1 : verinum::V0, 1);
vtmp = new NetEConst(result);
vtmp->set_line(*this);
return vtmp;
}
NetEConst* NetEBComp::eval_eqeq_(bool ne_flag) NetEConst* NetEBComp::eval_eqeq_(bool ne_flag)
{ {
if (right_->expr_type() == IVL_VT_REAL)
return eval_eqeq_real_(right_, left_, ne_flag);
if (left_->expr_type() == IVL_VT_REAL)
return eval_eqeq_real_(right_, left_, ne_flag);
NetEConst*l = dynamic_cast<NetEConst*>(left_); NetEConst*l = dynamic_cast<NetEConst*>(left_);
if (l == 0) return 0; if (l == 0) return 0;
NetEConst*r = dynamic_cast<NetEConst*>(right_); NetEConst*r = dynamic_cast<NetEConst*>(right_);

View File

@ -3206,6 +3206,7 @@ class NetEBComp : public NetEBinary {
NetEConst* must_be_leeq_(NetExpr*le, const verinum&rv, bool eq_flag); NetEConst* must_be_leeq_(NetExpr*le, const verinum&rv, bool eq_flag);
NetEConst*eval_eqeq_(bool ne_flag); NetEConst*eval_eqeq_(bool ne_flag);
NetEConst*eval_eqeq_real_(NetExpr*le, NetExpr*ri, bool ne_flag);
NetEConst*eval_less_(); NetEConst*eval_less_();
NetEConst*eval_leeq_(); NetEConst*eval_leeq_();
NetEConst*eval_leeq_real_(NetExpr*le, NetExpr*ri, bool eq_flag); NetEConst*eval_leeq_real_(NetExpr*le, NetExpr*ri, bool eq_flag);