Skip to content

Commit

Permalink
Allow for non-const RHS in ==?
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Dec 11, 2024
1 parent 9656311 commit 8876de4
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/V3Unknown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,20 @@ class UnknownVisitor final : public VNVisitor {
AstNodeExpr* const lhsp = nodep->lhsp()->unlinkFrBack();
AstNodeExpr* const rhsp = nodep->rhsp()->unlinkFrBack();
AstNodeExpr* newp;
if (!VN_IS(rhsp, Const)) {
nodep->v3warn(E_UNSUPPORTED, "Unsupported: RHS of ==? or !=? must be "
"constant to be synthesizable"); // Says spec.
// Replace with anything that won't cause more errors
newp = new AstEq{nodep->fileline(), lhsp, rhsp};
// X or Z's become mask, ala case statements.
V3Number nummask{rhsp, rhsp->width()};
nummask.opBitsNonX(VN_AS(rhsp, Const)->num());
V3Number numval{rhsp, rhsp->width()};
numval.opBitsOne(VN_AS(rhsp, Const)->num());
AstNodeExpr* const and1p
= new AstAnd{nodep->fileline(), lhsp, new AstConst{nodep->fileline(), nummask}};
AstNodeExpr* const and2p = new AstConst{nodep->fileline(), numval};
if (VN_IS(nodep, EqWild)) {
newp = new AstEq{nodep->fileline(), and1p, and2p};
} else {
// X or Z's become mask, ala case statements.
V3Number nummask{rhsp, rhsp->width()};
nummask.opBitsNonX(VN_AS(rhsp, Const)->num());
V3Number numval{rhsp, rhsp->width()};
numval.opBitsOne(VN_AS(rhsp, Const)->num());
AstNodeExpr* const and1p = new AstAnd{nodep->fileline(), lhsp,
new AstConst{nodep->fileline(), nummask}};
AstNodeExpr* const and2p = new AstConst{nodep->fileline(), numval};
if (VN_IS(nodep, EqWild)) {
newp = new AstEq{nodep->fileline(), and1p, and2p};
} else {
newp = new AstNeq{nodep->fileline(), and1p, and2p};
}
VL_DO_DANGLING(rhsp->deleteTree(), rhsp);
newp = new AstNeq{nodep->fileline(), and1p, and2p};
}
VL_DO_DANGLING(rhsp->deleteTree(), rhsp);
nodep->replaceWith(newp);
VL_DO_DANGLING(nodep->deleteTree(), nodep);
// Iterate tree now that we may have gotten rid of the compare
Expand Down

0 comments on commit 8876de4

Please sign in to comment.