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:
parent
c38e8182c2
commit
e7d463704c
|
|
@ -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;
|
||||
|
|
|
|||
10
elaborate.cc
10
elaborate.cc
|
|
@ -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.
|
||||
|
|
|
|||
19
netmisc.cc
19
netmisc.cc
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue