Commit Graph

2109 Commits

Author SHA1 Message Date
Marlon James d4aef1e6d8 Fix vpi_handle_by_name() handling of escaped identifiers when finding a toplevel module
find_scope() requires the hierarchical path to use escaped identifiers;
without the leading '\' and trailing ' ', if there are any '.' characters,
the path will be broken up at the wrong point(s).
2023-11-06 15:48:31 -08:00
DeflateAwning 95217830b4 Update URL http://iverilog.icarus.com/ -> https://steveicarus.github.io/iverilog/ 2023-10-15 19:29:40 -06:00
Lars-Peter Clausen 52a8b31ac3 vvp: Add parser rule for unsigned 2-state net arrays
vvp is missing a parser rule for unsigned 2-state net arrays. E.g.

```
  bit a[0:1];
  assign a[0] = 1'b0;
```

will synthesize fine, but when running it with vvp cause a syntax error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-10-15 10:03:10 -07:00
Lars-Peter Clausen 0eb01fff1e vvp: Fix initial value propagation for 2-state non-automatic arrays
For 2-state non-automatic arrays currently real 0.0 value is propagated as
the initial value. This will cause an assert at the downstream receivers
which expect a vector.

Make sure that the vector value 0 is propagated instead for 2-state
vectors.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-09-23 05:40:13 -07:00
mole99 d7c6d7ce76 Fix memory leak and add vpi_release_handle() 2023-09-04 15:20:31 +02:00
mole99 d70ad015f2 Cleanup 2023-09-04 14:07:48 +02:00
mole99 b8ae6b1686 Fix port bit index 2023-09-04 11:31:35 +02:00
mole99 f9d658caeb Add more debug information 2023-09-04 09:20:19 +02:00
mole99 a1440ced86 Add support for annotation of input and output vectors 2023-09-04 09:20:19 +02:00
Cary R f229dfcb2b Fix the trigger for user functions with no args 2023-09-03 18:41:38 -07:00
Cary R 64cfd681af
Merge pull request #980 from sifferman/argumentless-functions-fix
Argumentless functions fix
2023-09-03 17:31:10 -07:00
mole99 11c944f5e9 Cleanup 2023-08-29 09:54:39 +02:00
mole99 db068aa137 Correctly dump the delayed signal for output ports 2023-08-23 12:56:11 +02:00
mole99 423f88cce9 Fix annotation for special cases 2023-08-23 12:56:11 +02:00
mole99 6d3e2bf344 Improve SDF interconnect support, add -ginterconnect flag 2023-08-23 12:56:11 +02:00
mole99 adb40e7572 Annotate simple designs 2023-08-23 12:56:10 +02:00
mole99 7beadb92f8 Framework of the INTERCONNECT implementation 2023-08-23 12:56:10 +02:00
Cary R 77f7609b67 Fix formatting of link routine 2023-08-22 20:41:30 -07:00
Cary R 70243b8163
Merge pull request #989 from mole99/fix-modpaths
Always evaluate `vvp_fun_modpath_src` first
2023-08-22 19:41:03 -07:00
Mason Loyet dc1038c877 Fix Typo in vvp's scope search in interactive mode.
When vvp parses a command which it thinks is a system call it tries to
match the symbols to values in the scope. The typo uses the wrong index
variable to access the vpi table. This results in a failed dynamic cast
which goes unchecked until the value is dereferenced, resulting in a
segfault.
2023-08-17 05:44:31 +00:00
mole99 5a87d2fa38 Keep the order of other nodes 2023-08-15 10:18:12 +02:00
mole99 bd2b67961e Connect nodes with vvp_fun_modpath_src always to head of list 2023-08-14 15:37:53 +02:00
Lars-Peter Clausen 0dfbcbdf47 vvp: Initialize automatic 2-state vectors to 0
Automatic 2-state vectors currently get initialized to 'hx, while their
default value should be 0.

Make sure the vector is initialized to 0 at the beginning of the automatic
context.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-07-29 06:17:47 -07:00
Ethan Sifferman eb104a727e initial commit 2023-07-28 22:22:15 -07:00
Cary R ee14cb0eb0 Update displayed Copyright dates 2023-06-10 20:33:08 -07:00
Cary R bff91566ab
Merge pull request #930 from larsclausen/fix-fn-partial-oob-write
Fix incorrect assert for partial oob write to function return value
2023-06-10 18:00:06 -07:00
mole99 b0c1eab51e Move textfiles to documentation 2023-06-09 13:30:44 +02:00
Cary R 13166092da
Merge pull request #919 from larsclausen/fix-real-format-arm
Fix formatting real to binary and hex strings on ARM
2023-06-04 21:10:49 -07:00
Lars-Peter Clausen 925f5fb608 Fix incorrect assert for partial oob write to function return value
Partial out-of-bounds write to a function's return value will trigger an
assert, even though the operation is valid.

The assert checks that the truncated value has the expected width, but
instead it should check that the non-truncated value has the expected with.

Move the assert before the truncation to fix this.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-06-04 16:04:16 -07:00
Lars-Peter Clausen abe1099335 Fix formatting real to binary and hex strings on ARM
Directly casting a negative double to a unsigned integer type is undefined
behavior and has different results on x86 and ARM based platforms.

On x86 the behavior is similar to casting a signed int to an unsigned
integer, i.e. the sign bit will end up in the MSB. But on ARM the result
will be 0.

To get consistent behavior, first cast to signed integer and then cast the
signed integer value to an unsigned integer value.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-05-08 09:16:00 -07:00
Lars-Peter Clausen df30eda3a3 vvp: Handle %fork in `final` procedures
In the current implementation a `%fork` instruction in a final block will
get scheduled, but never executed.

And while SystemVerilog requires a `final` procedure to execute in 0 time
and so no SystemVerilog `fork` is allowed inside of it, there are some
other scenarios where iverilog generates `%fork` statements.

For example when declaring variables in a sub-block a sub-scope with its
own thread is is used to allocate the storage for those variables and
`%fork` is used to execute the child thread.

E.g. the following, while being valid SystemVerilog, will never execute the
loop because the generated code will implement the loop as a child thread
being executed by a `%fork` statement.
```
  final for (int i = 0; i < 10; i++) $display(i);
```

To mitigate this treat final statements the same as functions and rather
than scheduling a child thread, execute it immediately when using the
`%fork` statement.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-04-16 09:20:31 -07:00
Stephen Williams 08f2c88fcf
Merge pull request #852 from larsclausen/vvp-string-vpi
vvp: Handle null-bytes in a conistent way when reading through VPI
2023-01-06 20:21:03 -08:00
Lars-Peter Clausen 3cfbd7345f 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>
2023-01-02 15:36:02 -08:00
Lars-Peter Clausen b8ddeb8848 vvp: Handle null-bytes in the string literal VPI support
The VPI API for string literals does not correctly handle the case where a
null-byte ('\0') appears in the string literal. It uses strlen() to
calculate the length of the literal, which will give the wrong result if
there is a null-byte in the string literal. Instead of using strlen() use
the stored length to fix this.

In addition when formatting a string literal as a string ignore any
null-bytes. The LRM is not entirely clear what should happen to null-bytes
when formatting a value as a string. But the behavior of ignoring the
null-bytes is consistent with the rules of SystemVerilog for converting a
string literal to a SV string.

This problem can occur when a string literal gets null-byte left-padded due
to width of its context of its expression, but then optimization removes
part of the expression and only leaves the padded string literal.

E.g.
```
$display(0 ? "Yes" : "No");
```

will be transformed into

```
$display("\000No");
```

There is also one subtle change in behavior associated with this. The empty
string ("") is supposed to be equivalent to 8'h00. So e.g.
`$display(":%s:", "")` should print ": :" since the width of the empty
string is 1 byte and the %s modifier prints a string with the width of the
value, left-padding with spaces if necessary. The current implementation
will print "::" though. This change requires to update the marco_with_args
gold file.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 15:35:34 -08:00
Lars-Peter Clausen 4ddf234c32 vvp: Remove null-bytes when converting string literals to SV strings
The `%pushi/str` and `%concati/str` instructions should remove null-bytes
from the string literal when converting it to a string. This is defined in
section 6.16 ("String data type") of the LRM (1800-2017).

This is already handled correctly when converting a vector from the stack
to a SV string, just not when converting a string literal to SV string.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 13:19:40 -08:00
Cary R dc8b7d0184 Cleanup some cppcheck warnings 2022-12-28 00:00:31 -08:00
Stephen Williams 43c85529af devel: Fix ci build vvp test
The vvp test expects a proper version stamp in the examples/hello.vvp file.
2022-12-26 17:16:26 -05:00
Stephen Williams 03f912dc55 Clean up warnings
Clean up warnings that show up on newer compilers. Many of these warnings
are related to obsolete c library features or language features. This does
not clear up warnings in code generated by bison or flex.
2022-12-18 10:18:10 -05:00
Jonathan Kimmitt fc2d9372ef Explicitly refer to std::isnan to avoid clash with system standard library 2022-12-02 16:10:36 +00:00
Lars-Peter Clausen 567df9c29a vvp: Handle copying of empty dynamic array and queue
An empty dynamic array or queue is represented by a null object in vvp.

Currently when trying to copy such an object results in undefined behavior
in various places. Either hitting an assert or causing a nullptr
dereference.

Make sure that the empty object is handled correctly by treating it as a
special case.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-09-19 18:47:18 +02:00
Lars-Peter Clausen 5e8eb5e67d vvp: Remove unused `compile_varw_real()`
The only user was removed in commit 6cac1d2cab ("Add support for
real/realtime arrays.").

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-20 22:59:12 +02:00
Lars-Peter Clausen 608c18699e vvp: Remove unused `vvp_fun_signal_{real,string}::size()`
Both the `vvp_fun_signal_real` and `vvp_fun_signal_string` classes
implement a `size()` method that returns 1. There are no users of these
methods, remove them.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-20 22:59:12 +02:00
Lars-Peter Clausen 1603df47d0 vvp: Remove `{send,recv,filter}_long()`
The last user was removed in 682ab886d8 ("Implement release and deassign
more directly.").

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-20 22:59:03 +02:00
Lars-Peter Clausen c286d1c418 vvp: Remove unused function prototypes
Remove prototypes of functions that have already been removed.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-20 22:52:56 +02:00
Lars-Peter Clausen 2346cc8b69 vvp: Implement partial writes to 2-state arrays
Writes to 2-state arrays currently only support full writes. If the write
is a partial write it will trigger an assert. E.g.

```
int a[3:0]
int i = -1;
a[i+:8] = 8'h0; // Triggers assert
```

Add support for partial writes by doing a read-modify-write in the same way
as for 4-state arrays.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-12 16:14:30 +02:00
Lars-Peter Clausen 9a50956f5e vvp: Handle (partial) out-of-bounds writes for `%store/vec4a`
The `%store/vec4a` instruction does not handle partial of full
out-of-bounds writes to a vector array element. Trying to do so will
trigger an assert. E.g.

```
integer a[3:0];
integer i = -10;
a[0][i+:8] = 8'h0; // Triggers assert
```

For fully out-of-bounds writes the write should be skipped, for partial
out-of-bounds writes the value needs to be resized to be within the bounds
of the vector. Use the `resize_rval_vec()` helper function to implement
this.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-12 16:14:30 +02:00
Lars-Peter Clausen ce9f3d5e59 vvp: Add helper function for vector (partial) out-of-bounds write
There are a few functions that handle implement different kinds of vector
writes that have to handle that the assigned value partially or completely
out-of-bounds.

Each function has similar, but not identical, code for this, sometimes with
small bugs for corner cases.

Add a helper function that takes care of handling of updating the width and
offset of the assigned value if necessary.

This ensure consistent and correct behavior and allow to remove some
duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-12 16:14:30 +02:00
Lars-Peter Clausen eab37efb56 vvp: Handle fully out-of-bounds write for `%assign/vec4/a/{d,e}`
The `%assign/vec4/a/{d,e}` instructions, when checking for a full
out-of-bounds write on the low side, uses the target signal width, while it
should use the assigned value width.

This can lead to a fully out-of-bounds write to be assumed to be a partial
out-of-bounds access, which will trigger an assert later on.

E.g.

```
integer a[1:0];
integer i = -4;
a[0][i+:4] <= 4'h0; // Triggers assert
```

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-08 06:51:04 +02:00
Stephen Williams e5abd4bf82
Merge pull request #727 from larsclausen/nb-ec-concat
Handle non-blocking event control to lvalue concatenation
2022-06-05 17:31:14 -07:00
Stephen Williams 68f75dce61
Merge pull request #726 from larsclausen/vvp-remove-unused-instructions
vvp: Remove unused index word instructions
2022-06-05 17:29:38 -07:00