Support , bug977.

This commit is contained in:
Wilson Snyder 2015-10-03 07:12:56 -04:00
parent c60ffd7fd9
commit f1874b211f
5 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,8 @@ indicates the contributor was also the author of the fix; Thanks!
** Add --vpi flag, and fix VPI linkage, bug969. [Arthur Kahlich]
** Support $sformatf, bug977. [Johan Bjork]
**** Add VerilatedScopeNameMap for introspection, bug966. [Todd Strader]
**** Fix very long module names, bug937. [Todd Strader]

View File

@ -2208,11 +2208,13 @@ class AstSFormatF : public AstNode {
public:
AstSFormatF(FileLine* fl, const string& text, bool hidden, AstNode* exprsp)
: AstNode(fl), m_text(text), m_hidden(hidden) {
dtypeSetString();
addNOp1p(exprsp); addNOp2p(NULL); }
ASTNODE_NODE_FUNCS(SFormatF, SFORMATF)
virtual string name() const { return m_text; }
virtual int instrCount() const { return instrCountPli(); }
virtual V3Hash sameHash() const { return V3Hash(text()); }
virtual bool hasDType() const { return true; }
virtual bool same(AstNode* samep) const { return text()==samep->castSFormatF()->text(); }
virtual string verilogKwd() const { return "$sformatf"; }
void exprsp(AstNode* nodep) { addOp1p(nodep); } // op1 = Expressions to output

View File

@ -221,6 +221,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5}
"$setup" { FL; return yaTIMINGSPEC; }
"$setuphold" { FL; return yaTIMINGSPEC; }
"$sformat" { FL; return yD_SFORMAT; }
"$sformatf" { FL; return yD_SFORMATF; }
"$skew" { FL; return yaTIMINGSPEC; }
"$sqrt" { FL; return yD_SQRT; }
"$sscanf" { FL; return yD_SSCANF; }

View File

@ -474,6 +474,7 @@ class AstSenTree;
%token<fl> yD_RIGHT "$right"
%token<fl> yD_RTOI "$rtoi"
%token<fl> yD_SFORMAT "$sformat"
%token<fl> yD_SFORMATF "$sformatf"
%token<fl> yD_SIGNED "$signed"
%token<fl> yD_SIZE "$size"
%token<fl> yD_SQRT "$sqrt"
@ -2655,7 +2656,7 @@ system_f_call<nodep>: // IEEE: system_tf_call (as func)
| yD_RIGHT '(' expr ')' { $$ = new AstAttrOf($1,AstAttrType::DIM_RIGHT,$3,NULL); }
| yD_RIGHT '(' expr ',' expr ')' { $$ = new AstAttrOf($1,AstAttrType::DIM_RIGHT,$3,$5); }
| yD_RTOI '(' expr ')' { $$ = new AstRToIS($1,$3); }
//| yD_SFORMATF '(' str commaEListE ')' { $$ = new AstSFormatF($1,*$3,false,$4); } // Have AST, just need testing and debug
| yD_SFORMATF '(' str commaEListE ')' { $$ = new AstSFormatF($1,*$3,false,$4); }
| yD_SIGNED '(' expr ')' { $$ = new AstSigned($1,$3); }
| yD_SIZE '(' expr ')' { $$ = new AstAttrOf($1,AstAttrType::DIM_SIZE,$3,NULL); }
| yD_SIZE '(' expr ',' expr ')' { $$ = new AstAttrOf($1,AstAttrType::DIM_SIZE,$3,$5); }

View File

@ -16,6 +16,8 @@ module t;
reg [8:1] char;
reg [48*8:1] str;
reg [48*8:1] str2;
string str3;
real r;
@ -32,6 +34,10 @@ module t;
`ifdef TEST_VERBOSE $display("str2=%0s",str2); `endif
if (str2 !== "n=1100 q= 2623536935500120647 w=hello-there12345") $stop;
str3 = $sformatf("n=%b q=%d w=%s", n, q, wide);
`ifdef TEST_VERBOSE $display("str3=%0s",str3); `endif
if (str3 !== "n=1100 q= 2623536935500120647 w=hello-there12345") $stop;
$swrite(str2, "e=%e", r);
$swrite(str2, "e=%f", r);
$swrite(str2, "e=%g", r);