From b97e1aa9fe3a9f912f27b2a63d0893a8bacd0f18 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 10 May 2020 15:42:16 -0400 Subject: [PATCH] Support cast to string --- src/verilog.y | 11 ++++++----- test_regress/t/t_string.v | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/verilog.y b/src/verilog.y index 003f02b02..625834280 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1585,9 +1585,9 @@ casting_type: // IEEE: casting_type // // // IEEE: signing //See where casting_type used - //^^ ySIGNED { $$ = new AstSigned($1,$3); } - //^^ yUNSIGNED { $$ = new AstUnsigned($1,$3); } - //UNSUP ySTRING { $$ = $1; } + //^^ ySIGNED { in parent rule } + //^^ yUNSIGNED { in parent rule } + //^^ ySTRING { in parent rule } //UNSUP yCONST__ETC/*then `*/ { $$ = $1; } ; @@ -3889,8 +3889,9 @@ expr: // IEEE: part of expression/constant_expression/primary // // IEEE: cast/constant_cast | casting_type yP_TICK '(' expr ')' { $$ = new AstCast($1->fileline(), $4, $1); } // // expanded from casting_type - | ySIGNED yP_TICK '(' expr ')' { $$ = new AstSigned($1,$4); } - | yUNSIGNED yP_TICK '(' expr ')' { $$ = new AstUnsigned($1,$4); } + | ySIGNED yP_TICK '(' expr ')' { $$ = new AstSigned($1, $4); } + | yUNSIGNED yP_TICK '(' expr ')' { $$ = new AstUnsigned($1, $4); } + | ySTRING yP_TICK '(' expr ')' { $$ = new AstCvtPackString($1, $4); } // // Spec only allows primary with addition of a type reference // // We'll be more general, and later assert LHS was a type. | ~l~expr yP_TICK '(' expr ')' { $$ = new AstCastParse($2,$4,$1); } diff --git a/test_regress/t/t_string.v b/test_regress/t/t_string.v index 11bf3ac16..6b8e48e07 100644 --- a/test_regress/t/t_string.v +++ b/test_regress/t/t_string.v @@ -31,6 +31,7 @@ module t (/*AUTOARG*/ initial begin $sformat(vstr, "s=%s", s); `checks(vstr, "s=a"); + `checks(string'(vstr), "s=a"); `checks(s, "a"); `checks({s,s,s}, "aaa"); `checks({4{s}}, "aaaa");