From 675d9a641ea3446021e223284e1f4db4a5025a79 Mon Sep 17 00:00:00 2001 From: Krzysztof Bieganski Date: Wed, 28 Aug 2024 19:42:49 +0200 Subject: [PATCH] Call `pre`/`post_randomize` on `randomize() with` (#5412) Signed-off-by: Krzysztof Bieganski --- src/V3Randomize.cpp | 4 ++++ test_regress/t/t_randomize_prepost.pl | 12 ++++++++---- test_regress/t/t_randomize_prepost.v | 8 ++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) 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