diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 95e2d01c2..0833db2d9 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -1918,6 +1918,8 @@ class RandomizeVisitor final : public VNVisitor { AstFunc* const randomizeFuncp = V3Randomize::newRandomizeFunc( m_memberMap, classp, m_inlineUniqueNames.get(nodep), false); + addPrePostCall(classp, randomizeFuncp, "pre_randomize"); + // Detach the expression and prepare variable copies const CaptureVisitor captured{withp->exprp(), m_modp, classp}; @@ -1975,6 +1977,8 @@ class RandomizeVisitor final : public VNVisitor { new AstVarRef{nodep->fileline(), VN_AS(randomizeFuncp->fvarp(), Var), VAccess::WRITE}, new AstAnd{nodep->fileline(), basicRandomizeFuncCallp, solverCallp}}); + addPrePostCall(classp, randomizeFuncp, "post_randomize"); + // Replace the node with a call to that function nodep->name(randomizeFuncp->name()); nodep->addPinsp(captured.getArgs()); diff --git a/test_regress/t/t_randomize_prepost.pl b/test_regress/t/t_randomize_prepost.pl index 49330a5fe..9562a55db 100755 --- a/test_regress/t/t_randomize_prepost.pl +++ b/test_regress/t/t_randomize_prepost.pl @@ -10,11 +10,15 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di scenarios(simulator => 1); -compile( - ); +if (!$Self->have_solver) { + skip("No constraint solver installed"); +} else { + compile( + ); -execute( - ); + execute( + ); +} ok(1); 1; diff --git a/test_regress/t/t_randomize_prepost.v b/test_regress/t/t_randomize_prepost.v index 734bb3c31..07b749c43 100644 --- a/test_regress/t/t_randomize_prepost.v +++ b/test_regress/t/t_randomize_prepost.v @@ -41,6 +41,14 @@ module t (/*AUTOARG*/); if (c.pre != 10) $stop; if (c.r != RANDOMIZED) $stop; if (c.post != 30) $stop; + + c = new; + rand_result = c.randomize() with { r == RANDOMIZED; }; + if (rand_result != 1) $stop; + if (c.pre != 10) $stop; + if (c.r != RANDOMIZED) $stop; + if (c.post != 30) $stop; + $write("*-* All Finished *-*\n"); $finish; end