forked from github/verilator
handle constant format field widths (#3946)
This commit is contained in:
parent
b778784333
commit
4eb280601e
@ -1084,12 +1084,19 @@ private:
|
||||
const string format = nodep->text();
|
||||
auto pos = format.cbegin();
|
||||
bool inPct = false;
|
||||
string width;
|
||||
for (; pos != format.cend(); ++pos) {
|
||||
if (!inPct && pos[0] == '%') {
|
||||
inPct = true;
|
||||
width = "";
|
||||
} else if (!inPct) { // Normal text
|
||||
result += *pos;
|
||||
} else { // Format character
|
||||
if (std::isdigit(pos[0])) {
|
||||
width += pos[0];
|
||||
continue;
|
||||
}
|
||||
|
||||
inPct = false;
|
||||
|
||||
if (V3Number::displayedFmtLegal(tolower(pos[0]), false)) {
|
||||
@ -1101,7 +1108,7 @@ private:
|
||||
nodep, "Argument for $display like statement is not constant");
|
||||
break;
|
||||
}
|
||||
const string pformat = std::string{"%"} + pos[0];
|
||||
const string pformat = std::string{"%"} + width + pos[0];
|
||||
result += constp->num().displayed(nodep, pformat);
|
||||
} else {
|
||||
switch (tolower(pos[0])) {
|
||||
|
@ -8,12 +8,15 @@ module t ();
|
||||
|
||||
function automatic string foo_func();
|
||||
foo_func = "FOO";
|
||||
foo_func = $sformatf("%sBAR", foo_func);
|
||||
for (int i = 0; i < 4; i++)
|
||||
foo_func = $sformatf("%s%0d", foo_func, i);
|
||||
endfunction
|
||||
|
||||
localparam string the_foo = foo_func();
|
||||
|
||||
initial begin
|
||||
if (the_foo != "FOO") $stop;
|
||||
if (the_foo != "FOOBAR0123") $stop;
|
||||
$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user