Support randsequence (#6131)

This commit is contained in:
Wilson Snyder
2025-11-30 09:04:42 -05:00
parent 35615c268b
commit b9b6eb61d9
32 changed files with 1271 additions and 280 deletions
+15 -1
View File
@@ -57,6 +57,7 @@ class LinkJumpVisitor final : public VNVisitor {
AstNodeModule* m_modp = nullptr; // Current module
AstNodeFTask* m_ftaskp = nullptr; // Current function/task
AstNode* m_loopp = nullptr; // Current loop
AstRandSequence* m_randsequencep = nullptr; // Current randsequence
bool m_loopInc = false; // In loop increment
bool m_inFork = false; // Under fork
int m_modRepeatNum = 0; // Repeat counter
@@ -289,6 +290,11 @@ class LinkJumpVisitor final : public VNVisitor {
iterateChildren(nodep);
}
}
void visit(AstRandSequence* nodep) override {
VL_RESTORER(m_randsequencep);
m_randsequencep = nodep;
iterateChildren(nodep);
}
void visit(AstRepeat* nodep) override {
// So later optimizations don't need to deal with them,
// REPEAT(count,body) -> loop=count,WHILE(loop>0) { body, loop-- }
@@ -354,6 +360,10 @@ class LinkJumpVisitor final : public VNVisitor {
nodep->v3error("Return isn't legal under fork (IEEE 1800-2023 9.2.3)");
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
return;
} else if (!m_ftaskp && m_randsequencep) {
nodep->replaceWith(new AstRSReturn{nodep->fileline()});
VL_DO_DANGLING(pushDeletep(nodep), nodep);
return;
} else if (!m_ftaskp) {
nodep->v3error("Return isn't underneath a task or function");
} else if (funcp && !nodep->lhsp() && !funcp->isConstructor()) {
@@ -377,7 +387,11 @@ class LinkJumpVisitor final : public VNVisitor {
}
void visit(AstBreak* nodep) override {
iterateChildren(nodep);
if (!m_loopp) {
if (!m_loopp && m_randsequencep) {
nodep->replaceWith(new AstRSBreak{nodep->fileline()});
VL_DO_DANGLING(pushDeletep(nodep), nodep);
return;
} else if (!m_loopp) {
nodep->v3error("break isn't underneath a loop");
} else {
// Jump to the end of the loop