From 933e796cc2f1e164396135bd0831e03cd134f3ea Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 6 Jun 2020 14:47:54 -0400 Subject: [PATCH] Support $swrite with arbitrary arguments --- src/V3AstNodes.h | 5 +++++ src/verilog.y | 10 +++++----- test_regress/t/t_sys_sformat.v | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index dc7c87a9f..faaead3ab 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -3708,6 +3708,11 @@ public: setOp1p(new AstSFormatF(fl, text, true, exprsp, missingArgChar)); setOp3p(lhsp); } + AstSFormat(FileLine* fl, AstNode* lhsp, AstNode* exprsp, char missingArgChar = 'd') + : ASTGEN_SUPER(fl) { + setOp1p(new AstSFormatF(fl, AstSFormatF::NoFormat(), exprsp, missingArgChar)); + setOp3p(lhsp); + } ASTNODE_NODE_FUNCS(SFormat) virtual const char* broken() const { BROKEN_RTN(!fmtp()); diff --git a/src/verilog.y b/src/verilog.y index 78952599e..b1ac37556 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3450,11 +3450,11 @@ system_t_call: // IEEE: system_tf_call (as task) | yD_STOP parenE { $$ = new AstStop($1, false); } | yD_STOP '(' expr ')' { $$ = new AstStop($1, false); DEL($3); } // - | yD_SFORMAT '(' expr ',' str commaEListE ')' { $$ = new AstSFormat($1, $3, *$5, $6); } - | yD_SWRITE '(' expr ',' str commaEListE ')' { $$ = new AstSFormat($1, $3, *$5, $6); } - | yD_SWRITEB '(' expr ',' str commaEListE ')' { $$ = new AstSFormat($1, $3, *$5, $6, 'b'); } - | yD_SWRITEH '(' expr ',' str commaEListE ')' { $$ = new AstSFormat($1, $3, *$5, $6, 'h'); } - | yD_SWRITEO '(' expr ',' str commaEListE ')' { $$ = new AstSFormat($1, $3, *$5, $6, 'o'); } + | yD_SFORMAT '(' expr ',' exprDispList ')' { $$ = new AstSFormat($1, $3, $5); } + | yD_SWRITE '(' expr ',' exprDispList ')' { $$ = new AstSFormat($1, $3, $5); } + | yD_SWRITEB '(' expr ',' exprDispList ')' { $$ = new AstSFormat($1, $3, $5, 'b'); } + | yD_SWRITEH '(' expr ',' exprDispList ')' { $$ = new AstSFormat($1, $3, $5, 'h'); } + | yD_SWRITEO '(' expr ',' exprDispList ')' { $$ = new AstSFormat($1, $3, $5, 'o'); } // | yD_DISPLAY parenE { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY, NULL, NULL); } | yD_DISPLAY '(' exprDispList ')' { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY, NULL, $3); } diff --git a/test_regress/t/t_sys_sformat.v b/test_regress/t/t_sys_sformat.v index ecd5f8eb3..96bf9f389 100644 --- a/test_regress/t/t_sys_sformat.v +++ b/test_regress/t/t_sys_sformat.v @@ -43,6 +43,11 @@ module t; $swrite(str2, "e=%f", r); $swrite(str2, "e=%g", r); + str3 = "hello"; + $swrite(str2, {str3, str3}); +`ifdef TEST_VERBOSE $display("str2=%0s",str2); `endif + if (str2 !== "hellohello") $stop; + r = 0.01; $swrite(str2, "e=%e f=%f g=%g", r, r, r); `ifdef TEST_VERBOSE $display("str2=%0s",str2); `endif