Use iterate*Const V3EmitV visitors. No functional change.

This commit is contained in:
Geza Lore 2022-04-23 14:03:37 +01:00
parent 0b74e9b354
commit f1ea30f257
2 changed files with 99 additions and 99 deletions

View File

@ -52,10 +52,10 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} }
// VISITORS // VISITORS
virtual void visit(AstNetlist* nodep) override { iterateAndNextNull(nodep->modulesp()); } virtual void visit(AstNetlist* nodep) override { iterateAndNextConstNull(nodep->modulesp()); }
virtual void visit(AstNodeModule* nodep) override { virtual void visit(AstNodeModule* nodep) override {
putfs(nodep, nodep->verilogKwd() + " " + prefixNameProtect(nodep) + ";\n"); putfs(nodep, nodep->verilogKwd() + " " + prefixNameProtect(nodep) + ";\n");
iterateChildren(nodep); iterateChildrenConst(nodep);
putqs(nodep, "end" + nodep->verilogKwd() + "\n"); putqs(nodep, "end" + nodep->verilogKwd() + "\n");
} }
virtual void visit(AstPort* nodep) override {} virtual void visit(AstPort* nodep) override {}
@ -65,7 +65,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
puts(nodep->prettyName()); puts(nodep->prettyName());
puts(";\n"); puts(";\n");
// Only putfs the first time for each visitor; later for same node is putqs // Only putfs the first time for each visitor; later for same node is putqs
iterateAndNextNull(nodep->stmtsp()); iterateAndNextConstNull(nodep->stmtsp());
putfs(nodep, nodep->isFunction() ? "endfunction\n" : "endtask\n"); putfs(nodep, nodep->isFunction() ? "endfunction\n" : "endtask\n");
} }
@ -75,7 +75,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} else { } else {
putbs("begin : " + nodep->name() + "\n"); putbs("begin : " + nodep->name() + "\n");
} }
iterateChildren(nodep); iterateChildrenConst(nodep);
puts("end\n"); puts("end\n");
} }
virtual void visit(AstFork* nodep) override { virtual void visit(AstFork* nodep) override {
@ -84,75 +84,75 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} else { } else {
putbs("fork : " + nodep->name() + "\n"); putbs("fork : " + nodep->name() + "\n");
} }
iterateChildren(nodep); iterateChildrenConst(nodep);
puts(nodep->joinType().verilogKwd()); puts(nodep->joinType().verilogKwd());
puts("\n"); puts("\n");
} }
virtual void visit(AstFinal* nodep) override { virtual void visit(AstFinal* nodep) override {
putfs(nodep, "final begin\n"); putfs(nodep, "final begin\n");
iterateChildren(nodep); iterateChildrenConst(nodep);
putqs(nodep, "end\n"); putqs(nodep, "end\n");
} }
virtual void visit(AstInitial* nodep) override { virtual void visit(AstInitial* nodep) override {
putfs(nodep, "initial begin\n"); putfs(nodep, "initial begin\n");
iterateChildren(nodep); iterateChildrenConst(nodep);
putqs(nodep, "end\n"); putqs(nodep, "end\n");
} }
virtual void visit(AstInitialAutomatic* nodep) override { iterateChildren(nodep); } virtual void visit(AstInitialAutomatic* nodep) override { iterateChildrenConst(nodep); }
virtual void visit(AstAlways* nodep) override { virtual void visit(AstAlways* nodep) override {
putfs(nodep, "always "); putfs(nodep, "always ");
if (m_sensesp) { if (m_sensesp) {
iterateAndNextNull(m_sensesp); iterateAndNextConstNull(m_sensesp);
} // In active } // In active
else { else {
iterateAndNextNull(nodep->sensesp()); iterateAndNextConstNull(nodep->sensesp());
} }
putbs(" begin\n"); putbs(" begin\n");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
putqs(nodep, "end\n"); putqs(nodep, "end\n");
} }
virtual void visit(AstAlwaysPublic* nodep) override { virtual void visit(AstAlwaysPublic* nodep) override {
putfs(nodep, "/*verilator public_flat_rw "); putfs(nodep, "/*verilator public_flat_rw ");
if (m_sensesp) { if (m_sensesp) {
iterateAndNextNull(m_sensesp); iterateAndNextConstNull(m_sensesp);
} // In active } // In active
else { else {
iterateAndNextNull(nodep->sensesp()); iterateAndNextConstNull(nodep->sensesp());
} }
putqs(nodep, " "); putqs(nodep, " ");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
putqs(nodep, "*/\n"); putqs(nodep, "*/\n");
} }
virtual void visit(AstNodeAssign* nodep) override { virtual void visit(AstNodeAssign* nodep) override {
if (VN_IS(nodep, AssignForce)) puts("force "); if (VN_IS(nodep, AssignForce)) puts("force ");
iterateAndNextNull(nodep->lhsp()); iterateAndNextConstNull(nodep->lhsp());
putfs(nodep, " " + nodep->verilogKwd() + " "); putfs(nodep, " " + nodep->verilogKwd() + " ");
iterateAndNextNull(nodep->rhsp()); iterateAndNextConstNull(nodep->rhsp());
if (!m_suppressSemi) puts(";\n"); if (!m_suppressSemi) puts(";\n");
} }
virtual void visit(AstAssignDly* nodep) override { virtual void visit(AstAssignDly* nodep) override {
iterateAndNextNull(nodep->lhsp()); iterateAndNextConstNull(nodep->lhsp());
putfs(nodep, " <= "); putfs(nodep, " <= ");
iterateAndNextNull(nodep->rhsp()); iterateAndNextConstNull(nodep->rhsp());
puts(";\n"); puts(";\n");
} }
virtual void visit(AstAssignAlias* nodep) override { virtual void visit(AstAssignAlias* nodep) override {
putbs("alias "); putbs("alias ");
iterateAndNextNull(nodep->lhsp()); iterateAndNextConstNull(nodep->lhsp());
putfs(nodep, " = "); putfs(nodep, " = ");
iterateAndNextNull(nodep->rhsp()); iterateAndNextConstNull(nodep->rhsp());
if (!m_suppressSemi) puts(";\n"); if (!m_suppressSemi) puts(";\n");
} }
virtual void visit(AstAssignW* nodep) override { virtual void visit(AstAssignW* nodep) override {
putfs(nodep, "assign "); putfs(nodep, "assign ");
iterateAndNextNull(nodep->lhsp()); iterateAndNextConstNull(nodep->lhsp());
putbs(" = "); putbs(" = ");
iterateAndNextNull(nodep->rhsp()); iterateAndNextConstNull(nodep->rhsp());
if (!m_suppressSemi) puts(";\n"); if (!m_suppressSemi) puts(";\n");
} }
virtual void visit(AstRelease* nodep) override { virtual void visit(AstRelease* nodep) override {
puts("release "); puts("release ");
iterateAndNextNull(nodep->lhsp()); iterateAndNextConstNull(nodep->lhsp());
if (!m_suppressSemi) puts(";\n"); if (!m_suppressSemi) puts(";\n");
} }
virtual void visit(AstBreak*) override { virtual void visit(AstBreak*) override {
@ -172,7 +172,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
putfs(nodep, ""); putfs(nodep, "");
puts(nodep->edgeType().verilogKwd()); puts(nodep->edgeType().verilogKwd());
if (nodep->sensp()) puts(" "); if (nodep->sensp()) puts(" ");
iterateChildren(nodep); iterateChildrenConst(nodep);
} }
virtual void visit(AstNodeCase* nodep) override { virtual void visit(AstNodeCase* nodep) override {
putfs(nodep, ""); putfs(nodep, "");
@ -183,7 +183,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} }
puts(nodep->verilogKwd()); puts(nodep->verilogKwd());
puts(" ("); puts(" (");
iterateAndNextNull(nodep->exprp()); iterateAndNextConstNull(nodep->exprp());
puts(")\n"); puts(")\n");
if (const AstCase* const casep = VN_CAST(nodep, Case)) { if (const AstCase* const casep = VN_CAST(nodep, Case)) {
if (casep->fullPragma() || casep->parallelPragma()) { if (casep->fullPragma() || casep->parallelPragma()) {
@ -192,22 +192,22 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
if (casep->parallelPragma()) puts(" parallel_case"); if (casep->parallelPragma()) puts(" parallel_case");
} }
} }
iterateAndNextNull(nodep->itemsp()); iterateAndNextConstNull(nodep->itemsp());
putqs(nodep, "endcase\n"); putqs(nodep, "endcase\n");
} }
virtual void visit(AstCaseItem* nodep) override { virtual void visit(AstCaseItem* nodep) override {
if (nodep->condsp()) { if (nodep->condsp()) {
iterateAndNextNull(nodep->condsp()); iterateAndNextConstNull(nodep->condsp());
} else { } else {
putbs("default"); putbs("default");
} }
putfs(nodep, ": begin "); putfs(nodep, ": begin ");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
putqs(nodep, "end\n"); putqs(nodep, "end\n");
} }
virtual void visit(AstComment* nodep) override { virtual void visit(AstComment* nodep) override {
puts(string("// ") + nodep->name() + "\n"); puts(string("// ") + nodep->name() + "\n");
iterateChildren(nodep); iterateChildrenConst(nodep);
} }
virtual void visit(AstContinue*) override { virtual void visit(AstContinue*) override {
putbs("continue"); putbs("continue");
@ -222,13 +222,13 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
putbs("("); putbs("(");
if (fileOrStrgp) { if (fileOrStrgp) {
iterateAndNextNull(fileOrStrgp); iterateAndNextConstNull(fileOrStrgp);
putbs(", "); putbs(", ");
} }
putsQuoted(text); putsQuoted(text);
for (AstNode* expp = exprsp; expp; expp = expp->nextp()) { for (AstNode* expp = exprsp; expp; expp = expp->nextp()) {
puts(", "); puts(", ");
iterateAndNextNull(expp); iterateAndNextConstNull(expp);
} }
puts(");\n"); puts(");\n");
} }
@ -254,32 +254,32 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
virtual void visit(AstFOpen* nodep) override { virtual void visit(AstFOpen* nodep) override {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
putbs("("); putbs("(");
iterateAndNextNull(nodep->filenamep()); iterateAndNextConstNull(nodep->filenamep());
putbs(", "); putbs(", ");
iterateAndNextNull(nodep->modep()); iterateAndNextConstNull(nodep->modep());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstFOpenMcd* nodep) override { virtual void visit(AstFOpenMcd* nodep) override {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
putbs("("); putbs("(");
iterateAndNextNull(nodep->filenamep()); iterateAndNextConstNull(nodep->filenamep());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstFClose* nodep) override { virtual void visit(AstFClose* nodep) override {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
putbs("("); putbs("(");
if (nodep->filep()) iterateAndNextNull(nodep->filep()); if (nodep->filep()) iterateAndNextConstNull(nodep->filep());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstFFlush* nodep) override { virtual void visit(AstFFlush* nodep) override {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
putbs("("); putbs("(");
if (nodep->filep()) iterateAndNextNull(nodep->filep()); if (nodep->filep()) iterateAndNextConstNull(nodep->filep());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstJumpBlock* nodep) override { virtual void visit(AstJumpBlock* nodep) override {
putbs("begin : label" + cvtToStr(nodep->labelNum()) + "\n"); putbs("begin : label" + cvtToStr(nodep->labelNum()) + "\n");
if (nodep->stmtsp()) iterateAndNextNull(nodep->stmtsp()); if (nodep->stmtsp()) iterateAndNextConstNull(nodep->stmtsp());
puts("end\n"); puts("end\n");
} }
virtual void visit(AstJumpGo* nodep) override { virtual void visit(AstJumpGo* nodep) override {
@ -291,27 +291,27 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
virtual void visit(AstNodeReadWriteMem* nodep) override { virtual void visit(AstNodeReadWriteMem* nodep) override {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
putbs("("); putbs("(");
if (nodep->filenamep()) iterateAndNextNull(nodep->filenamep()); if (nodep->filenamep()) iterateAndNextConstNull(nodep->filenamep());
putbs(", "); putbs(", ");
if (nodep->memp()) iterateAndNextNull(nodep->memp()); if (nodep->memp()) iterateAndNextConstNull(nodep->memp());
if (nodep->lsbp()) { if (nodep->lsbp()) {
putbs(", "); putbs(", ");
iterateAndNextNull(nodep->lsbp()); iterateAndNextConstNull(nodep->lsbp());
} }
if (nodep->msbp()) { if (nodep->msbp()) {
putbs(", "); putbs(", ");
iterateAndNextNull(nodep->msbp()); iterateAndNextConstNull(nodep->msbp());
} }
puts(");\n"); puts(");\n");
} }
virtual void visit(AstSysFuncAsTask* nodep) override { virtual void visit(AstSysFuncAsTask* nodep) override {
iterateAndNextNull(nodep->lhsp()); iterateAndNextConstNull(nodep->lhsp());
puts(";\n"); puts(";\n");
} }
virtual void visit(AstSysIgnore* nodep) override { virtual void visit(AstSysIgnore* nodep) override {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
putbs("("); putbs("(");
iterateAndNextNull(nodep->exprsp()); iterateAndNextConstNull(nodep->exprsp());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstNodeFor* nodep) override { virtual void visit(AstNodeFor* nodep) override {
@ -319,31 +319,31 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
{ {
VL_RESTORER(m_suppressSemi); VL_RESTORER(m_suppressSemi);
m_suppressSemi = true; m_suppressSemi = true;
iterateAndNextNull(nodep->initsp()); iterateAndNextConstNull(nodep->initsp());
puts(";"); puts(";");
iterateAndNextNull(nodep->condp()); iterateAndNextConstNull(nodep->condp());
puts(";"); puts(";");
iterateAndNextNull(nodep->incsp()); iterateAndNextConstNull(nodep->incsp());
} }
puts(") begin\n"); puts(") begin\n");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
putqs(nodep, "end\n"); putqs(nodep, "end\n");
} }
virtual void visit(AstRepeat* nodep) override { virtual void visit(AstRepeat* nodep) override {
putfs(nodep, "repeat ("); putfs(nodep, "repeat (");
iterateAndNextNull(nodep->countp()); iterateAndNextConstNull(nodep->countp());
puts(") begin\n"); puts(") begin\n");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
putfs(nodep, "end\n"); putfs(nodep, "end\n");
} }
virtual void visit(AstWhile* nodep) override { virtual void visit(AstWhile* nodep) override {
iterateAndNextNull(nodep->precondsp()); iterateAndNextConstNull(nodep->precondsp());
putfs(nodep, "while ("); putfs(nodep, "while (");
iterateAndNextNull(nodep->condp()); iterateAndNextConstNull(nodep->condp());
puts(") begin\n"); puts(") begin\n");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
iterateAndNextNull(nodep->incsp()); iterateAndNextConstNull(nodep->incsp());
iterateAndNextNull(nodep->precondsp()); // Need to recompute before next loop iterateAndNextConstNull(nodep->precondsp()); // Need to recompute before next loop
putfs(nodep, "end\n"); putfs(nodep, "end\n");
} }
virtual void visit(AstNodeIf* nodep) override { virtual void visit(AstNodeIf* nodep) override {
@ -354,28 +354,28 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
if (ifp->unique0Pragma()) puts("unique0 "); if (ifp->unique0Pragma()) puts("unique0 ");
} }
puts("if ("); puts("if (");
iterateAndNextNull(nodep->condp()); iterateAndNextConstNull(nodep->condp());
puts(") begin\n"); puts(") begin\n");
iterateAndNextNull(nodep->ifsp()); iterateAndNextConstNull(nodep->ifsp());
if (nodep->elsesp()) { if (nodep->elsesp()) {
putqs(nodep, "end\n"); putqs(nodep, "end\n");
putqs(nodep, "else begin\n"); putqs(nodep, "else begin\n");
iterateAndNextNull(nodep->elsesp()); iterateAndNextConstNull(nodep->elsesp());
} }
putqs(nodep, "end\n"); putqs(nodep, "end\n");
} }
virtual void visit(AstPast* nodep) override { virtual void visit(AstPast* nodep) override {
putfs(nodep, "$past("); putfs(nodep, "$past(");
iterateAndNextNull(nodep->exprp()); iterateAndNextConstNull(nodep->exprp());
if (nodep->ticksp()) { if (nodep->ticksp()) {
puts(", "); puts(", ");
iterateAndNextNull(nodep->ticksp()); iterateAndNextConstNull(nodep->ticksp());
} }
puts(")"); puts(")");
} }
virtual void visit(AstReturn* nodep) override { virtual void visit(AstReturn* nodep) override {
putfs(nodep, "return "); putfs(nodep, "return ");
iterateAndNextNull(nodep->lhsp()); iterateAndNextConstNull(nodep->lhsp());
puts(";\n"); puts(";\n");
} }
virtual void visit(AstStop* nodep) override { putfs(nodep, "$stop;\n"); } virtual void visit(AstStop* nodep) override { putfs(nodep, "$stop;\n"); }
@ -401,22 +401,22 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
virtual void visit(AstScopeName* nodep) override {} virtual void visit(AstScopeName* nodep) override {}
virtual void visit(AstCStmt* nodep) override { virtual void visit(AstCStmt* nodep) override {
putfs(nodep, "$_CSTMT("); putfs(nodep, "$_CSTMT(");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstCMath* nodep) override { virtual void visit(AstCMath* nodep) override {
putfs(nodep, "$_CMATH("); putfs(nodep, "$_CMATH(");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstUCStmt* nodep) override { virtual void visit(AstUCStmt* nodep) override {
putfs(nodep, "$c("); putfs(nodep, "$c(");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
puts(");\n"); puts(");\n");
} }
virtual void visit(AstUCFunc* nodep) override { virtual void visit(AstUCFunc* nodep) override {
putfs(nodep, "$c("); putfs(nodep, "$c(");
iterateAndNextNull(nodep->bodysp()); iterateAndNextConstNull(nodep->bodysp());
puts(")"); puts(")");
} }
@ -450,27 +450,27 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
case 'k': putbs(""); break; case 'k': putbs(""); break;
case 'l': { case 'l': {
UASSERT_OBJ(lhsp, nodep, "emitVerilog() references undef node"); UASSERT_OBJ(lhsp, nodep, "emitVerilog() references undef node");
iterateAndNextNull(lhsp); iterateAndNextConstNull(lhsp);
break; break;
} }
case 'r': { case 'r': {
UASSERT_OBJ(rhsp, nodep, "emitVerilog() references undef node"); UASSERT_OBJ(rhsp, nodep, "emitVerilog() references undef node");
iterateAndNextNull(rhsp); iterateAndNextConstNull(rhsp);
break; break;
} }
case 't': { case 't': {
UASSERT_OBJ(thsp, nodep, "emitVerilog() references undef node"); UASSERT_OBJ(thsp, nodep, "emitVerilog() references undef node");
iterateAndNextNull(thsp); iterateAndNextConstNull(thsp);
break; break;
} }
case 'o': { case 'o': {
UASSERT_OBJ(thsp, nodep, "emitVerilog() references undef node"); UASSERT_OBJ(thsp, nodep, "emitVerilog() references undef node");
iterateAndNextNull(fhsp); iterateAndNextConstNull(fhsp);
break; break;
} }
case 'd': { case 'd': {
UASSERT_OBJ(nodep->dtypep(), nodep, "emitVerilog() references undef node"); UASSERT_OBJ(nodep->dtypep(), nodep, "emitVerilog() references undef node");
iterateAndNextNull(nodep->dtypep()); iterateAndNextConstNull(nodep->dtypep());
break; break;
} }
default: nodep->v3fatalSrc("Unknown emitVerilog format code: %" << c); break; default: nodep->v3fatalSrc("Unknown emitVerilog format code: %" << c); break;
@ -494,10 +494,10 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} }
virtual void visit(AstAttrOf* nodep) override { virtual void visit(AstAttrOf* nodep) override {
putfs(nodep, "$_ATTROF("); putfs(nodep, "$_ATTROF(");
iterateAndNextNull(nodep->fromp()); iterateAndNextConstNull(nodep->fromp());
if (nodep->dimp()) { if (nodep->dimp()) {
putbs(", "); putbs(", ");
iterateAndNextNull(nodep->dimp()); iterateAndNextConstNull(nodep->dimp());
} }
puts(")"); puts(")");
} }
@ -516,11 +516,11 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} }
virtual void visit(AstNodeCond* nodep) override { virtual void visit(AstNodeCond* nodep) override {
putbs("("); putbs("(");
iterateAndNextNull(nodep->condp()); iterateAndNextConstNull(nodep->condp());
putfs(nodep, " ? "); putfs(nodep, " ? ");
iterateAndNextNull(nodep->expr1p()); iterateAndNextConstNull(nodep->expr1p());
putbs(" : "); putbs(" : ");
iterateAndNextNull(nodep->expr2p()); iterateAndNextConstNull(nodep->expr2p());
puts(")"); puts(")");
} }
virtual void visit(AstRange* nodep) override { virtual void visit(AstRange* nodep) override {
@ -532,21 +532,21 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
puts(cvtToStr(nodep->rightConst())); puts(cvtToStr(nodep->rightConst()));
puts("]"); puts("]");
} else { } else {
iterateAndNextNull(nodep->leftp()); iterateAndNextConstNull(nodep->leftp());
puts(":"); puts(":");
iterateAndNextNull(nodep->rightp()); iterateAndNextConstNull(nodep->rightp());
puts("]"); puts("]");
} }
} }
virtual void visit(AstSel* nodep) override { virtual void visit(AstSel* nodep) override {
iterateAndNextNull(nodep->fromp()); iterateAndNextConstNull(nodep->fromp());
puts("["); puts("[");
if (VN_IS(nodep->lsbp(), Const)) { if (VN_IS(nodep->lsbp(), Const)) {
if (nodep->widthp()->isOne()) { if (nodep->widthp()->isOne()) {
if (VN_IS(nodep->lsbp(), Const)) { if (VN_IS(nodep->lsbp(), Const)) {
puts(cvtToStr(VN_AS(nodep->lsbp(), Const)->toSInt())); puts(cvtToStr(VN_AS(nodep->lsbp(), Const)->toSInt()));
} else { } else {
iterateAndNextNull(nodep->lsbp()); iterateAndNextConstNull(nodep->lsbp());
} }
} else { } else {
puts(cvtToStr(VN_AS(nodep->lsbp(), Const)->toSInt() puts(cvtToStr(VN_AS(nodep->lsbp(), Const)->toSInt()
@ -555,20 +555,20 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
puts(cvtToStr(VN_AS(nodep->lsbp(), Const)->toSInt())); puts(cvtToStr(VN_AS(nodep->lsbp(), Const)->toSInt()));
} }
} else { } else {
iterateAndNextNull(nodep->lsbp()); iterateAndNextConstNull(nodep->lsbp());
putfs(nodep, "+:"); putfs(nodep, "+:");
iterateAndNextNull(nodep->widthp()); iterateAndNextConstNull(nodep->widthp());
puts("]"); puts("]");
} }
puts("]"); puts("]");
} }
virtual void visit(AstSliceSel* nodep) override { virtual void visit(AstSliceSel* nodep) override {
iterateAndNextNull(nodep->fromp()); iterateAndNextConstNull(nodep->fromp());
puts(cvtToStr(nodep->declRange())); puts(cvtToStr(nodep->declRange()));
} }
virtual void visit(AstTypedef* nodep) override { virtual void visit(AstTypedef* nodep) override {
putfs(nodep, "typedef "); putfs(nodep, "typedef ");
iterateAndNextNull(nodep->dtypep()); iterateAndNextConstNull(nodep->dtypep());
puts(" "); puts(" ");
puts(nodep->prettyName()); puts(nodep->prettyName());
puts(";\n"); puts(";\n");
@ -578,7 +578,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
putfs(nodep, nodep->prettyName()); putfs(nodep, nodep->prettyName());
if (nodep->rangep()) { if (nodep->rangep()) {
puts(" "); puts(" ");
iterateAndNextNull(nodep->rangep()); iterateAndNextConstNull(nodep->rangep());
puts(" "); puts(" ");
} else if (nodep->isRanged()) { } else if (nodep->isRanged()) {
puts(" ["); puts(" [");
@ -592,14 +592,14 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} }
virtual void visit(AstNodeArrayDType* nodep) override { virtual void visit(AstNodeArrayDType* nodep) override {
iterate(nodep->subDTypep()); iterate(nodep->subDTypep());
iterateAndNextNull(nodep->rangep()); iterateAndNextConstNull(nodep->rangep());
} }
virtual void visit(AstNodeUOrStructDType* nodep) override { virtual void visit(AstNodeUOrStructDType* nodep) override {
puts(nodep->verilogKwd() + " "); puts(nodep->verilogKwd() + " ");
if (nodep->packed()) puts("packed "); if (nodep->packed()) puts("packed ");
puts("\n"); puts("\n");
puts("{"); puts("{");
iterateAndNextNull(nodep->membersp()); iterateAndNextConstNull(nodep->membersp());
puts("}"); puts("}");
} }
virtual void visit(AstMemberDType* nodep) override { virtual void visit(AstMemberDType* nodep) override {
@ -616,10 +616,10 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
putfs(nodep, nodep->prettyName()); putfs(nodep, nodep->prettyName());
} }
puts("("); puts("(");
iterateAndNextNull(nodep->pinsp()); iterateAndNextConstNull(nodep->pinsp());
puts(")"); puts(")");
} }
virtual void visit(AstArg* nodep) override { iterateAndNextNull(nodep->exprp()); } virtual void visit(AstArg* nodep) override { iterateAndNextConstNull(nodep->exprp()); }
virtual void visit(AstPrintTimeScale* nodep) override { virtual void visit(AstPrintTimeScale* nodep) override {
puts(nodep->verilogKwd()); puts(nodep->verilogKwd());
puts(";\n"); puts(";\n");
@ -654,8 +654,8 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
virtual void visit(AstConst* nodep) override { putfs(nodep, nodep->num().ascii(true, true)); } virtual void visit(AstConst* nodep) override { putfs(nodep, nodep->num().ascii(true, true)); }
// Just iterate // Just iterate
virtual void visit(AstTopScope* nodep) override { iterateChildren(nodep); } virtual void visit(AstTopScope* nodep) override { iterateChildrenConst(nodep); }
virtual void visit(AstScope* nodep) override { iterateChildren(nodep); } virtual void visit(AstScope* nodep) override { iterateChildrenConst(nodep); }
virtual void visit(AstVar* nodep) override { virtual void visit(AstVar* nodep) override {
if (nodep->isIO()) { if (nodep->isIO()) {
putfs(nodep, nodep->verilogKwd()); putfs(nodep, nodep->verilogKwd());
@ -686,7 +686,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
} }
virtual void visit(AstActive* nodep) override { virtual void visit(AstActive* nodep) override {
m_sensesp = nodep->sensesp(); m_sensesp = nodep->sensesp();
iterateAndNextNull(nodep->stmtsp()); iterateAndNextConstNull(nodep->stmtsp());
m_sensesp = nullptr; m_sensesp = nullptr;
} }
virtual void visit(AstParseRef* nodep) override { puts(nodep->prettyName()); } virtual void visit(AstParseRef* nodep) override { puts(nodep->prettyName()); }
@ -700,7 +700,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor {
// Default // Default
virtual void visit(AstNode* nodep) override { virtual void visit(AstNode* nodep) override {
puts(string("\n???? // ") + nodep->prettyTypeName() + "\n"); puts(string("\n???? // ") + nodep->prettyTypeName() + "\n");
iterateChildren(nodep); iterateChildrenConst(nodep);
// Not v3fatalSrc so we keep processing // Not v3fatalSrc so we keep processing
if (!m_suppressUnknown) { if (!m_suppressUnknown) {
nodep->v3error( nodep->v3error(
@ -754,10 +754,10 @@ class EmitVStreamVisitor final : public EmitVBaseVisitor {
virtual void putqs(AstNode*, const string& str) override { putbs(str); } virtual void putqs(AstNode*, const string& str) override { putbs(str); }
public: public:
EmitVStreamVisitor(AstNode* nodep, std::ostream& os) EmitVStreamVisitor(const AstNode* nodep, std::ostream& os)
: EmitVBaseVisitor{false, nullptr} : EmitVBaseVisitor{false, nullptr}
, m_os(os) { // Need () or GCC 4.8 false warning , m_os(os) { // Need () or GCC 4.8 false warning
iterate(nodep); iterate(const_cast<AstNode*>(nodep));
} }
virtual ~EmitVStreamVisitor() override = default; virtual ~EmitVStreamVisitor() override = default;
}; };
@ -828,12 +828,12 @@ class EmitVPrefixedVisitor final : public EmitVBaseVisitor {
} }
public: public:
EmitVPrefixedVisitor(AstNode* nodep, std::ostream& os, const string& prefix, int flWidth, EmitVPrefixedVisitor(const AstNode* nodep, std::ostream& os, const string& prefix, int flWidth,
AstSenTree* domainp, bool user3mark) AstSenTree* domainp, bool user3mark)
: EmitVBaseVisitor{false, domainp} : EmitVBaseVisitor{false, domainp}
, m_formatter{os, prefix, flWidth} { , m_formatter{os, prefix, flWidth} {
if (user3mark) VNUser3InUse::check(); if (user3mark) VNUser3InUse::check();
iterate(nodep); iterate(const_cast<AstNode*>(nodep));
} }
virtual ~EmitVPrefixedVisitor() override = default; virtual ~EmitVPrefixedVisitor() override = default;
}; };
@ -841,11 +841,11 @@ public:
//###################################################################### //######################################################################
// EmitV class functions // EmitV class functions
void V3EmitV::verilogForTree(AstNode* nodep, std::ostream& os) { void V3EmitV::verilogForTree(const AstNode* nodep, std::ostream& os) {
{ EmitVStreamVisitor{nodep, os}; } { EmitVStreamVisitor{nodep, os}; }
} }
void V3EmitV::verilogPrefixedTree(AstNode* nodep, std::ostream& os, const string& prefix, void V3EmitV::verilogPrefixedTree(const AstNode* nodep, std::ostream& os, const string& prefix,
int flWidth, AstSenTree* domainp, bool user3mark) { int flWidth, AstSenTree* domainp, bool user3mark) {
{ EmitVPrefixedVisitor{nodep, os, prefix, flWidth, domainp, user3mark}; } { EmitVPrefixedVisitor{nodep, os, prefix, flWidth, domainp, user3mark}; }
} }

View File

@ -27,8 +27,8 @@ class AstSenTree;
class V3EmitV final { class V3EmitV final {
public: public:
static void verilogForTree(AstNode* nodep, std::ostream& os = std::cout); static void verilogForTree(const AstNode* nodep, std::ostream& os = std::cout);
static void verilogPrefixedTree(AstNode* nodep, std::ostream& os, const string& prefix, static void verilogPrefixedTree(const AstNode* nodep, std::ostream& os, const string& prefix,
int flWidth, AstSenTree* domainp, bool user3mark); int flWidth, AstSenTree* domainp, bool user3mark);
static void emitvFiles(); static void emitvFiles();
static void debugEmitV(const string& filename); static void debugEmitV(const string& filename);