Fix loop exits on $finish

This commit is contained in:
Wilson Snyder
2025-10-06 19:19:15 -04:00
parent 5229ce8660
commit 717667034b
3 changed files with 50 additions and 1 deletions
+11 -1
View File
@@ -45,7 +45,8 @@ VL_DEFINE_DEBUG_FUNCTIONS;
class LinkJumpVisitor final : public VNVisitor {
// NODE STATE
// AstNode::user1() -> AstJumpBlock*, for body of this loop
// AstBegin/etc::user1() -> AstJumpBlock*, for body of this loop
// AstFinish::user1() -> bool, processed
// AstNode::user2() -> AstJumpBlock*, for this block
// AstNodeBlock::user3() -> bool, true if contains a fork
const VNUser1InUse m_user1InUse;
@@ -437,6 +438,15 @@ class LinkJumpVisitor final : public VNVisitor {
nodep->unlinkFrBack();
VL_DO_DANGLING(pushDeletep(nodep), nodep);
}
void visit(AstFinish* nodep) override {
if (nodep->user1SetOnce()) return; // Process once
iterateChildren(nodep);
if (m_loopp) {
// Jump to the end of the loop (post-finish)
AstJumpBlock* const blockp = getJumpBlock(m_loopp, false);
nodep->addNextHere(new AstJumpGo{nodep->fileline(), blockp});
}
}
void visit(AstVarRef* nodep) override {
if (m_loopInc && nodep->varp()) nodep->varp()->usedLoopIdx(true);
}