Skip to content

Commit

Permalink
Simplify if handling in branch coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
  • Loading branch information
RRozak committed Feb 7, 2025
1 parent 5b65c15 commit d3e2d8f
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions src/V3Coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,32 +437,9 @@ class CoverageVisitor final : public VNVisitor {
//
// If both if and else are "on", and we're not in an if/else, then
// we do branch coverage
if (!(first_elsif || cont_elsif || final_elsif) && ifState.lineCoverageOn(nodep)
&& elseState.lineCoverageOn(nodep)) {
if (!(first_elsif || cont_elsif)) {
// Normal if. Linecov shows what's inside the if (not condition that is
// always executed)
UINFO(4, " COVER-branch: " << nodep << endl);
nodep->addThensp(newCoverInc(nodep->fileline(), "", "v_branch", "if",
linesCov(ifState, nodep), 0,
traceNameForLine(nodep, "if")));
// The else has a column offset of 1 to uniquify it relative to the if
// As "if" and "else" are more than one character wide, this won't overlap
// another token
nodep->addElsesp(newCoverInc(nodep->fileline(), "", "v_branch", "else",
linesCov(elseState, nodep), 1,
traceNameForLine(nodep, "else")));
}
// If/else attributes to each block as non-branch coverage
else if (first_elsif || cont_elsif) {
UINFO(4, " COVER-elsif: " << nodep << endl);
if (ifState.lineCoverageOn(nodep)) {
nodep->addThensp(newCoverInc(nodep->fileline(), "", "v_line", "elsif",
linesCov(ifState, nodep), 0,
traceNameForLine(nodep, "elsif")));
}
// and we don't insert the else as the child if-else will do so
} else {
// Cover as separate blocks (not a branch as is not two-legged)
if (ifState.lineCoverageOn(nodep)) {
UINFO(4, " COVER-half-if: " << nodep << endl);
nodep->addThensp(newCoverInc(nodep->fileline(), "", "v_line", "if",
Expand All @@ -475,6 +452,14 @@ class CoverageVisitor final : public VNVisitor {
linesCov(elseState, nodep), 1,
traceNameForLine(nodep, "else")));
}
} else {
UINFO(4, " COVER-elsif: " << nodep << endl);
if (ifState.lineCoverageOn(nodep)) {
nodep->addThensp(newCoverInc(nodep->fileline(), "", "v_line", "elsif",
linesCov(ifState, nodep), 0,
traceNameForLine(nodep, "elsif")));
}
// and we don't insert the else as the child if-else will do so
}
m_state = lastState;
}
Expand Down

0 comments on commit d3e2d8f

Please sign in to comment.