Skip to content

Commit

Permalink
vvp: Only ignore leading null-bytes when reading as string through VPI
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
larsclausen committed Jan 2, 2023
1 parent b8ddeb8 commit 3cfbd73
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vvp/vpi_priv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 3cfbd73

Please sign in to comment.