Fix $display with string without %s, bug1441.

This commit is contained in:
Wilson Snyder 2019-05-16 21:21:38 -04:00
parent d841e68f4f
commit 01725f662f
5 changed files with 25 additions and 8 deletions

View File

@ -14,6 +14,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
**** Fix fault on $realtime with %t, bug1443. [Julien Margetts]
**** Fix $display with string without %s, bug1441. [Denis Rystsov]
**** Fix parameter function string returns, bug1441. [Denis Rystsov]

View File

@ -341,13 +341,13 @@ private:
AstNode *nextp = argp->nextp();
argp->unlinkFrBack(); pushDeletep(argp); VL_DANGLING(argp);
argp = nextp;
} else {
newFormat.append("%h");
argp = argp->nextp();
}
}
}
return newFormat;
} else {
newFormat.append("%?"); // V3Width to figure it out
argp = argp->nextp();
}
}
}
return newFormat;
}
void expectDescriptor(AstNode* nodep, AstNodeVarRef* filep) {

View File

@ -2179,6 +2179,17 @@ private:
if (argp) argp = argp->nextp();
break;
}
case '?': { // Unspecified by user, guess
if (argp && argp->isDouble()) {
ch = 'g';
} else if (argp && argp->isString()) {
ch = '@';
} else {
ch = 'h';
}
if (argp) argp = argp->nextp();
break;
}
default: { // Most operators, just move to next argument
if (argp) argp=argp->nextp();
break;

View File

@ -1,5 +1,7 @@
String: ' 1'
foo(1): ' 1'
s f(1): ' 1'
s parm: ' 1'
s strg: ' 1'
r: 1.234
*-* All Finished *-*

View File

@ -7,14 +7,16 @@ module t;
function automatic string foo(int i);
return $sformatf("'%d'", i); // %0d does not work here
endfunction
real r = 1.234;
string bar = foo(1);
localparam string pbar = foo(1);
initial begin
$write("String: "); $display("' 1'");
//$write("foo(1): "); $display(foo(1));
$write("foo(1): "); $display(foo(1));
$write("s f(1): "); $display("%s", foo(1));
$write("s parm: "); $display("%s", pbar);
$write("s strg: "); $display("%s", bar);
$write("r: "); $display(r);
$write("*-* All Finished *-*\n");
$finish;
end