diff --git a/Changes b/Changes index 566675607..6975cac23 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix fault on $realtime with %t, bug1443. [Julien Margetts] +**** Fix $display with string without %s, bug1441. [Denis Rystsov] + **** Fix parameter function string returns, bug1441. [Denis Rystsov] diff --git a/src/V3LinkResolve.cpp b/src/V3LinkResolve.cpp index 6f94aaf71..623ac89d4 100644 --- a/src/V3LinkResolve.cpp +++ b/src/V3LinkResolve.cpp @@ -341,13 +341,13 @@ private: AstNode *nextp = argp->nextp(); argp->unlinkFrBack(); pushDeletep(argp); VL_DANGLING(argp); argp = nextp; - } else { - newFormat.append("%h"); - argp = argp->nextp(); - } - } - } - return newFormat; + } else { + newFormat.append("%?"); // V3Width to figure it out + argp = argp->nextp(); + } + } + } + return newFormat; } void expectDescriptor(AstNode* nodep, AstNodeVarRef* filep) { diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 1024e383a..b54e10474 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -2179,6 +2179,17 @@ private: if (argp) argp = argp->nextp(); break; } + case '?': { // Unspecified by user, guess + if (argp && argp->isDouble()) { + ch = 'g'; + } else if (argp && argp->isString()) { + ch = '@'; + } else { + ch = 'h'; + } + if (argp) argp = argp->nextp(); + break; + } default: { // Most operators, just move to next argument if (argp) argp=argp->nextp(); break; diff --git a/test_regress/t/t_display_string.out b/test_regress/t/t_display_string.out index 34c0ef735..85322223a 100644 --- a/test_regress/t/t_display_string.out +++ b/test_regress/t/t_display_string.out @@ -1,5 +1,7 @@ String: ' 1' +foo(1): ' 1' s f(1): ' 1' s parm: ' 1' s strg: ' 1' +r: 1.234 *-* All Finished *-* diff --git a/test_regress/t/t_display_string.v b/test_regress/t/t_display_string.v index 70d60b272..f2bd7deaa 100644 --- a/test_regress/t/t_display_string.v +++ b/test_regress/t/t_display_string.v @@ -7,14 +7,16 @@ module t; function automatic string foo(int i); return $sformatf("'%d'", i); // %0d does not work here endfunction + real r = 1.234; string bar = foo(1); localparam string pbar = foo(1); initial begin $write("String: "); $display("' 1'"); - //$write("foo(1): "); $display(foo(1)); + $write("foo(1): "); $display(foo(1)); $write("s f(1): "); $display("%s", foo(1)); $write("s parm: "); $display("%s", pbar); $write("s strg: "); $display("%s", bar); + $write("r: "); $display(r); $write("*-* All Finished *-*\n"); $finish; end