Support old-style (), bug467.

This commit is contained in:
Wilson Snyder
2017-01-09 19:19:21 -05:00
parent 2f34132275
commit f942aba855
7 changed files with 42 additions and 7 deletions
+15 -1
View File
@@ -2324,9 +2324,15 @@ class AstSFormatF : public AstNode {
// Also used as "real" function for /*verilator sformat*/ functions
string m_text;
bool m_hidden; // Under display, etc
bool m_hasFormat; // Has format code
public:
class NoFormat {};
AstSFormatF(FileLine* fl, const string& text, bool hidden, AstNode* exprsp)
: AstNode(fl), m_text(text), m_hidden(hidden) {
: AstNode(fl), m_text(text), m_hidden(hidden), m_hasFormat(true) {
dtypeSetString();
addNOp1p(exprsp); addNOp2p(NULL); }
AstSFormatF(FileLine* fl, NoFormat, AstNode* exprsp)
: AstNode(fl), m_text(""), m_hidden(true), m_hasFormat(false) {
dtypeSetString();
addNOp1p(exprsp); addNOp2p(NULL); }
ASTNODE_NODE_FUNCS(SFormatF)
@@ -2345,6 +2351,8 @@ public:
bool formatScopeTracking() const { // Track scopeNamep(); Ok if false positive
return (name().find("%m") != string::npos || name().find("%M") != string::npos); }
bool hidden() const { return m_hidden; }
void hasFormat(bool flag) { m_hasFormat=flag; }
bool hasFormat() const { return m_hasFormat; }
};
class AstDisplay : public AstNodeStmt {
@@ -2360,6 +2368,12 @@ public:
setNOp3p(filep);
m_displayType = dispType;
}
AstDisplay(FileLine* fileline, AstDisplayType dispType, AstNode* filep, AstNode* exprsp)
: AstNodeStmt (fileline) {
setOp1p(new AstSFormatF(fileline, AstSFormatF::NoFormat(), exprsp));
setNOp3p(filep);
m_displayType = dispType;
}
ASTNODE_NODE_FUNCS(Display)
virtual void dump(ostream& str);
virtual const char* broken() const { BROKEN_RTN(!fmtp()); return NULL; }
+11
View File
@@ -377,6 +377,17 @@ private:
}
virtual void visit(AstSFormatF* nodep) {
nodep->iterateChildren(*this);
// Cleanup old-school displays without format arguments
if (!nodep->hasFormat()) {
if (nodep->text()!="") nodep->v3fatalSrc("Non-format $sformatf should have \"\" format");
if (nodep->exprsp()->castConst()
&& nodep->exprsp()->castConst()->num().isFromString()) {
AstConst* fmtp = nodep->exprsp()->unlinkFrBack()->castConst();
nodep->text(fmtp->num().toString());
pushDeletep(fmtp); VL_DANGLING(fmtp);
}
nodep->hasFormat(true);
}
string newFormat = expectFormat(nodep, nodep->text(), nodep->exprsp(), false);
nodep->text(newFormat);
if ((nodep->backp()->castDisplay() && nodep->backp()->castDisplay()->displayType().needScopeTracking())
+11 -6
View File
@@ -2629,13 +2629,13 @@ system_t_call<nodep>: // IEEE: system_tf_call (as task)
| yD_SWRITE '(' expr ',' str commaEListE ')' { $$ = new AstSFormat($1,$3,*$5,$6); }
| yD_SYSTEM '(' expr ')' { $$ = new AstSystemT($1,$3); }
//
| yD_DISPLAY parenE { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,"", NULL,NULL); }
| yD_DISPLAY '(' str commaEListE ')' { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,*$3,NULL,$4); }
| yD_DISPLAY parenE { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,NULL,NULL); }
| yD_DISPLAY '(' exprList ')' { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,NULL,$3); }
| yD_WRITE parenE { $$ = NULL; } // NOP
| yD_WRITE '(' str commaEListE ')' { $$ = new AstDisplay($1,AstDisplayType::DT_WRITE, *$3,NULL,$4); }
| yD_FDISPLAY '(' expr ')' { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,"",$3,NULL); }
| yD_FDISPLAY '(' expr ',' str commaEListE ')' { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,*$5,$3,$6); }
| yD_FWRITE '(' expr ',' str commaEListE ')' { $$ = new AstDisplay($1,AstDisplayType::DT_WRITE, *$5,$3,$6); }
| yD_WRITE '(' exprList ')' { $$ = new AstDisplay($1,AstDisplayType::DT_WRITE, NULL,$3); }
| yD_FDISPLAY '(' expr ')' { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,$3,NULL); }
| yD_FDISPLAY '(' expr ',' exprListE ')' { $$ = new AstDisplay($1,AstDisplayType::DT_DISPLAY,$3,$5); }
| yD_FWRITE '(' expr ',' exprListE ')' { $$ = new AstDisplay($1,AstDisplayType::DT_WRITE, $3,$5); }
| yD_INFO parenE { $$ = new AstDisplay($1,AstDisplayType::DT_INFO, "", NULL,NULL); }
| yD_INFO '(' str commaEListE ')' { $$ = new AstDisplay($1,AstDisplayType::DT_INFO, *$3,NULL,$4); }
| yD_WARNING parenE { $$ = new AstDisplay($1,AstDisplayType::DT_WARNING,"", NULL,NULL); }
@@ -3162,6 +3162,11 @@ cateList<nodep>:
| cateList ',' stream_expression { $$ = new AstConcat($2,$1,$3); }
;
exprListE<nodep>:
/* empty */ { $$ = NULL; }
| exprList { $$ = $1; }
;
exprList<nodep>:
expr { $$ = $1; }
| exprList ',' expr { $$ = $1;$1->addNext($3); }