From bd2f27c5dface45cf9a74cf6f81008da4f82da41 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Wed, 4 Dec 2024 11:43:34 +0100 Subject: [PATCH] Get constraints from class Signed-off-by: Ryszard Rozak --- src/V3Randomize.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 0bbf178fb9..507d93692a 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -2111,6 +2111,17 @@ class RandomizeVisitor final : public VNVisitor { AstVar* const randModeVarp = getRandModeVar(classp); if (randModeVarp) addSetRandMode(randomizeFuncp, localGenp, randModeVarp); + // Get constraints from the class + classp->foreachMember([&](AstClass* const clp, AstConstraint* const constrp) { + AstTask* const setupTaskp = VN_AS(constrp->user2p(), Task); + UASSERT_OBJ(setupTaskp, constrp, "Constraint should have setup task generated before"); + AstTaskRef* const setupRefp = new AstTaskRef{ + fl, setupTaskp->name(), + new AstArg{fl, "constraint", new AstVarRef{fl, localGenp, VAccess::READWRITE}}}; + setupRefp->taskp(setupTaskp); + randomizeFuncp->addStmtsp( + wrapIfConstraintMode(classp, constrp, new AstStmtExpr{fl, setupRefp})); + }); // Generate constraint setup code and a hardcoded call to the solver AstNode* const capturedTreep = withp->exprp()->unlinkFrBackWithNext(); randomizeFuncp->addStmtsp(capturedTreep);