Commit Graph

9421 Commits

Author SHA1 Message Date
Lars-Peter Clausen 74b433c083 parse.y: Refector enum rule
Refactor the enum rule by adding a enum_base_type rule which handles the
type specific initialization. This allows to keep the non-type specific
parts in a common rule, which makes it easier to modify in future changes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 20:53:55 +01:00
Stephen Williams bedc68707e
Merge pull request #581 from larsclausen/struct-invalid-member
Handle invalid struct members
2022-01-15 11:46:49 -08:00
Lars-Peter Clausen 3e5f9fd044 Add a regression test with invalid struct member declarations
The test checks that all invalid declarations produce an error and also do
not crash the application.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 19:54:13 +01:00
Lars-Peter Clausen 5bfc8a42eb Handle invalid struct members
When something goes wrong when parsing a struct member, e.g. the type does
not exist, a nullptr is added to the struct member list. This will cause a
crash when iterating over the list.

E.g.

```
struct packed {
  logc x;
} s;
```

Add a check so that nullptr members are not added to the list.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 19:46:26 +01:00
Stephen Williams 8b1240f7cf
Merge pull request #582 from steveicarus/bring-in-ivtest
Add ivtest to the iverilog source tree
2022-01-15 10:45:30 -08:00
Stephen Williams cea237b407 Add ivtest to the iverilog source tree
By adding ivtest to the iverilog source tree, it is easier to keep
the regression test synchronized with the source that is being tested.
This should be especially helpful for PRs that add a new feature, and
have a matching ivtest PR with the regression test for that feature.
2022-01-15 10:18:50 -08:00
Stephen Williams 279b2665af
Merge pull request #577 from larsclausen/packed_array
Support signals of packed arrays of packed types
2022-01-14 20:53:30 -08:00
Stephen Williams db72a1d769
Merge pull request #578 from larsclausen/enum_invalid_dimensions
Handle invalid enum dimensions
2022-01-14 20:49:54 -08:00
Lars-Peter Clausen d0223e6ed9 Support signals of packed arrays of packed types
Currently it is only possible to declare packed array variables with a
struct type as the element type.

Add support for packed arrays of other packed types. This includes packed
arrays of enums and vectors as well as packed arrays of packed arrays.

Since packed arrays of packed types are already supported for class members
the infrastructure for elaborating all types of packed arrays exists.
It just needs to be called when elaborating a signal.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-09 20:31:22 +01:00
Lars-Peter Clausen 9ec42b1b8c Check that packed array base-type is packed
When creating a signal of a packed array it is checked that the base-type
of the packed array is a packed type.

But this check is only done if the packed array itself is the type of the
signal. Placing the packed array in a struct or class will elaborate fine,
but then crash during simulation.

E.g.

```
typedef real myreal;
struct packed {
  myreal [1:0] p;
} s;
```

Move the check from signal creation to type elaboration, so that it is not
possible to create a packed type with a non-packed base-type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-09 20:31:21 +01:00
Lars-Peter Clausen 3176611771 netenum_t: Use netrange_t to store range
Use netrange_t, which is meant for storing ranges, for storing the range of
a netenum_t.

This makes the integration with the rest of the codebase a bit more
seamlessly and also allow to reuse methods defined for netrange_t such as
the width() method rather than having to reimplement it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-08 16:26:32 +01:00
Lars-Peter Clausen 90edf48ac6 Handle invalid enum dimensions
Specifying and enum with an invalid dimension range results in an assert or
segfault. E.g. `enum [$] E { ... }`.

Use the `evaluate_ranges()` function to elaborate the enum dimensions. This
functions has proper error checking and recovery built-in.

In addition verify that there is at most one packed dimension.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-08 16:21:45 +01:00
Lars-Peter Clausen ea1bf7577a Allow lsb > msb for enum base type
Having an enum with a lsb > msb base type, e.g. `enum logic [0:9]` is a
legal construct.

It is handled correctly for the most part already, there is just an assert
that triggers on it. Remove that assert.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-08 16:10:25 +01:00
Lars-Peter Clausen adf64f3cc8 Fix base type for nested types with enum or atom2 sub-types
To determine the base type structs and packed arrays call the
figure_packed_base_type() for their sub-types.

This method is not defined for enum or atom2 types and the default
implementation returns IVL_VT_NO_TYPE.

As a result packed arrays of enum or atom2 types and packed structs with
members of enum or atom2 types get elaborated with IVL_VT_NO_TYPE
as the base type.

For example

```
struct packed {
  bit signed [31:0] x;
} s1;
```

gets elaborated with a base type of IVL_VT_BOOL, while

```
struct packed {
  int x;
} s2;
```

gets elaborated with a base type of IVL_VT_NONE.

To fix this define the figure_packed_base_type() for enum_type_t and
atom2_type_t.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-08 15:41:49 +01:00
Lars-Peter Clausen 52925ce9ff Handle invalid packed dimensions
Trying to elaborate a type with invalid packed dimensions currently results
in a crash. E.g. `typedef logic [] T;`

The issue is in the `elaborate_array_ranges()` function which
does not verify that the range specification is valid.

Replace the `elaborate_array_ranges()` with `evaluate_ranges()`, which does
the same thing, but properly checks the range specification and
reports an error if it is invalid.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-08 15:41:49 +01:00
Martin Whitaker f705e7b61c Fix CI on Windows again.
man-db has now been removed from the base-devel group.
2022-01-07 23:33:41 +00:00
martinwhitaker f98e7d1a70
Merge pull request #574 from mmicko/osx_fix
Fix find_ivl_root for OSX
2022-01-06 08:29:32 +00:00
Miodrag Milanovic 57cfbc0cea Fix find_ivl_root for OSX 2022-01-05 09:23:48 +01:00
martinwhitaker b86d7c8284
Merge pull request #511 from mmicko/fix_cross
Fix for cross compile build
2021-12-31 09:33:22 +00:00
martinwhitaker 3481d48d18
Merge pull request #572 from msinger/unique0-token
Fix unique0 keyword/token mapping
2021-12-31 09:20:56 +00:00
martinwhitaker 18cc3b91a1
Merge pull request #573 from larsclausen/short-circuit-logical-operator
Short circuit logical operator
2021-12-31 09:16:35 +00:00
Lars-Peter Clausen 957e3d482f Short circuit logical operator to constant if possible
If the left-hand side of a logical operator is a constant that causes the
right-hand side to be short-circuited the right-hand side can be discarded
even if it is not constant.

In this case replace the expression by a constant.

E.g.
 * `0 && expr` will be replaced by a constant 0.
 * `1 || expr` will be replaced by a constant 1.
 * `0 -> expr` will be replaced by a constant 1.

Note that it is not possible to replace the expression by a constant if
only the right-hand side is a constant, even when the value of the
expression is constant. The left side still has to be evaluated for side
effects.

E.g. it is known at elaboration that `a++ && 0` will yield 0, but the
increment on `a` has to be executed regardless.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2021-12-30 19:05:18 +01:00
Lars-Peter Clausen d4334139d3 tgt-vvp: Short circuit logical operators
Section 11.4.7 of the SystemVerilog LRM states

```
The && and || operators shall use short circuit evaluation as follows:
  - The first operand expression shall always be evaluated.
  - For &&, if the first operand value is logically false then the second operand shall not be evaluated.
  - For ||, if the first operand value is logically true then the second operand shall not be evaluated.
```

vvp currently evaluates both operands of a logical operator. This works
fine as long as the right-hand side does not have a side effect. But if it
has the result might be incorrect.

E.g. for `a && b++` `b` must not be incremented if `a` evaluates to false.

The Verilog LRM mentions that it is allowed to short circuit any expression
"if the final result of an expression can be determined early". But there
is no requirement to do so.

So the new and the old behavior are both correct implementations in
Verilog.

Use the new behavior in both Verilog and SystemVerilog mode to make sure
the behavior is consistent when an expression has side effects.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2021-12-30 18:56:39 +01:00
Martin Whitaker a6e71f30d6 Fix CI on Windows (2nd attempt). 2021-12-30 11:05:11 +00:00
Martin Whitaker 9bcee6c2c8 Fix CI on Windows.
autoconf has been removed from the MSYS2 base-devel group.
2021-12-30 10:33:41 +00:00
Lars-Peter Clausen 2fa7260a4c tgt-vvp: Consolidate vec4 logical `and` and `or` generation
The code for generating the logical `and` and `or` operators is identical
except for the final opcode to combine the two results.

Consolidate this into a single function to reduce the code a bit.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2021-12-29 16:20:22 +01:00
Michael Singer 6c60851558 Fix unique0 keyword/token mapping 2021-12-26 06:47:37 +01:00
Martin Whitaker 668f9850bc Warn when a negative value is assigned to a genvar (-g2001 only) (issue #567) 2021-12-13 21:30:31 +00:00
Martin Whitaker e1d6fd78f4 Fix genvar increment/decrement operations to be signed (issue #568) 2021-12-13 20:45:57 +00:00
Martin Whitaker 67b9374c69 Change compiler's generate loop counter from int to long.
This matches the type of the values assigned to it, and exposes a bug that
was previously only showing up under Windows.
2021-12-13 20:28:41 +00:00
Martin Whitaker 71c36d1289 Improve error message on assignment to an array or array slice (issue #562).
This is valid SystemVerilog, but not something we support yet.
2021-11-12 21:43:24 +00:00
Martin Whitaker 61aed6882c Fix an assertion failure when a variable name is replicated in the same list. 2021-11-11 19:02:40 +00:00
Martin Whitaker 3c23180af3 Remove unreachable code.
pform_get_or_make_wire() should always return a valid pointer. Replace the
existing unreachable code with an assertion.
2021-11-11 19:02:40 +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 dcc9b59f6d Support SV [size] dimension for module and gate instances (issue #553).
Also output a proper error message if multiple dimensions are supplied
instead of failing an assertion.
2021-11-06 00:02:38 +00:00
Martin Whitaker dbf55da0f5 Clean up indentation. 2021-11-05 21:49:51 +00:00
Martin Whitaker 0e3682a127 Remove buggy assertion.
If this assert fires, the "this" pointer we pass to it will be a
null pointer, so will cause a null pointer dereference. We've
tested it is not null earlier, so we don't need the assertion.
2021-11-04 17:07:30 +00: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 23390c1ba3 Remove "using namespace std" from tgt-vhdl header files and fix the fallout. 2021-11-04 17:01:16 +00:00
Martin Whitaker ecbbb60fb6 Remove "using namespace std" from compiler header files and fix the fallout. 2021-11-04 16:55:03 +00:00
Martin Whitaker 19e44d79ec Revert "Reorder header file inclusion to avoid "byte" name collision."
This reverts commit 4c4b09947f.

This didn't completely fix the problem, so try a different tack.
2021-11-04 10:58:49 +00:00
Martin Whitaker 4c4b09947f Reorder header file inclusion to avoid "byte" name collision.
When using the latest mingw64 header files, rpcndr.h (which is indiretly
included by windows.h) defines a type named "byte" which collides with a
definition in cpp_type_traits.h (included indirectly by the STL). This is
only a problem if "using namespace std" is declared prior to including
windows.h.
2021-11-03 18:36:13 +00:00
Martin Whitaker 829d361b17 Fix null pointer warning from latest GCC. 2021-11-03 18:07:15 +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 e3c2234893 Update fstapi.c to the latest from GTKWave 2021-10-26 19:41:29 -07:00
Martin Whitaker ef01dd1e81 Fix signedness of non-ANSI port declarations (issue #540).
For non-ANSI port declarations that have both a port declaration and
a corresponding variable declaration, the signed attribute may be
attached to either the port declaration or the variable declaration,
or both declarations.
2021-09-10 23:09:03 +01:00
Martin Whitaker 7ee7a48310 Check that a genvar is not shadowed when used in a generate loop construct.
This also ensures the same genvar cannot be used in two nested loops
(issue #533), because the implicit localparam with the same name
shadows the genvar declaration.
2021-08-04 14:35:38 +01:00
Martin Whitaker cefcffecda Include named events in checks for name collisions. 2021-08-04 14:14:09 +01:00
Martin Whitaker a17557575d Include typedefs in checks for name collisions.
This requires us to make a copy of the typedefs map when adding it to
a NetScope object, because the pform data is deleted before we are
finished with it.
2021-08-04 14:00:33 +01:00
Martin Whitaker 7445b424f1 Avoid name collisions when naming unnamed generate blocks.
As specified in the IEEE standard, the automatically generated name
must not conflict with any explicitly declared name (not just scope
names).
2021-08-04 12:07:52 +01:00