Commit Graph

9541 Commits

Author SHA1 Message Date
Stephen Williams e8bc3bf8dd
Merge pull request #719 from steveicarus/steveicarus/issue717-vcd-real-parameters
Fix vcd dump of real value parameters
2022-05-21 11:35:17 -07:00
Stephen Williams 6564f55219 Fix vcd dump of real value parameters
Parameters with real values are possible in Verilog, but not in the VCD
format, so lie a little and call them "real" objects. Otherwise, we can
treat them like constants and it works out, at least for gtkwave.
2022-05-21 10:13:27 -07:00
Stephen Williams 6176f8eec3
Merge pull request #715 from larsclausen/vvp-load-store-skip
tgt-vvp: Fix incorrect load or store operation skip
2022-05-21 09:17:38 -07:00
Stephen Williams 5d97405724
Merge pull request #714 from steveicarus/steveicarus/issue156-vcd-dump-parameter
Add parameters to vcd dumps
2022-05-17 08:37:21 -07:00
Stephen Williams 73f40f73b0 Add parameters to fst dumps
Add support for parameters (constants) in fst dumps. And while we are at
it, factor out some of the declarations shared with sys_vcd.
2022-05-16 20:47:32 -07:00
Lars-Peter Clausen c2c758369d Add regression tests for accidental store/load skip
Check that for the following operations the load or store is not skipped
after a operation that sets vvp flag 4.

 * Assignment to immediate indexed real array entry
 * Assignment operator on immediate indexed vector array entry
 * Assignment operator on dynamic vector part select

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-16 11:36:20 +02:00
Lars-Peter Clausen e263d5b268 tgt-vvp: Fix store skip for assignment operator on dynamic part select
The operator assignment on dynamic part selects uses the `%store/vec4`
instruction to store the value. This instruction will skip the assignment
if flag 4 is set. This is for handling the case where the index is
undefined.

Since the left hand side of the assignment is an arbitrary expression it
can change the flag. The implementation handles this by making a copy of
the flag and restoring it before executing the `%store/vec4` instruction.

The flag is set by the `%ix/vec4` instruction when loading the index
register. But the copy of the flag is made before that and just picks
up the flag that was stored by previous expressions. This can cause
the store to be skipped when it shouldn't.

E.g. in the following code the increment will be skipped. Flag 4 is used
from the `a == 0` comparison, rather than from computing the part select
index.

```
int a = 0;
if (a == 0) begin
  a[a+:2] += 1;
end
$display(a); // Will print 0, should print 1
```

Fix this by moving the copy of the flag after the `%ix/vec4` instruction.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-16 10:18:27 +02:00
Lars-Peter Clausen 2abfef68ff tgt-vvp: Fix load skip for assignment operator to array entry
The vvp `%load/vec4a` instruction will skip the load if vvp flag 4 is set
and return 'x. This is meant for handling the case where the index is
undefined.

For assignment operators on array entries, when the index is an immediate
value, vvp flag 4 is not cleared before the load instruction. If a previous
instruction set flag 4 it load yield 'x.

E.g. for the following sequence `x[0]` should be `11`, but will be `'x`.

```
integer x[10];
logic a = 1'b0;
x[0] = 10;
if (a == 0) begin
  x[0] += 1;
end
```

Properly clear the flag before the load instruction to handle this
correctly.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-16 10:18:27 +02:00
Lars-Peter Clausen b83ebf3c8e tgt-vvp: Fix store skip on real typed array entries
When assigning a value to a real typed array entry the vvp `%store/reala`
instruction. This instruction will skip the store if the vvp flag 4 is set.
This is to handle the case where the index is undefined.

When the index into the array is an immediate value the flag 4 is not
cleared. If a previous instruction set flag 4 the store will be skipped.

E.g. for the following r[0] will remain 0.0 since the assignment to it is
skipped.

```
integer a = 0;
real r[1:0];
if (a == 0) begin
  r[0] = 1.23;
end
```

Fix this by using the `draw_eval_expr_into_integer()` helper function to
evaluate the index into a word register. The function correctly handles all
the special cases.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-16 10:18:27 +02:00
Stephen Williams 4c8903f117
Merge pull request #713 from larsclausen/remove-svector
Replace svector with std::vector
2022-05-15 18:59:09 -07:00
Stephen Williams e4372c8eda
Merge pull request #712 from larsclausen/fix-darray-oob
Return value of correct width for dynamic array out-of-bound access
2022-05-15 18:57:49 -07: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 b83daa3ae3 Add regression tests for dynamic array and queue out-of-bounds access
Check that out-of-bounds access on a dynamic array or queue works and
returns the correct value.

  * 2-state vectors: '0 with the element width
  * 4-state vectors: 'x with the element width
  * reals: 0.0
  * strings: ""

Note that the 2-state test currently still fails as out-of-bounds access on
a 2-state vector incorrectly returns 'x.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-15 21:58:01 +02:00
Lars-Peter Clausen abc3ad95e6 Return value of correct width for dynamic array out-of-bound access
Commit e1870acfac ("Return the correct value when a queue or darray
references an undefined element") added support for specifying the width of
the vector elements stored in a queue or dynamic array, so that an
out-of-bounds access can create a word with the right width.

To get the element width of a queue or dynamic array it uses the
`packed_width()` method. But this method is only implemented for
`netqueue_t` and returns always 1 for dynamic arrays. As a result
out-of-bounds access on a dynamic array will push a vector of the wrong
width onto the stack if the vector element is wider than 1 bit. This will
usually trigger an assert in vvp.

Fix this by moving the `packed_width()` method implementation from
`netqueue_t` to its base class `netdarray_t` so that it works for all types
of dynamic arrays.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-15 21:57:51 +02:00
Lars-Peter Clausen e15b125da8 Replace svector with std::vector
The custom `svector` class is essentially a subset of `std::vector`. There
is no inherent advantage to using `svector`. Both have the same memory
footprint.

`svector` was designed to be of static size, but there are a few places in
the parser where it has to grow at runtime. Handling this becomes a bit
easier by switching to `std::vector` since it is possible to use its
methods which take care of resizing the vector.

This also allows to remove the unused parameter of the `lgate` struct
constructor, which was only needed for compatibility with `svector`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-15 21:56:48 +02:00
Lars-Peter Clausen 278e071b35 netqueue_t: Remove redundant get_signed() method
The get_signed() method for the netqueue_t class is identical to that of
its base class netdarray_t.

Remove the redundant re-implementation of the method.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-14 13:42:59 +02:00
Stephen Williams e67a796a77
Merge pull request #709 from larsclausen/remove-draw-bool
tgt-vvp: Remove unused draw_eval_bool64()
2022-05-12 14:49:42 -07:00
Stephen Williams e076400449
Merge pull request #708 from larsclausen/real-array-multi-dim
tgt-vvp: Allow multi-dimensional real arrays
2022-05-12 14:48:15 -07:00
Stephen Williams 508564b79f
Merge pull request #706 from larsclausen/parameter-scalar
Handle scalar typed parameters
2022-05-12 14:46:31 -07:00
Lars-Peter Clausen 5a616bcaf4 tgt-vvp: Remove unused draw_eval_bool64()
Ever since the conversion to use a stack for vectors `draw_eval_bool64()`
has been unused. The last caller of `draw_eval_bool64()` was removed in
commit e4b862f3d1 ("Clean up vector handling dead code.").

Remove `draw_eval_bool64()` and related functions as well.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-04 11:45:46 +02:00
Lars-Peter Clausen 37392383b5 Add regression test for scalar and 1-bit parameters
Check that scalar typed parameters are handled correctly. Make sure the
width of the parameter only depends on the type and not on the value
assigned to the parameter.

Same for parameters with a 1-bit range specification.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-02 14:33:31 +02:00
Lars-Peter Clausen 37f9cde49f Handle scalar typed parameters
Parameters without any type or range specification inherit the type from
the value that has been assigned to it. Similarly a parameter with just an
`signed` or `unsigned` keyword will inherit its range from the value
assigned to it.

In the current implementation any vector type parameter that does not have
a range specification inherits the type form the assigned value. That
includes parameters with an explicit scalar vector type. E.g.

```
parameter bit X = 10
```

Make sure that a parameter only uses the width from the assigned value if
the parameter does not have an explicit data type.

To support this we need to remember whether a `netvector_t` was declared as
an explicit or implicit data type. Currently this information is only
available on the unelaborated `vector_type_t`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-02 14:33:31 +02:00
Lars-Peter Clausen ef009e7200 Add regression test for multi-dimensional real array
Check that multi-dimensional real arrays are supported and can be accessed.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-02 14:30:29 +02:00
Lars-Peter Clausen 1eb22b7e14 tgt-vvp: Allow multi-dimensional real arrays
There is currently a restriction in the vvp code generator backend that
throws an assertion when generating wire access for a multi-dimensional
real array.

But there is nothing special about multi-dimensional arrays. In vvp arrays
are in canonical form. Meaning they only have a single dimension and the
conversion form multi to single dimension is done in the higher layers.

Remove the assert to allow multi-dimensional real arrays.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-02 14:29:15 +02:00
Stephen Williams 0a86773c5e
Merge pull request #705 from larsclausen/class_new_fix
Handle class new assignment to non-class variables
2022-05-01 07:36:10 -07:00
Stephen Williams 64cc04f6d8
Merge pull request #701 from larsclausen/lgate-lineinfo
lgate: Inherit from LineInfo
2022-05-01 07:34:45 -07:00
Lars-Peter Clausen 58ac6ed1f8 Add regression tests for invalid class new
Check that using a class new operator on a variable that is not of a class
type results in an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-30 21:13:59 +02:00
Lars-Peter Clausen eeed05d9cd Handle class new assignment to non-class variables
Using a class new operator on a non-class variable should result in an
error. At the moment when using a class new operator on a dynamic array or
queue will result in an segmentation fault. This is because the
implementation assumes that the left hand side is of a class type.

Add a check in the class new operator implementation that the type of the
left hand side is a class. Report an error if it is not.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-30 21:13:55 +02:00
Lars-Peter Clausen dddc41891e lgate: Inherit from LineInfo
The lgate struct has its own fields for tracking file and line number,
while everything else that has this information attached inherits from the
LineInfo class.

Make lgate also inherit from LineInfo for consistency.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-24 17:00:46 +02:00
Stephen Williams e7b700f48e
Merge pull request #700 from steveicarus/steveicarus/gh_pr699-fix-segfault
Fix issue 699: segfault when rvalue to elaboration fails.
2022-04-23 19:24:13 -07:00
Stephen Williams 7e67b8b11b Add br_gh699 regression test. 2022-04-23 18:52:35 -07:00
Stephen Williams dc203a20ba Handle the error case that the rval fails
There are some cases where the r-value for an assignment just can't
be elaborated. Instead of segfaulting on the error, handle it by
assuming that the nullptr came from an error message, and ignore it
going forward.
2022-04-23 18:52:15 -07:00
Stephen Williams 4679c722e3
Merge pull request #698 from larsclausen/type-cast-elaborated
PECastType: Use elaborated data type
2022-04-23 17:33:40 -07:00
Stephen Williams 3a3f7fc623
Merge pull request #697 from larsclausen/module-port-shortreal
Allow shortreal module ports
2022-04-23 17:31:03 -07:00
Stephen Williams 5d316c1fd9
Merge pull request #695 from steveicarus/steveicarus/document-gtkwave
Document using gtkwave with Icarus Verilog
2022-04-23 17:29:30 -07:00
Lars-Peter Clausen da21c62f29 Add regression tests for type casts with type identifiers
Check that type casts using type identifiers works as expected.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-22 09:06:31 +02:00
Lars-Peter Clausen 227cf20684 PECastType: Use elaborated data type
PECastType currently uses the unelaborated data type to make the decision
how to implement the cast. The unelaborated data type is provided by the
parser and this works as long as the parser knows the data type.

But for example with type parameters the actual data type is not known
until elaboration. In preparation for supporting type parameters make sure
to only use the elaborated type in the PECastType implementation.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-22 09:06:08 +02:00
Lars-Peter Clausen 9d37878aa7 Add regression test for shortreal module ports
Check that module ports can have the shortreal data type.

Note that SystemVerilog does not allow nets to be of shortreal type.
Supporting net ports with a shortreal type is a Icarus extension.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-21 10:18:12 +02:00
Lars-Peter Clausen 854422a3eb Allow `shortreal` module ports
Currently there is a restriction in the parser that rejects `shortreal`
typed module ports. And while at the moment `shortreal` signals are
implemented as `real` typed signals, which is not standard compliant, there
is nothing special about module ports in this regard.

Note that support for `shortreal` (and `real`) nets is an Icarus extension,
but ports can also be variables, in which case a shortreal port is allowed
by the LRM.

`shortreal` variables and nets are allowed everywhere else. There is no
good reason to not allow them for module ports, so remove the restriction.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-21 10:17:50 +02:00
Stephen Williams bd94c72472 Document using gtkwave with Icarus Verilog
Recover the Icarus Verilog documentation for using GTKWave. It needs a bit
of rework, and formatting.
2022-04-18 20:01:59 -07:00
Stephen Williams 5da2951c12
Merge pull request #694 from larsclausen/parser-avoid-signal-lookup
Avoid signal look-up by name in the parser
2022-04-18 16:33:19 -07:00
Stephen Williams bdf581edd0
Merge pull request #693 from larsclausen/consolidate-array-elab
Consolidate unpacked array type elaboration
2022-04-18 16:31:48 -07:00
Lars-Peter Clausen d4e862dc4e pform_attach_discipline(): Avoid signal look-up by name
The `pform_attach_discipline()` function creates a signal using
`pform_makewire()` and then looks it up by name.

`pform_makewire()` now returns the signal, so use that directly and skip
the look-up by name.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-18 12:07:19 +02:00
Lars-Peter Clausen 254e9dc094 pform_set_data_type(): Avoid signal look-up by name
The `pform_set_data_type()` function is used to set the data type as well
as attributes on a list of signals. Currently the signals are passed as a
list of signal names and then the function looks up the actual signals from
the names.

Refactor the code to directly pass a list of signals. This will allow to
skip the look-up by name.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-18 12:07:16 +02:00
Lars-Peter Clausen 135c664adf pform_set_net_range(): Avoid signal look-up by name
The `pform_set_net_range()` function currently looks up a signal by name.
But in all places where it is called the reference to the signal is already
available.

Refactor the code to pass the signal itself, rather than the signal name, to
`pform_set_net_range()`. This allows to skip the look-up by name.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-18 11:19:52 +02:00
Lars-Peter Clausen e815d37c25 pform_make_var_init(): Remove unnecessary signal look-up by name
`pform_make_var_init()` calls `pform_get_wire_in_scope()` but never uses
the result other than checking that the signal exists. But we already know
that the signal exists since we only call `pform_make_var_init()` for a freshly
created signal.

Remove the unnecessary signal look-up by name.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-18 11:19:11 +02:00
Lars-Peter Clausen 818dfa55f3 Add regression tests for nested dynamic arrays and queues
SystemVerilog allows to declare signals of nested unpacked types. E.g. a
queue of dynamic arrays.

This is currently not supported by Icarus. Add regression test nevertheless
to check that this is reported as a non-supported construct and does not
result in random crashes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-18 09:58:02 +02:00
Lars-Peter Clausen f42ab248a4 Add regression test for functions with bounded queue return type
Check that the maximum size of a bounded queue is properly handled when
being used as the return type for a function.

Elements beyond the maximum size should be ignored.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-18 09:58:02 +02:00
Lars-Peter Clausen 724d7d4282 Consolidate unpacked array type elaboration
There are currently two implementations for elaborating unpacked array
types. One that is used when elaborating a signal with an unpacked array
type and one that is used everywhere else using the elaborate_type()
infrastructure.

The elaborate_type() implementation is less complete and for example does
not support bounded queue types.

Consolidate both into a single implementation to reduce duplicated code and
get consistent behavior. This for example makes sure that the maximum queue
size is respected when used as a function return type.

Nested data structures of arrays, dynamic arrays or queues are not yet
supported. In the current implementation when encountering such a type an
assert will be triggered and the application crashes. In the new
implementation an error message will be printed without crashing the
application.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-18 09:58:02 +02:00
Stephen Williams 66a5cfe660
Merge pull request #691 from larsclausen/cleanup-pform-makewire
Small cleanups for `pform_makewire()`
2022-04-17 18:38:15 -07:00