From 8876de4d93018bd56aa9bad1b2bca088b8cf9326 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Wed, 11 Dec 2024 14:40:27 +0100 Subject: [PATCH] =?UTF-8?q?Allow=20for=20non-const=20RHS=20in=20=3D=3D=3F?= Signed-off-by: Ryszard Rozak --- src/V3Unknown.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/V3Unknown.cpp b/src/V3Unknown.cpp index e649c02cdc..c89ccb227b 100644 --- a/src/V3Unknown.cpp +++ b/src/V3Unknown.cpp @@ -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