Commit Graph

2070 Commits

Author SHA1 Message Date
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
Lars-Peter Clausen ec75c1aa74 Handle non-blocking event control to lvalue concatenation
A non-blocking event controlled assignment consists of 3 steps.

 * Setup event
 * Perform assignment
 * Clear event

This works fine if the lvalue is a singular value. If the lvalue is a
concatenation multiple assignments are generated and the event is cleared
after each assignment. As a result only the first assignment is event
controlled. All other assignments will be regular non-blocking assignments.

E.g.

```
reg x, y;
event e;
{x,y} <= @e 2'b11;
$display(x, y); // x will be 1'b1, y will be 1'bx
```

To resolve this the event needs to be cleared after all assignments have
been done. This requires changes to both tgt-vvp and the vvp runtime.

tgt-vvp is updated to only insert a single `%evctl/c` instruction for each
event controlled non-blocking assignment.

The vvp runtime is not updated to implicitly clear the event in the
`%assign/vec4/e` instruction and instead rely on the explicit `%evctl/c`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-04 22:27:00 +02:00
Lars-Peter Clausen 07378fd300 vvp: `%{concati,pushi}/vec4` use `get_immediate_rval()` helper
Both the `%concati/vec4` and `%pushi/vec4` instructions need to construct a
vector from the immediate value encoded in the instruction. Currently both
these instructions have a custom implementation for that.

Remove the custom implementations from those functions and use the
`get_immediate_rval()` helper function. This removes a bit of duplicated
code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-02 22:11:46 +02:00
Lars-Peter Clausen 86cc6e6159 vvp: Remove unused `%cmp/ws` and `%cmp/wu` instructions
The `%cmp/ws` and `%cmp/wu` instructions compare two index registers. They
are currently unused. Since the index registers are not used for data there
is not really a need to compare them. Values can be compared before loading
them into an index register.

So remove these two instructions.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-02 21:53:27 +02:00
Lars-Peter Clausen 781089662c vvp: Remove unused `%mov/wu` instruction
The `%mov/wu` instruction moves data from one index register to another.
The instruction is not used. It also does the same as `%ix/mov`. So remove
it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-06-02 21:53:27 +02:00
Lars-Peter Clausen 2032e14f5a vvp: Remove `wid` parameter from `recv_vec{4,8}_pv()`
The `recv_vec{4,8}_pv()` functions are used to implement a partial write to
a vector. As parameters they take both the value and the width of the
value.

All callers of of these functions pass `val.size()` or a variation thereof
as the width of the value. And all implementations that do anything with
the data have an assert that `val.size() == wid`.

Remove the `wid` parameter from these functions and just use `val.size()`
directly where needed. This allows to simplify the interface and also
to remove the asserts.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-28 15:34:02 +02:00
Stephen Williams a1485906ca Add parameters to vcd dumps
Writing parameters into VCD files makes the values available to waveform
tools. This can be done easily enough by writing out a $dumpadd section
at the beginning of the file that sets the parameter values. We don't need
to track the values over change, because by definition they do not change.

This changes the typical vcd output as well, so a few of the regression tests
need to be adjusted to account for this.

Also, while tracking this down, found and fixed the vvp/README.txt documention
for the .param/x records.
2022-05-15 18:47:18 -07:00
Lars-Peter Clausen ca919b3ce0 vvp: Add `%disable/flow` instruction
The `%disable` instruction will stop the execution of all active
threads of a specific scope. This is what is required to implement
the semantics of the Verilog `disable` statement.

But it is not suited to implement the SystemVerilog flow control
statements such as `return`, `continue` and `break`. These only
affect the thread hierarchy from which it is called, but not other
concurrently running threads from the same scope.

Add a new `%disable/flow` instruction that will only disable the thread
closest to the current thread in the thread hierarchy. This can either be
the thread itself or one of its parents. This will leave other concurrent
threads of the same scope untouched and also allows function recursion
since only the closest parent thread is disabled.

Note that it is not possible to implement this using `%jmp` instructions
since a block in a function with variable declarations will be its own
sub-thread, but using flow control instructions it is possible to exit from
that thread to the parent scope, which is not possible with `%jmp`
instructions.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-11 19:22:22 +02:00
Martin Whitaker 673b0d3066 vvp: Only support one path separator in IVERILOG_VPI_MODULE_PATH (issue #608)
Previously both ':' and ';' were recognised as path separators on all
platforms, but ':' can't be used in Windows. So now we only recognise
';' when running in Windows and ':' when running in any other OS.
2022-03-25 22:04:43 +00:00
Martin Whitaker 4c36b2a8a7 vvp: Fix implementation of strndup for Windows (issue #608).
The maximum length to copy, n, does not include the terminating null
character.
2022-03-25 20:34:11 +00:00
Martin Whitaker 3c58ca908d vvp: Fix error message output when a VPI module can't be found. 2022-03-25 20:23:47 +00:00
Martin Whitaker 2bf753fd8f vvp: Accept either \ or / as path separators in the -m option (issue #606).
Windows system calls will accept either of these. This is already done in
the iverilog driver.
2022-03-25 20:14:20 +00:00
Martin Whitaker b3f7ce6020 vvp: ensure array ports are added to the correct context (issue #621)
Array ports are created via a resolve list. We need to detect and
record whether they need to be created in an automatic context at
the point they are declared, not at the time they are created.
2022-03-21 19:57:05 +00:00
Stephen Williams 679a6567e9 Fix string handling of escaped special characters.
String literals may have escaped special characters in them. Make sure
we are processing all the special characters that the standard supports,
and also fix the handling of the assignment to strings. Note that the
vvp input has string literals sanitized so that the parser can handle
the various binary values. desanitize the strings when pushing string
literals into the string stack. This fixes string assignments, and other
string operations.
2022-03-05 18:49:30 -08:00
Stephen Williams de579f2650 Add more types to vvp-stop
Several scope types were not understood by the push command, and
a few types were not displayed reasonably. Flesh these out.
2022-02-26 11:12:50 -08:00
martinwhitaker b86d7c8284
Merge pull request #511 from mmicko/fix_cross
Fix for cross compile build
2021-12-31 09:33:22 +00:00
Cary R c6ef2ba809 Fix valgrind compile to work with new using std reorg 2021-11-10 18:21:14 -08:00
Martin Whitaker 9cc09b8513 Remove "using namespace std" from vvp header files and fix the fallout. 2021-11-04 17:02:07 +00:00
Martin Whitaker 3dda39bce3 Handle run-time out-of-bounds access for wire real arrays (issue #556). 2021-11-03 17:50:45 +00:00
Cary R 31e3155426 Fix fprintf display type 2021-06-17 22:46:24 -07:00
Martin Whitaker 1f8876be1c Fix .event/or connectivity when inputs have multiple fanout (issue #508).
The old implementation connected all inputs to the same vvp_net_t port,
on the basis that we don't care about the data values or what port they
arrived on. But if one or more of the inputs fans out to multiple nets,
the chains get tangled, which either results in connections being lost
or inappropriate connections being made, depending on the order that
the inputs are linked.

This could have been fixed by using a standard wide functor. But as we
don't care about the data values, that would be unnecessary overhead.
We just need separate vvp_net_t objects to handle the input connectivity
and can keep using a single shared functor.
2021-05-18 08:36:04 +01:00
Miodrag Milanovic 1341dee0e6 Fix for cross compile build 2021-05-12 09:16:11 +02:00
Martin Whitaker d2521878d7 Add support for vpiInstance as the type code in calls to vpi_iterate().
This is needed for the waveform dumpers now that vpi_iterate(vpiModule, NULL)
has been ficed to only return modules.

This includes recognising vpiProgram and vpiInterface, although the compiler
and vvp currently incorrectly classify them as modules.
2021-04-21 09:01:50 +01:00
Martin Whitaker 3167b2ed24 Don't return packages when iterating over root modules (issue #496)
The code assumed all handles stored in vpip_root_table were modules. This
is true for traditional Verilog, but not so for SystemVerilog.

Whilst here, also add support for iterating over packages.
2021-04-18 09:47:21 +01:00
Cary R 60a77b08d2 Add compiler and the start of vvp support for ->> 2021-02-19 23:21:51 -08:00
Cary R 956f6ccf4c Update VPI routines to on error signal VVP to return non-zero 2021-01-20 23:50:53 -08:00
Stephen Williams 9b432ba172 Implement vpiSize method for stack string values.
This might come to pass for example when calling the function
$ivl_string_method$len(<expression>) where the expression is
calculated, and not simply a variable name.
2021-01-18 12:39:54 -08:00
Cary R c978d28c09 Update main component Copyright to 2021 2021-01-10 14:32:30 -08:00
Cary R 32787bb973 Add support for SV edge 2021-01-07 01:22:49 -08:00
Cary R 8f908a213d Fix typo 2021-01-06 22:41:43 -08:00
Cary R 4efbfa3e8f Fix a couple more cppcheck warnings 2021-01-06 22:39:16 -08:00
Martin Whitaker aae3a570c2 Fix build with clang. 2021-01-03 10:48:21 +00:00
Cary R 7299625ab5 Cleanup vvp with suggestions from cppcheck 2021-01-02 13:53:18 -08:00
Cary R 1d318c4393 Update cppcheck to not run posix and add some -U flags 2021-01-02 13:23:59 -08:00
Martin Whitaker 51a171a399 Fix warnings about implicit copy assignments. 2021-01-02 14:49:09 +00:00
Cary R 66c5d8cc20 Cleanup cppcheck warnings in vvp 2021-01-01 00:20:26 -08:00
Cary R 82a6e93c56 Update cppcheck waivers 2020-12-31 23:05:12 -08:00
Cary R 0a429dba99 And another compiler warning fix 2020-12-14 20:22:12 -08:00
Cary R 7f2ee99ebd Fix some compiler warnings 2020-12-14 20:06:40 -08:00
Cary R b7b7280794 Merge branch 'master' of github.com:steveicarus/iverilog 2020-12-13 23:02:43 -08:00