From 232f465f36e80480a4bc09678b0c043e7a3c6fe7 Mon Sep 17 00:00:00 2001 From: Tomasz Gorochowik Date: Fri, 27 Dec 2024 14:57:53 +0100 Subject: [PATCH] Add initial ternary operator branch coverage support Signed-off-by: Tomasz Gorochowik --- src/V3Coverage.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/V3Coverage.cpp b/src/V3Coverage.cpp index 7f36c409f34..68ad1390285 100644 --- a/src/V3Coverage.cpp +++ b/src/V3Coverage.cpp @@ -402,6 +402,22 @@ class CoverageVisitor final : public VNVisitor { } // VISITORS - LINE COVERAGE + void visit(AstCond* nodep) override { + UINFO(4, " COND: " << nodep << endl); + + // Current method cannot run coverage for impure statements + if (!nodep->condp()->isPure()) { + return; + } + + auto fake_if = new AstIf(nodep->fileline(), nodep->condp()->cloneTree(true)); + FileLine* newFl = new FileLine{nodep->fileline()}; + auto always = new AstAlways{newFl, VAlwaysKwd::ALWAYS, nullptr, fake_if}; + // Disable coverage for this fake always block + newFl->coverageOn(false); + nodep->addNextStmt(always, nodep); + + } // Note not AstNodeIf; other types don't get covered void visit(AstIf* nodep) override { UINFO(4, " IF: " << nodep << endl);