The inputs to logical and/or are condition expressions.

Logical and/or take as inputs condition expressions, which are scalar
expressions. Be sure to reduce vectors using proper logic to get the
right condition value.
This commit is contained in:
Stephen Williams 2008-04-22 21:03:18 -07:00
parent c38e8182c2
commit e7d463704c
4 changed files with 30 additions and 8 deletions

View File

@ -167,6 +167,8 @@ NetExpr* PEBinary::elaborate_expr_base_(Design*des,
case 'a':
case 'o':
lp = condition_reduce(lp);
rp = condition_reduce(rp);
tmp = new NetEBLogic(op_, lp, rp);
tmp->set_line(*this);
break;

View File

@ -2045,14 +2045,8 @@ NetProc* PCondit::elaborate(Design*des, NetScope*scope) const
return 0;
}
if (expr->expr_width() > 1) {
assert(expr->expr_width() > 1);
verinum zero (verinum::V0, expr->expr_width());
NetEConst*ezero = new NetEConst(zero);
ezero->set_width(expr->expr_width());
NetEBComp*cmp = new NetEBComp('n', expr, ezero);
expr = cmp;
}
// Make sure the condition expression evaluates to a condition.
expr = condition_reduce(expr);
// Well, I actually need to generate code to handle the
// conditional, so elaborate.

View File

@ -123,6 +123,25 @@ NetExpr* make_sub_expr(long val, NetExpr*expr)
return res;
}
NetExpr* condition_reduce(NetExpr*expr)
{
if (expr->expr_width() == 1)
return expr;
verinum zero (verinum::V0, expr->expr_width());
NetEConst*ezero = new NetEConst(zero);
ezero->cast_signed(expr->has_sign());
ezero->set_line(*expr);
ezero->set_width(expr->expr_width());
NetEBComp*cmp = new NetEBComp('n', expr, ezero);
cmp->cast_signed(false);
cmp->set_line(*expr);
return cmp;
}
NetExpr* elab_and_eval(Design*des, NetScope*scope,
const PExpr*pe, int expr_wid, int prune_width)
{

View File

@ -64,6 +64,13 @@ extern NetNet*pad_to_width(Design*des, NetNet*n, unsigned w);
extern NetNet*pad_to_width_signed(Design*des, NetNet*n, unsigned w);
/*
* Take the input expression and return a variation that assures that
* the expression is 1-bit wide and logical. This reflects the needs
* of conditions i.e. for "if" statements or logical operators.
*/
extern NetExpr*condition_reduce(NetExpr*expr);
/*
* This function transforms an expression by cropping the high bits
* off with a part select. The result has the width w passed in. This