Fix missing leading zeros in %0d, bug367
This commit is contained in:
parent
ae4a261463
commit
698aaffb0b
2
Changes
2
Changes
|
|
@ -11,6 +11,8 @@ indicates the contributor was also the author of the fix; Thanks!
|
||||||
|
|
||||||
*** Support $fopen and I/O with integer instead of `verilator_file_descriptor.
|
*** Support $fopen and I/O with integer instead of `verilator_file_descriptor.
|
||||||
|
|
||||||
|
**** Fix $display missing leading zeros in %0d, bug367. [Alex Solomatnikov]
|
||||||
|
|
||||||
**** Use 'vluint64_t' for SystemC instead of (same sized) 'uint64' for MSVC++.
|
**** Use 'vluint64_t' for SystemC instead of (same sized) 'uint64' for MSVC++.
|
||||||
|
|
||||||
* Verilator 3.813 2011/06/28
|
* Verilator 3.813 2011/06/28
|
||||||
|
|
|
||||||
|
|
@ -284,12 +284,14 @@ void _vl_vsformat(string& output, const char* formatp, va_list ap) {
|
||||||
// Note also assumes variables < 64 are not wide, this assumption is
|
// Note also assumes variables < 64 are not wide, this assumption is
|
||||||
// sometimes not true in low-level routines written here in verilated.cpp
|
// sometimes not true in low-level routines written here in verilated.cpp
|
||||||
static VL_THREAD char tmp[VL_VALUE_STRING_MAX_WIDTH];
|
static VL_THREAD char tmp[VL_VALUE_STRING_MAX_WIDTH];
|
||||||
|
const char* pctp = NULL; // Most recent %##.##g format
|
||||||
bool inPct = false;
|
bool inPct = false;
|
||||||
bool widthSet = false;
|
bool widthSet = false;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
const char* pos = formatp;
|
const char* pos = formatp;
|
||||||
for (; *pos; ++pos) {
|
for (; *pos; ++pos) {
|
||||||
if (!inPct && pos[0]=='%') {
|
if (!inPct && pos[0]=='%') {
|
||||||
|
pctp = pos;
|
||||||
inPct = true;
|
inPct = true;
|
||||||
widthSet = false;
|
widthSet = false;
|
||||||
width = 0;
|
width = 0;
|
||||||
|
|
@ -311,6 +313,9 @@ void _vl_vsformat(string& output, const char* formatp, va_list ap) {
|
||||||
widthSet = true;
|
widthSet = true;
|
||||||
width = width*10 + (fmt - '0');
|
width = width*10 + (fmt - '0');
|
||||||
break;
|
break;
|
||||||
|
case '.':
|
||||||
|
inPct = true; // Get more digits
|
||||||
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
output += '%';
|
output += '%';
|
||||||
break;
|
break;
|
||||||
|
|
@ -357,14 +362,26 @@ void _vl_vsformat(string& output, const char* formatp, va_list ap) {
|
||||||
case 'd': { // Signed decimal
|
case 'd': { // Signed decimal
|
||||||
int digits=sprintf(tmp,"%" VL_PRI64 "d",(vlsint64_t)(VL_EXTENDS_QQ(lbits,lbits,ld)));
|
int digits=sprintf(tmp,"%" VL_PRI64 "d",(vlsint64_t)(VL_EXTENDS_QQ(lbits,lbits,ld)));
|
||||||
int needmore = width-digits;
|
int needmore = width-digits;
|
||||||
if (needmore>0) output.append(needmore,' '); // Pre-pad spaces
|
if (needmore>0) {
|
||||||
|
if (pctp && pctp[0] && pctp[1]=='0') { //%0
|
||||||
|
output.append(needmore,'0'); // Pre-pad zero
|
||||||
|
} else {
|
||||||
|
output.append(needmore,' '); // Pre-pad spaces
|
||||||
|
}
|
||||||
|
}
|
||||||
output += tmp;
|
output += tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'u': { // Unsigned decimal
|
case 'u': { // Unsigned decimal
|
||||||
int digits=sprintf(tmp,"%" VL_PRI64 "u",ld);
|
int digits=sprintf(tmp,"%" VL_PRI64 "u",ld);
|
||||||
int needmore = width-digits;
|
int needmore = width-digits;
|
||||||
if (needmore>0) output.append(needmore,' '); // Pre-pad spaces
|
if (needmore>0) {
|
||||||
|
if (pctp && pctp[0] && pctp[1]=='0') { //%0
|
||||||
|
output.append(needmore,'0'); // Pre-pad zero
|
||||||
|
} else {
|
||||||
|
output.append(needmore,' '); // Pre-pad spaces
|
||||||
|
}
|
||||||
|
}
|
||||||
output += tmp;
|
output += tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -472,7 +472,11 @@ string V3Number::displayed(const string& vformat) const {
|
||||||
str = cvtToStr(toUQuad());
|
str = cvtToStr(toUQuad());
|
||||||
}
|
}
|
||||||
int intfmtsize = atoi(fmtsize.c_str());
|
int intfmtsize = atoi(fmtsize.c_str());
|
||||||
while ((int)(str.length()) < intfmtsize) str = " "+str;
|
bool zeropad = fmtsize.length()>0 && fmtsize[0]=='0';
|
||||||
|
while ((int)(str.length()) < intfmtsize) {
|
||||||
|
if (zeropad) str = "0"+str;
|
||||||
|
else str = " "+str;
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ execute (
|
||||||
[0] In top.v.sub2
|
[0] In top.v.sub2
|
||||||
[0] In top.v.sub2.subblock2
|
[0] In top.v.sub2.subblock2
|
||||||
[0] Back \ Quote "
|
[0] Back \ Quote "
|
||||||
[0] %X=0c %D=12 %0X=c %0O=14 %B=001100
|
[0] %X=0c %0X=c %0O=14 %B=001100
|
||||||
[0] %x=0c %d=12 %0x=c %0o=14 %b=001100
|
[0] %x=0c %0x=c %0o=14 %b=001100
|
||||||
|
[0] %D=12 %d=12 %01d=12 %06d=000012 %6d= 12
|
||||||
[0] %x=00abbbbcccc %0x=abbbbcccc %o=00527356746314 %b=00000101010111011101110111100110011001100
|
[0] %x=00abbbbcccc %0x=abbbbcccc %o=00527356746314 %b=00000101010111011101110111100110011001100
|
||||||
[0] %x=00abc1234567812345678 %0x=abc1234567812345678 %o=012570110642547402215053170 %b=000001010101111000001001000110100010101100111100000010010001101000101011001111000
|
[0] %x=00abc1234567812345678 %0x=abc1234567812345678 %o=012570110642547402215053170 %b=000001010101111000001001000110100010101100111100000010010001101000101011001111000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,11 @@ module t;
|
||||||
$display("[%0t] Back \\ Quote \"", $time); // Old bug when \" last on the line.
|
$display("[%0t] Back \\ Quote \"", $time); // Old bug when \" last on the line.
|
||||||
|
|
||||||
// Display formatting
|
// Display formatting
|
||||||
$display("[%0t] %%X=%X %%D=%D %%0X=%0X %%0O=%0O %%B=%B", $time,
|
$display("[%0t] %%X=%X %%0X=%0X %%0O=%0O %%B=%B", $time,
|
||||||
quad[5:0], quad[5:0], quad[5:0], quad[5:0], quad[5:0]);
|
quad[5:0], quad[5:0], quad[5:0], quad[5:0]);
|
||||||
$display("[%0t] %%x=%x %%d=%d %%0x=%0x %%0o=%0o %%b=%b", $time,
|
$display("[%0t] %%x=%x %%0x=%0x %%0o=%0o %%b=%b", $time,
|
||||||
|
quad[5:0], quad[5:0], quad[5:0], quad[5:0]);
|
||||||
|
$display("[%0t] %%D=%D %%d=%d %%01d=%01d %%06d=%06d %%6d=%6d", $time,
|
||||||
quad[5:0], quad[5:0], quad[5:0], quad[5:0], quad[5:0]);
|
quad[5:0], quad[5:0], quad[5:0], quad[5:0], quad[5:0]);
|
||||||
$display("[%0t] %%x=%x %%0x=%0x %%o=%o %%b=%b", $time,
|
$display("[%0t] %%x=%x %%0x=%0x %%o=%o %%b=%b", $time,
|
||||||
quad, quad, quad, quad);
|
quad, quad, quad, quad);
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,9 @@ execute (
|
||||||
[0] In top.v.sub2
|
[0] In top.v.sub2
|
||||||
[0] In top.v.sub2.subblock2
|
[0] In top.v.sub2.subblock2
|
||||||
[0] Back \ Quote "
|
[0] Back \ Quote "
|
||||||
[0] %X=0c %D=12 %0X=c %0O=14 %B=001100
|
[0] %X=0c %0X=c %0O=14 %B=001100
|
||||||
[0] %x=0c %d=12 %0x=c %0o=14 %b=001100
|
[0] %x=0c %0x=c %0o=14 %b=001100
|
||||||
|
[0] %D=12 %d=12 %01d=12 %06d=000012 %6d= 12
|
||||||
[0] %x=00abbbbcccc %0x=abbbbcccc %o=00527356746314 %b=00000101010111011101110111100110011001100
|
[0] %x=00abbbbcccc %0x=abbbbcccc %o=00527356746314 %b=00000101010111011101110111100110011001100
|
||||||
[0] %x=00abc1234567812345678 %0x=abc1234567812345678 %o=012570110642547402215053170 %b=000001010101111000001001000110100010101100111100000010010001101000101011001111000
|
[0] %x=00abc1234567812345678 %0x=abc1234567812345678 %o=012570110642547402215053170 %b=000001010101111000001001000110100010101100111100000010010001101000101011001111000
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue