Commit Graph

9541 Commits

Author SHA1 Message Date
Stephen Williams 9898bffd41
Merge pull request #590 from larsclausen/packed-type-cast
Add support for explicit cast to packed array, packed struct and enum
2022-01-17 12:27:11 -08:00
Lars-Peter Clausen 5fc1976496 Add regression test for explicit cast to packed array and packed struct
These test verify that explicit cast to packed array and packed struct
types are supported and executed correctly.

The tests are based on the test for integer casts. Just the type of the
variables was changed to packed array and packed struct respectively.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-17 20:21:29 +01:00
Lars-Peter Clausen 1858c6a313 Set regression test for explicit enum cast to supported
Update the enum cast test to reflect that enum casts are now supported.

Also add a small check to verify that the right value got assigned to the
enum after the cast.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-17 20:21:28 +01:00
Lars-Peter Clausen 053453c645 Add support for explicit cast to enum
Assigning a value to an enum signal that is not of the same type as the
enum requires an explicit cast.

To support this attach the type of a type cast to the resulting expression.
This allows the assignment elaboration to confirm that value has been
explicitly cast to the right type.

Also handle the case where the value is a constant. In this case create a
NetEConstEnum instead of a NetEConst as the resulting expression.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-17 20:21:28 +01:00
Lars-Peter Clausen 9b7c99b8a8 NetEConstEnum: Remove unused scope_ field
The scope_ field of the NetEConstEnum class is initialized in the
constructor, but never used anywhere again. Remove it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-17 20:21:28 +01:00
Lars-Peter Clausen 25dae60bb6 Add support for explicit cast to packed struct and packed array
Currently explicit cast is supported to atom2 and vector types. packed
struct, packed array and enum are not supported.

An explicit cast to packed type works the same for all packed types though.

Add support for handling also packed structs, packed arrays and enums by
make the code more generic and querying the packed base type from the
ivl_type_t.

To correctly handle enums a bit more work is necessary, which will be done
in a follow up patch.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-17 20:21:28 +01:00
Stephen Williams be06e293f6
Merge pull request #587 from steveicarus/ivtests-fail-exit
Rework the regression tests to not use regression_report references
2022-01-16 13:36:09 -08:00
Stephen Williams 7c73ef8fb6 ivtest: Mark as NI tests that are known to fail.
Mark them as NI so that in the fugure they might be turned back
on if they can be made to work. Keep the tests around as reference.

Also, remove reports that are no longer tested in CI. This is because
they are no longer tested by a previous patch that relies on the
change vvp_reg.pl behavior around failed tests.

Remove now obsolete update_msys2_report.pl, and simplify the test.sh
script, since diff commands and Windows specific trickery are no
longer needed.
2022-01-16 13:17:46 -08:00
Stephen Williams d0b9c11d35 ivtest: vvp_reg.pl sets exit status
If there are any failures, return a non-zero exit status so that
invoking scripts can detect that failures happen. This eliminates
the need to use regression report reference outputs, and should
make it easier to merge PRs that add or impact tests.
2022-01-16 11:03:21 -08:00
Stephen Williams f5f07d52b0
Merge pull request #586 from larsclausen/struct-signed
Add  support for signed packed structs/unions
2022-01-16 10:37:44 -08:00
Lars-Peter Clausen e176ce0776 Add regression test for signed struct
Add a test that checks that signing annotations on structs are supported
and that signed structs are properly evaluated as a signed value.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-16 16:16:33 +01:00
Lars-Peter Clausen 09ac7c207e Add support for signed packed structs/unions
packed structs and packed unions as a whole can either be signed or
unsigned. This information is used when it is used as a primary in an
expression, i.e. without accessing any of the members.

Add support for parsing and elaborating signed structs.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-16 16:16:24 +01:00
Stephen Williams f1c543194c
Merge pull request #585 from larsclausen/packed-array-direct-struct-enum
Support direct packed arrays of struct and enums and packed arrays of scoped types
2022-01-15 18:51:11 -08:00
Lars-Peter Clausen 38c4c20cbc Add test for packed arrays of types from other scopes
Extend the array_packed test to check declaring a packed array of a type
from another scope that is addressed via a scoped identifier.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 22:26:29 +01:00
Lars-Peter Clausen c670170ac0 Add test for direct packed arrays of struct and enums
It is possible to directly declare a packed array of a struct or enum
without having to create a typedef first.

Add a check to the array_packed test that this is supported and works as
expected.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 22:26:29 +01:00
Lars-Peter Clausen 3ca1c129ce Allow packed arrays of scoped types identifiers
Allow scoped identifiers to be used as the base type for packed array
types. Scoped type identifiers can be used the same way as unscoped type
identifiers.

E.g.
```
package p;
  typedef logic [1:0] vector;
endpackage

module test;
  p::vector [1:0] pa;
endmodule
```

is a valid construct.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 22:26:29 +01:00
Lars-Peter Clausen ae954e5df7 Support direct packed arrays of structs and enums
It is possible to directly declare a packed array of a struct or enum,
without having to typedef the struct or enum first. E.g.

```
struct packed {
  int x;
} [1:0] pa;
```

Add support to the parser for handling this.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 22:26:29 +01:00
Stephen Williams 6222a84d67
Merge pull request #584 from larsclausen/enum-put-in-scope
Put enum type into scope when declaring it
2022-01-15 13:21:50 -08:00
Lars-Peter Clausen d856a35e4d Add regression test for enums declared in structs and classes
These tests check that a enum that is declared in a struct or class are
correctly elaborated and also name collisions with the enum names are
detected.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 21:43:01 +01:00
Lars-Peter Clausen 9e6f651e09 Put enum type into scope when declaring it
When creating an enum type it must be added to the scope where it is
declared so it can later be elaborated and the enum and its names can be
referenced in expressions.

In addition the names of the enum must be added to the lexor scope so that
name collisions are detected and can be reported as errors.

This is done with pform_put_enum_type_in_scope() function.

At the moment the function is called from two different places
 * When adding a typedef of a enum type
 * When creating a signal of a enum type

In addition the enum_type_t is added to a class scope `enum_sets` when
declaring a enum property in a class. But this only makes sure that the
enum gets elaborated, its names are not added to the lexor scope.

This works fine for the most part, but breaks for a few corner cases.

E.g. it is possible to declare a enum type as part of the subtype of
another packed type such as structs or packed arrays. E.g.

```
struct packed {
  enum {
    A
  } e;
} s;
```

This is not covered by either of the cases above and neither do the names
of the enum get added to the lexor scope, nor is the enum type elaborated.

Another corner case that is currently not working is declaring a class
property where the type is a typedef of a enum that is declared outside of
the class. In this case the enum is elaborated again inside the class
scope. E.g. the below is supposed to work, but fails with an already
declared symbol error.

```
typedef enum {
  A
} e_t;

class C;
  typedef enum {
    A
  } e1;
  e_t e2;
endclass
```

In addition since for enums declared in classes they are only added to
`enum_sets`, but names are not added to the lexor scope, it is possible to
declare a different symbol in the class scope with the same name.

E.g. the following elaborates fine

```
class C;
  enum {
    A
  } e;
  typedef int A;
endclass
```

To fix this call pform_put_enum_type_in_scope() when the enum_type_t is
created in the parser. This makes sure that it is handled the same
regardless where the type is declared or used.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-01-15 21:24:23 +01:00
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