From 98282114c92fe04d520ba51d7e3404953cd6bbe4 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 6 Mar 2007 18:53:24 +0000 Subject: [PATCH] Fix display %m names inside named blocks. git-svn-id: file://localhost/svn/verilator/trunk/verilator@897 77ca24e4-aefa-0310-84f0-b9a241c72d87 --- Changes | 2 ++ src/V3AstNodes.h | 1 + src/V3Begin.cpp | 12 ++++++++++++ src/V3Inline.cpp | 4 ++-- test_regress/t/t_display.pl | 2 ++ test_regress/t/t_display.v | 14 ++++++++++++-- 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 330dacd3b..30a476df3 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix "Loops detected" assertion when model exceeds 4GB. [David Hewson] +**** Fix display %m names inside named blocks. + * Verilator 3.633 2/7/2007 *** Add --trace-depth option for minimizing VCD file size. [Emerson Suguimoto] diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 384c116ed..b773cc458 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -1265,6 +1265,7 @@ public: AstNode* scopeAttrp() const { return op3p(); } AstText* scopeTextp() const { return op3p()->castText(); } void scopeAttrp(AstNode* nodep) { addOp3p(nodep); } + bool needScopeTracking() { return name().find("%m") != string::npos; } }; struct AstFClose : public AstNodeStmt { diff --git a/src/V3Begin.cpp b/src/V3Begin.cpp index 4c048f2c6..1a9c67572 100644 --- a/src/V3Begin.cpp +++ b/src/V3Begin.cpp @@ -131,6 +131,18 @@ private: nodep->replaceWith(newp); nodep->deleteTree(); nodep=NULL; } + virtual void visit(AstDisplay* nodep, AstNUser*) { + // If there's a %m in the display text, we add a special node that will contain the name() + // Similar code in V3Inline + if (m_beginScope != "" && nodep->needScopeTracking()) { + // To keep correct visual order, must add before other Text's + AstNode* afterp = nodep->scopeAttrp(); + if (afterp) afterp->unlinkFrBackWithNext(); + nodep->scopeAttrp(new AstText(nodep->fileline(), (string)"."+AstNode::prettyName(m_beginScope))); + if (afterp) nodep->scopeAttrp(afterp); + } + nodep->iterateChildren(*this); + } virtual void visit(AstNode* nodep, AstNUser*) { nodep->iterateChildren(*this); } diff --git a/src/V3Inline.cpp b/src/V3Inline.cpp index aa5ed0c6e..36e2f6fa2 100644 --- a/src/V3Inline.cpp +++ b/src/V3Inline.cpp @@ -235,8 +235,8 @@ private: } virtual void visit(AstDisplay* nodep, AstNUser*) { // If there's a %m in the display text, we add a special node that will contain the name() - if (m_cellp - && nodep->name().find("%m") != string::npos) { + // Similar code in V3Begin + if (m_cellp && nodep->needScopeTracking()) { // To keep correct visual order, must add before other Text's AstNode* afterp = nodep->scopeAttrp(); if (afterp) afterp->unlinkFrBackWithNext(); diff --git a/test_regress/t/t_display.pl b/test_regress/t/t_display.pl index ae96409e6..af041fd7a 100755 --- a/test_regress/t/t_display.pl +++ b/test_regress/t/t_display.pl @@ -15,7 +15,9 @@ execute ( expect=>quotemeta( '[0] In TOP.v: Hi [0] In TOP.v.sub +[0] In TOP.v.sub.subblock [0] In TOP.v.sub2 +[0] In TOP.v.sub2.subblock2 [0] %X=0c %D=12 %0X=c %0O=14 %B=001100 [0] %x=0c %d=12 %0x=c %0o=14 %b=001100 [0] %x=00abbbbcccc %0x=abbbbcccc %o=00527356746314 %b=00000101010111011101110111100110011001100 diff --git a/test_regress/t/t_display.v b/test_regress/t/t_display.v index 3e5339414..551d53381 100644 --- a/test_regress/t/t_display.v +++ b/test_regress/t/t_display.v @@ -44,13 +44,23 @@ endmodule module sub; task write_m; - $write("[%0t] In %m\n", $time); + begin + $write("[%0t] In %m\n", $time); + begin : subblock + $write("[%0t] In %m\n", $time); + end + end endtask endmodule module sub2; // verilator no_inline_module task write_m; - $write("[%0t] In %m\n", $time); + begin + $write("[%0t] In %m\n", $time); + begin : subblock2 + $write("[%0t] In %m\n", $time); + end + end endtask endmodule