From cad2780219b300e34ea0d52a7b0ab8a561f3d4cf Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 11 Nov 2023 15:28:44 -0500 Subject: [PATCH] Fix display with no % printing assoc array (#4376). --- Changes | 1 + src/V3Width.cpp | 30 +++++++++++++++--------------- test_regress/t/t_display.out | 1 + test_regress/t/t_display.v | 3 +++ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Changes b/Changes index cd4251e07..1901104dc 100644 --- a/Changes +++ b/Changes @@ -23,6 +23,7 @@ Verilator 5.019 devel * Remove deprecated options (#4663). [Geza Lore] * Optimize timing-delayed queue (#4584). [qrqiuren] * Fix VPI TOP level variable iteration (#3919) (#4618). [Marlon James] +* Fix display with no % printing assoc array (#4376). [Alex Solomatnikov] * Fix scheduling of external force signals (#4577) (#4668). [Geza Lore] * Fix a memory leak in V3Fork (#4628). [Krzysztof BoroĊ„ski] * Fix linking parameterized hierarchical blocks and recursive hierarchical blocks (#4654). [Anthony Donlon] diff --git a/src/V3Width.cpp b/src/V3Width.cpp index d5442754d..4c5d0c0ee 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -4843,6 +4843,21 @@ private: } else if (inPct) { inPct = false; bool added = false; + const AstNodeDType* const dtypep = argp ? argp->dtypep()->skipRefp() : nullptr; + const AstBasicDType* const basicp = dtypep ? dtypep->basicp() : nullptr; + if (ch == '?') { // Unspecified by user, guess + if (argp && argp->isDouble()) { + ch = 'g'; + } else if (argp && argp->isString()) { + ch = '@'; + } else if (nodep->missingArgChar() == 'd' && argp->isSigned()) { + ch = '~'; + } else if (basicp) { + ch = nodep->missingArgChar(); + } else { + ch = 'p'; + } + } switch (std::tolower(ch)) { case '%': break; // %% - just output a % case 'm': break; // %m - auto insert "name" @@ -4871,8 +4886,6 @@ private: break; } case 'p': { // Pattern - const AstNodeDType* const dtypep = argp ? argp->dtypep()->skipRefp() : nullptr; - const AstBasicDType* const basicp = dtypep ? dtypep->basicp() : nullptr; if (basicp && basicp->isString()) { added = true; newFormat += "\"%@\""; @@ -4944,19 +4957,6 @@ private: } break; } - case '?': { // Unspecified by user, guess - if (argp && argp->isDouble()) { - ch = 'g'; - } else if (argp && argp->isString()) { - ch = '@'; - } else if (nodep->missingArgChar() == 'd' && argp->isSigned()) { - ch = '~'; - } else { - ch = nodep->missingArgChar(); - } - if (argp) argp = VN_AS(argp->nextp(), NodeExpr); - break; - } default: { // Most operators, just move to next argument if (argp) argp = VN_AS(argp->nextp(), NodeExpr); break; diff --git a/test_regress/t/t_display.out b/test_regress/t/t_display.out index 00db3a06d..259cffc0f 100644 --- a/test_regress/t/t_display.out +++ b/test_regress/t/t_display.out @@ -61,6 +61,7 @@ b: 000001100 000001100 4294967294 2863311530 2863311530 +assoc_c='{} [0] hello, from a very long string. Percent %s are literally substituted in. hello, from a concatenated string. hello, from a concatenated format string [0]. diff --git a/test_regress/t/t_display.v b/test_regress/t/t_display.v index ca2b59b21..9e23bd3b6 100644 --- a/test_regress/t/t_display.v +++ b/test_regress/t/t_display.v @@ -19,6 +19,8 @@ module t; string svs = "sv-str"; reg [31:0] regstr = "meep"; + reg [5:0] assoc_c[int]; + sub sub (); sub2 sub2 (); sub3 sub3 (); @@ -156,6 +158,7 @@ module t; $display($unsigned(-2)); // 4294967294 $display("%d", 32'haaaaaaaa); // 2863311530 $display(32'haaaaaaaa); // 2863311530 + $display("assoc_c=", assoc_c); // Default to %p $display("[%0t] %s%s%s", $time, "hel", "lo, fr", "om a very long string. Percent %s are literally substituted in.");