From 2ccf49031b86a54fdfc766e8b3ac14cc1b752d3b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 17 Nov 2021 18:50:52 -0500 Subject: [PATCH] Fix $display of signed/unsigned without format (#3207). --- Changes | 1 + src/V3Width.cpp | 2 ++ test_regress/t/t_debug_emitv.out | 4 ++-- test_regress/t/t_display.out | 6 ++++++ test_regress/t/t_display.v | 6 ++++++ test_regress/t/t_sys_file_basic.out | 2 +- 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 0a5f0c2f2..cc0bc92e2 100644 --- a/Changes +++ b/Changes @@ -21,6 +21,7 @@ Verilator 4.215 devel * Improve --thread verilation-time performance. * Fix array method names with parenthesis (#3181) (#3183). [Teng Huang] * Fix split_var assign merging (#3177) (#3179). [Yutetsu TAKATSUKASA] +* Fix $display of signed/unsigned without format (#3207). [Julie Schwartz] * Fix nested generate if genblk naming (#3189). [yanx21] * Fix display of empty string constant (#3207). [Julie Schwartz] * Fix %0 format on $value$plusargs. diff --git a/src/V3Width.cpp b/src/V3Width.cpp index d53574c2f..efb66f75b 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -3916,6 +3916,8 @@ private: ch = 'g'; } else if (argp && argp->isString()) { ch = '@'; + } else if (nodep->missingArgChar() == 'd' && argp->isSigned()) { + ch = '~'; } else { ch = nodep->missingArgChar(); } diff --git a/test_regress/t/t_debug_emitv.out b/test_regress/t/t_debug_emitv.out index d10784ec3..c7b2e8201 100644 --- a/test_regress/t/t_debug_emitv.out +++ b/test_regress/t/t_debug_emitv.out @@ -88,7 +88,7 @@ module Vt_debug_emitv___024root; $fflush(t.fd); $fscanf(t.fd, "%d", t.sum); ; - $fdisplay(32'h69203d20, "%d", t.sum); + $fdisplay(32'h69203d20, "%~", t.sum); $fwrite(t.fd, "hello"); $readmemh(t.fd, t.array); $readmemh(t.fd, t.array, 32'sh0); @@ -161,7 +161,7 @@ module Vt_debug_emitv___024root; else begin $display("0"); end - $display("%d%d", t._Vpast_0_0t._Vpast_1_0, + $display("%~%~", t._Vpast_0_0t._Vpast_1_0, t._Vpast_1_0); t.str = $sformatf("cyc=%~", t.cyc); ; diff --git a/test_regress/t/t_display.out b/test_regress/t/t_display.out index 5b3ba2aa9..7774e9e34 100644 --- a/test_regress/t/t_display.out +++ b/test_regress/t/t_display.out @@ -51,6 +51,12 @@ o: 014 014 b: 000001100 000001100 +-1431655766 +-1431655766 +4294967294 +4294967294 +2863311530 +2863311530 [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 fa280f616..0da4596e2 100644 --- a/test_regress/t/t_display.v +++ b/test_regress/t/t_display.v @@ -142,6 +142,12 @@ module t; $writeb; $displayb; $writeb("b: "); $writeb(nine); $writeb(" "); $displayb(nine); $writeo; $displayo; + $display("%d", $signed(32'haaaaaaaa)); // -1431655766 + $display($signed(32'haaaaaaaa)); // -1431655766 + $display("%d", $unsigned(-2)); // 4294967294 + $display($unsigned(-2)); // 4294967294 + $display("%d", 32'haaaaaaaa); // 2863311530 + $display(32'haaaaaaaa); // 2863311530 $display("[%0t] %s%s%s", $time, "hel", "lo, fr", "om a very long string. Percent %s are literally substituted in."); diff --git a/test_regress/t/t_sys_file_basic.out b/test_regress/t/t_sys_file_basic.out index 848109f37..931ff0fc2 100644 --- a/test_regress/t/t_sys_file_basic.out +++ b/test_regress/t/t_sys_file_basic.out @@ -1,6 +1,6 @@ [0] hello v=12345667 [0] Hello2 -d: 12 12 +d: 12 12 h: 0000000c 0000000c