vvp: Only ignore leading null-bytes when reading as string through VPI

Currently when reading a number literal through the VPI API as a
vpiStringVal all null-bytes in the literal get ignored. This behavior is
different from when reading a signal through the VPI API as a vpiStringVal.
The latter will only ignore leading null-bytes and replace other null-bytes
with a space. E.g. the following two will print different values.

```
$display("%s", "a\000b"); // -> " ab"
reg [23:0] x = "a\000b";
$display("%s", x); // -> "a b"
```

For consistency modify the number literal formatting code so that it has
the same behavior as the signal value formatting code and only replaces
leading null-bytes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-01-02 15:33:51 -08:00
parent b8ddeb8848
commit 3cfbd7345f
1 changed files with 7 additions and 0 deletions

View File

@ -635,6 +635,8 @@ static void vec4_get_value_string(const vvp_vector4_t&word_val, unsigned width,
if (char_val != 0)
*cp++ = char_val;
else if (cp != rbuf)
*cp++ = ' ';
}
for (unsigned idx = 0 ; idx < nchar ; idx += 1) {
@ -645,8 +647,13 @@ static void vec4_get_value_string(const vvp_vector4_t&word_val, unsigned width,
if (val == BIT4_1)
char_val |= 1 << bdx;
}
// Ignore leading null-bytes and replace other null-bytes with space.
// The LRM is not entirely clear on how null bytes should be handled.
// This is the implementation chosen for iverilog.
if (char_val != 0)
*cp++ = char_val;
else if (cp != rbuf)
*cp++ = ' ';
}
*cp = 0;