Commit Graph

9541 Commits

Author SHA1 Message Date
Lars-Peter Clausen 54956f0f29 Be consistent on allowing calling non-void function as task
When calling non-void functions or non-void methods of built-in types  as a
task a warning is issued. But when calling a non-void method of a user
defined class as a task an error is generated.

Be consistent here and generate a warning in both cases.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 11:19:30 -08:00
Stephen Williams 2d6243ea6c
Merge pull request #816 from larsclausen/task-in-expr-fail
Report errors for task and void function calls in expressions
2022-12-17 11:12:39 -08:00
Stephen Williams dd7bea1d5e
Merge pull request #815 from larsclausen/class-virtual-new
Do not allow to create objects of virtual classes
2022-12-17 11:11:30 -08:00
Stephen Williams 70e2ff0bd5
Merge pull request #817 from larsclausen/fix-left-right-c-array
Fix $left/$right for C-style unpacked arrays
2022-12-17 11:09:48 -08:00
Lars-Peter Clausen a8dbb38af2 Add regression test for array query functions on C style array
Check that array query functions return the correct value for C style
arrays.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 09:50:43 -08:00
Lars-Peter Clausen 3c4d1bbe4e Fix $left/$right for C-style unpacked arrays
Unpacked array dimensions that are specified with only a single size value
(C-style unpacked arrays) have a $left of 0 and a $right of size - 1. E.g.
`x[10]` is equivalent to `x[0:9]`. This is defined in the LRM (1800-2017)
section 7.4.2 ("Unpacked arrays").

Currently it is implemented the other way around. There are a few contexts
where this distinction matters. For example array to array assignments,
which are supposed to be done left-to-right.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 09:23:21 -08:00
Lars-Peter Clausen fa4c67ccf7 Add regression tests for tasks and void function calls in expression
Check that an error is reported when either calling a task or a void
function as part of an expression.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-15 21:07:39 -08:00
Lars-Peter Clausen d426e80c73 Fix error reporting when calling task in an expression
Calling a task as part of an expression should report an error. The current
implementation uses `func_def()` and if that returns nullptr will report
the error. But `func_def()` will trigger an assert if the underlying scope
is not a function.

Make sure to first check that the scope is actually a function before
trying to call `func_def()`. If the scope is not a function report an
error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-15 21:07:04 -08:00
Lars-Peter Clausen abc26eeaeb Report error when calling void function in an expression
Unlike normal functions void functions can not be called as part of an
expression. Trying so will currently hit an internal assert.

Make sure an error is reported instead.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-15 20:52:09 -08:00
Lars-Peter Clausen 569ba887b3 Add regression test for creating instances of virtual classes
Check that an error is reported when trying to create an object of a
virtual class.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-13 21:32:45 -08:00
Lars-Peter Clausen e0ec2ed386 Do not allow to create objects of virtual classes
It is not allowed to create objects of virtual classes. Currently the
virtual keyword is accepted by the parser, but otherwise ignored.

Keep track of whether a class is virtual and generate an error when the
class new operator is used for a virtual type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-13 21:27:53 -08:00
Stephen Williams 2a15489e9d
Merge pull request #811 from larsclausen/sv-cast-has-aa
Implement has_aa_term() for cast expressions
2022-12-12 09:12:13 -08:00
Stephen Williams 673193d508
Merge pull request #809 from larsclausen/post-refactor-cleanup
Post type support refactoring cleanup
2022-12-11 21:55:28 -08:00
Lars-Peter Clausen c4397e66f9 Add regression tests for automatic terms in cast expressions
Check that a sign, width or type cast expression that contains an automatic
term is detected as such and can not be used as the left-hand side in a
procedural continuous assignment.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 20:08:33 -08:00
Lars-Peter Clausen c9e7aecf1d Implement `has_aa_term()` for cast expressions
If the base expression of a cast expression has an automatic term then the
cast expression itself has an automatic term.

Make sure this is implemented so that an error is properly reported when
using such an expression in a context where automatic variables are not
allowed.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 20:07:53 -08:00
Lars-Peter Clausen 79771b17b2 Consolidate functions for task port declaration
With the recent refactorings pform_make_task_ports_vec() and
do_make_task_ports() are now very similar.

Consolidate them into a single function.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 17:39:34 -08:00
Lars-Peter Clausen 4e69fe1355 Remove ivl_variable_type_t from PWire
The ivl_variable_type_t in PWire is now only used for passing the base type
for vector types to the elaboration stage. But we can query the base the
from the vector_type_t itself. If the there is no data_type_t set for the
PWire the base type will default to IVL_VT_LOGIC.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 17:08:24 -08:00
Stephen Williams 2bb1489f92
Merge pull request #808 from steveicarus/steveicarus/for-loop-step-opt
Allow for for_step of for loops to be optional
2022-12-11 17:07:31 -08:00
Stephen Williams 15b4a8a046
Merge pull request #806 from larsclausen/class-sig-elab
Elaborate class properties during signal phase instead of scope phase
2022-12-11 16:46:54 -08:00
Stephen Williams 4ead552203
Merge pull request #805 from larsclausen/sv-type-params
Support type parameters
2022-12-11 16:45:39 -08:00
Stephen Williams 0acb938f79 Regression test that optional for_step works
Add the br_gh801b.v regression test.
2022-12-11 16:40:30 -08:00
Stephen Williams 5b9ceee062 Make the for_step of for loops optional
In IEEE Std 1800-2017 A.6.8: the for_step part of the for loop
is optional. If missing, it is assumed that the programmer known
what they are doing.
2022-12-11 16:39:53 -08:00
Stephen Williams bb779112c7
Merge pull request #807 from steveicarus/steveicarus/issue801-empty-for-init
Handle empty for-loop init statement
2022-12-11 16:07:24 -08:00
Stephen Williams afe2cd63ef Regression test for github issue 801 2022-12-11 15:46:23 -08:00
Stephen Williams 78f37f7156 Handle for loops with empty initialization statement
For loops may have empty initialization statements. In that case some things
can't be done, such as loop unrolling or synthesis, but otherwise it is a
valid thing to do. So generate the correct code in this case.
2022-12-11 15:46:16 -08:00
Stephen Williams 1e84e78cd6
Merge pull request #799 from larsclausen/foreach-omit
Allow to omit dimensions in foreach loop
2022-12-11 15:31:49 -08:00
Lars-Peter Clausen fbfb6016c1 Add regression test for using packed scoped type identifier in class
Check that it is possible to use a packed scope type identifier for the
type of a class property when the class is defined in the unit scope. This
makes sure that the elaboration is done in an order so that the type is
available when the class property is elaborated.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 14:10:40 -08:00
Lars-Peter Clausen 68d89bbe05 Add regression test for referencing forward declared classes
Check that it is possible to use a forward declared class type as the type
of a property in another class.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 14:10:40 -08:00
Lars-Peter Clausen b4b591adba Elaborate class properties during signal phase instead of scope phase
Elaborating uses a multi stage approach. Currently non-static class
properties are elaborated during the scope elaboration phase. This can
cause problems if the type of a property is declared in a different scope.
In that case it is possible that the scope in which the type is defined has
not been elaborated yet and the type is not available. E.g.

```
package P;
  typedef int T;
endpackage

class C;
  P::T x;
endclass
```

Another area where this is problematic is when a class has a property of a
another class that has a forward declaration. In this case the type of the
forward declared class, which is created when the scope is elaborated, is
not available when the scope of the class that is using it is elaborated.
E.g.

```
typedef class B;

class A;
  B b;
endclass

class B;
endclass
```

To avoid this elaborate the properties during the signal elaboration phase.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 14:07:53 -08:00
Lars-Peter Clausen 0e86e99358 Add regression tests for omitted foreach dimensions
Check that it is possible to omit one or more dimensions in a foreach loop.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 14:06:30 -08:00
Lars-Peter Clausen e141aef828 Allow to omit dimensions in foreach loop
SystemVerilog allows to skip dimensions in a foreach loop by not specifying
an identifier name for the dimensions. E.g. the following will iterate over
the first and last dimensions, but skip the middle dimension.

```
int x[1][2][3];
foreach(x[a,,b]) ...
```

Add support for this to the parser as well as elaboration.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 13:56:48 -08:00
Lars-Peter Clausen f8401095aa Add regression test for too many foreach loop indices
Check that an error is reported if too many indices are specified
in a foreach loop.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 13:56:48 -08:00
Lars-Peter Clausen eaea5e7939 Print error if foreach loops variables exceed number of array dimensions
Currently when the number of loop variables in a foreach loop is larger
than the number of array dimensions an assertion is triggered.

Turn this into a error message instead for graceful error reporting.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 13:56:48 -08:00
Lars-Peter Clausen aec1ee5a42 Add regression tests for type parameters
Check that all sorts of variations of type parameters are supported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 13:50:27 -08:00
Lars-Peter Clausen 5ef847ea87 Support type parameters
SystemVerilog supports type parameters. These are similar to value
parameters, but they allow to pass a type to a module or similar when
instantiating it.

E.g.

```
module A #(parameter type T = int);
endmodule

module B;
  A #(.T(real)) i_a;
endmodule
```

Add support for handling type parameters.

For the vlog95 and vhdl backends type parameters, similar to typedefs, get
replaced with their actual value. For modules with non-local type
parameters for each module instance a unique module or architecture is
generated with the actual type.

Querying type parameters through VPI is not yet supported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 13:50:14 -08:00
Stephen Williams 3509cc86f8
Merge pull request #804 from larsclausen/swap-elaboration_work_list
Use std::swap() to exchange elaboration_work_list
2022-12-11 13:17:09 -08:00
Stephen Williams 1434936aaa
Merge pull request #802 from larsclausen/forward-typedef
Add support for forward type declarations
2022-12-11 13:16:17 -08:00
Stephen Williams e97b7c4c56
Merge pull request #803 from steveicarus/steveicarus/document-vvp-debugmode
vvp: Document the vvp interactive debug mode
2022-12-11 13:07:39 -08:00
Lars-Peter Clausen bdafdb1e65 Use std::swap() to exchange elaboration_work_list
Rather than moving one item at a time form the elaboration_work_list to the
temporary queue use std::swap to exchange them all at once. This is a bit
more efficient.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 12:38:47 -08:00
Stephen Williams 06c819849f vvp: Document the vvp interactive debug mode
Vvp has an interactive debug mode that few seem to be aware of. Document
that mode.
2022-12-11 12:12:24 -08:00
Lars-Peter Clausen 10e35d1573 Add regression tests for circular type definitions
Check that circular type definitions are detected and an error is
reported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 10:38:08 -08:00
Lars-Peter Clausen 3787eca248 Add regression tests for forward typedefs
Check that all sorts of forward typedefs are supported.
Also check that any recursive use of a type results in an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 10:37:46 -08:00
Lars-Peter Clausen cdc9629ce7 Add support for forward type declarations
SystemVerilog supports forward type declarations. This allows to declare a
type identifier and use it, e.g. in a signal declaration, before declaring
what the actual type is. The type still needs to be fully defined
eventually in the same scope as its forward type declaration. E.g.

```
typedef T;
T x;
typedef int T;
```

The forward type definition can also contain the kind of the type it is
going to be. E.g struct, union, class, etc. The LRM calls this the basic
type. If the actual type is not of the basic type specified in the forward
type declaration this is an error. E.g.

```
typedef struct T;
typedef int T; // Error, int is not a struct
```

It is legal to have more than one forward type declaration for the same
type name, as long as the basic type is the compatible. It is even legal to
have a forward type declaration after the actual type has already been
declared. E.g.

```
typedef T;
typedef int T;
typedef T;
```

Implement support for forward type definitions as part of the new
typedef_t. The basic type will be attached to the typedef_t.

The compatibility of the basic type for multiple forward type declarations
will be checked in the parser. The compatibility of the basic type to the
actual type will be checked during elaboration, once the actual type is
known.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 10:19:59 -08:00
Lars-Peter Clausen 699ceb15a5 Elaborate enum type on demand
Enum types are currently elaborated in lexical declaration order. With forward
typedefs it is possible that a type is referenced before it is declared.

To support this elaborate the enum type on demand when it is used. This is
similar to what is being done for other types.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 10:18:23 -08:00
Lars-Peter Clausen 8ee9d6b5ea Detect circular type definitions
With forward type declarations it is possible to create a circular type
definition where a type resolves to itself. E.g.

```
typedef T1;
typedef T1 T2;
typedef T2 T1;
```

Flag a type as elaborating when elaboration of the type is started and
clear it when elaboration finishes. If the elaboration function is entered
again while the flag is still set a circular type has been detected and an
error is reported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 10:18:23 -08:00
Lars-Peter Clausen 2e0d6d5af1 Allow to attach additional information to typedefs
Currently typedefs are just a pointer to a data_type_t.

Currently typedefs are implemented by setting the name field of a
data_type_t when a typedef of the type is declared. This works mostly, but
there are some corner cases that can't be supported.

E.g. a typedef of a typedef does not work as it overwrites the name field
of the same data_type_t multiple times.

Forward typedefs can also not be supported since forward typedefs allow to
reference a type before it has been declared.

There are also some problems with type identifier references from a
higher-level scope if there is a type identifier in the current scope with
the same name, but it is declared after the type identifier has been
referenced. E.g. in the following x should be a vector fo width 8, but it
will be a vector of width 4, because while the right type is used it is
elaborated in the wrong scope.

```
localparam A = 8;
typedef logic [A-1:0] T;
module M;
  localparam A = 4;
  T x;
  typedef int T;
endmodule
```

Furthermore typedefs used for the type of ports are elaborated in the wrong
scope.

To handle these corner case issues introduce a data_type_t for typedefs.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 10:18:22 -08:00
Stephen Williams 3bea115c51
Merge pull request #798 from larsclausen/genvar-compressed
Support compressed assignment statements for genvar loops
2022-12-04 19:45:50 -08:00
Stephen Williams fdc7b0e1bd
Merge pull request #796 from jrrk2/isnan_patch
Explicitly refer to std::isnan to avoid clash with system standard library
2022-12-04 19:43:32 -08:00
Lars-Peter Clausen 9553a872da Add regression test for compressed assignment statement in genvar loops
Check that compressed assignment statements are supported for genvar loops.
This is supported in SystemVerilog, but not in Verilog.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-04 14:37:21 -08:00
Lars-Peter Clausen 410c8207ef Support compressed assignment statements for genvar loops
SystemVerilog supports using compressed assignment operators for the genvar
for loop variable update.

Add support for this in a similar way as increment/decrement operators by
transforming the statement to its uncompressed equivalent. E.g. `x += y`
gets transformed to `x = x + y`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-04 14:37:21 -08:00