Commit Graph

10116 Commits

Author SHA1 Message Date
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
Stephen Williams bd9f1b406e
Merge pull request #690 from larsclausen/remove-pform_set_param_from_type
Remove unused function `pform_set_param_from_type()`
2022-04-17 18:37:04 -07:00
Stephen Williams bf521c7eec
Merge pull request #686 from larsclausen/assignment-pattern-expr
Elaborate array assignment pattern values in the right context
2022-04-17 18:36:18 -07:00
Stephen Williams fe4891a77d
Merge pull request #688 from larsclausen/func-return-queue
Allow queues as return types for functions
2022-04-17 18:34:03 -07:00
Lars-Peter Clausen a3c329ae84 Add regression tests for evaluating expression within assignment patterns
Check that expressions within assignment patterns are evaluated as if they
were assigned to a variable with the same type as the base type of the
assignment pattern target.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:58:19 +02:00
Lars-Peter Clausen 5b8fb089bf Elaborate array assignment pattern values in the right context
The expressions within an array assignment pattern should be evaluated in a
context that is equivalent to an assignment to a variable of the element
type of the l-value array.

This is defined in section 10.9.1 ("Array assignment patterns") of the LRM
(1800-2017).

At the moment the values in an assignment pattern are evaluated in a self
determined context, which can lead to incorrect behavior.

Use the existing `elaborate_rval_expr()` function, which is meant for
elaborating assignments, to elaborate the assignment pattern values.

This solves the following issues:
 * implicit width conversion (including sign extension)
 * implicit type conversion (e.g. real to vector)
 * math operators that depend on the target width (e.g. addition)
 * use of expressions that require `test_width()` to be called. (e.g.
   unary operator)
 * use of concatenations
 * use of named constants (e.g. parameters or enums)

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:58:19 +02:00
Lars-Peter Clausen f19ba64614 trash 2022-04-17 09:58:11 +02:00
Lars-Peter Clausen ff8a44b025 Add variant of elaborate_rval_expr() that only takes a data_type_t
The `elaborate_rval_expr()` function takes a `data_type_t`, a
`ivl_variable_type_t` and a `width` parameter. In most places the
ivl_variable_type_t and width are directly derived from the data_type_t.
This slightly simplifies the code.

The only place where this is currently not possible is when assigning to a
compound expression like a concatenation, e.g. `{a,b} = c;`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:58:03 +02:00
Lars-Peter Clausen 52da910313 Move pform_set_reg_idx() into pform_makewire()
`pform_set_reg_idx()` is always called right after `pform_makewire()`. Move
it into the function. This avoids the extra lookup that
`pform_set_reg_idx()` does to get the PWire from the name.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:22:47 +02:00
Lars-Peter Clausen 7aee124cfe pform_makewire(): Remove unused parameters
There are a few parameters for `pform_makewire()` and related functions
that always get passed the same value.

 * port_type is always NetNet::NOT_A_PORT
 * attr is always 0

Remove these parameters.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:22:31 +02:00
Lars-Peter Clausen 393c7a3b49 Add a regression test for functions with queue return type
Check that a queue type is supported for the return type of a function.
Make sure that the queue is not cleared in between invocations for
non-automatic functions.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:14:38 +02:00
Lars-Peter Clausen 27f3fcc5f1 Allow queue types outside of classes
Currently the elaboration function for unpacked array types prints an error
for queues that they are not allowed inside classes. And while this error
gets triggered when declaring a property with a queue type, it also gets
triggered for other places that uses a queue type, e.g. a function return
type. The only exception is signals which uses a different internal code
path when elaborating queue types.

Move the error message, that is class property specific, to the class
property elaboration. This also makes sure that the error messages
references the line where the property is declared and not the line where
the type is declared.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:14:38 +02:00
Lars-Peter Clausen c853025305 Allow implicit cast between dynamic array and queue for all expressions
Dynamic arrays and queues can be implicitly cast between each other. At the
moment this only works if the right hand side is a signal or assignment
pattern.

But this should be possible for other r-value expression that returns a
queue or dynamic array type. E.g. function calls or class properties.

Since the expr_type() method is defined for all NetExpr objects we can use
that and do not have to cast to NetESignal.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:14:38 +02:00
Lars-Peter Clausen bcae0304a3 Set line info on class properties
This will allow to generate error messages that point to the right line if
there is something wrong or not supported in a class property declaration.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:14:38 +02:00
Lars-Peter Clausen dda960dce4 Use default copy-constructor for LineInfo
The LineInfo class defines a copy-constructor, but relies on the default
copy-assignment operator.

In newer versions of C++ this deprecated and modern compilers generate a
warning about this. A class must either use the default copy-constructor
and default copy-assignment operator or provide a user defined version of
both.

Since the current user-defined copy-constructor for LineInfo does the same
as the default copy-constructor, remove the custom one and rely on the
default constructor.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:14:38 +02:00
Lars-Peter Clausen b11da7e16f tgt-vvp: Don't accidentally skip assignment pattern initialization
The `%store/dar/...` and `%store/qdar/...` instructions are used to load a
value into an entry in dynamic array or queue. These instructions will skip
the load if VVP flag 4 is 1.

For assignment pattern initialization these instructions are used to load
the value of the individual assignment pattern expressions into the dynamic
array.

For queues flag 4 is never cleared when generating the code for the
assignment pattern. This means the initialization might be skipped
depending on what value the flag had before.

```
int a = 1;
int q[$];
a = a == 1;
q = {1, 2, 3, 4};
```

For dynamic arrays it is cleared once in the beginning. But each item in
the assignment pattern can be an arbitrary expression.  Evaluating the
expression can cause the flag to get overwritten. E.g. the following code
will skip the assignments.

```
int a = 1;
int d[];
d = {a ? 1 : 1, 2, 3, 4};
```

To fix these issues make sure that the flag is cleared after evaluating
each initialization expression and before executing the `%store/...`
instruction.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:09:38 +02:00
Stephen Williams 72b0498af4
Merge pull request #685 from larsclausen/signed-method
Handle signedness and width expansion for class properties and methods
2022-04-16 19:22:43 -07:00
Stephen Williams e7d4fd6fee
Merge pull request #689 from steveicarus/steveicarus/developer-docs
Document getting started as a developer
2022-04-16 14:17:27 -07:00
Stephen Williams 3166973f59 Document getting started as a developer 2022-04-16 07:58:14 -07:00
Lars-Peter Clausen b2516ead66 Remove unused function `pform_set_param_from_type()`
The `pform_set_param_from_type()` function is not used. The last user was
removed in commit 16646c547c ("Rework parsing of parameter types").

Remove the function itself.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-16 15:28:35 +02:00
Stephen Williams 0dc8596a89 Action to deploy documentation to gh-pages 2022-04-15 20:49:13 -07:00
Lars-Peter Clausen 031fbac5be Add regression tests for signed class properties
Check that the signedness of class properties is handled correctly
  * When sign extending
  * When passing as a value to a system function

Check this for both when accessing the property from within a class method
as well as accessing it on a class object.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-14 12:01:23 +02:00
Lars-Peter Clausen 0c123b8498 Add regression tests for methods with signed return values
Check that the signedness of the return value of methods is handled
correctly.
  * When sign extending
  * When passing as a value to a system function

Check this for both methods on user defined class as well as built-in
methods on SystemVerilog types.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-14 12:01:23 +02:00
Lars-Peter Clausen 3a26bbb59a Handle context signedness and width expansion for class properties
The signedness of an expression can change depending on its context. E.g.
for an arithmetic operation with one unsigned operand all operands are
treated as unsigned.

This is currently not considered when accessing class properties. This can
lead to incorrect behavior with regards to sign extension.

E.g. the following will print 4294967295 rather than 65535.

```
class C;
  shortint x = -1;
endclass
...
C c = new;
$display(c.x + 32'h0);
```

Furthermore the return value is not expanded to the width of its context.
This can cause vvp to crash with an exception when it expects a vector on
the stack to have a certain width. E.g.

```
class C;
  shortint x = -1;
endclass
...
C c = new;
int x;
bit a = 1'b1;
x = a ? c.x : 64'h0;
```

Solve both of this by using `pad_to_width()` on the property expression if
it is a vectorable type. Since any identifier, not just class properties,
need to have this done insert this on the common path and remove the
`pad_to_width()` call on individual paths.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-14 11:55:09 +02:00
Lars-Peter Clausen 22cba1073c Handle context signedness and width expansion for method return types
The signedness of an expression can change depending on its context. E.g.
for an arithmetic operation with one unsigned operand all operands are
treated as unsigned.

For methods, both on built-in SystemVerilog types as well as user defined
classes, this is currently not considered. This can lead to incorrect behavior
if the value is sign extended.

E.g. the following will print 4294967295 rather than 65535.

```
shortint q[$];
q.push_back(-1);
$display(q.pop_front() + 32'h0);
```

Furthermore the return value is not expanded to the width of its context.
This can cause vvp to crash with an exception when it expects a vector on
the stack to have a certain width.

E.g.
```
int d[];
longint x;
bit a = 1'b1;
x = a ? d.size() : 64'h0;
```

Solve both of this by using `pad_to_width()` on the method return value if
it is a vectorable type. Since any function call, not just methods, needs
to have this done to its return value insert this on the common path.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-14 11:55:09 +02:00
Lars-Peter Clausen 2f38adaeff Report correct queue method return type when call without parenthesis
When calling a queue method without parenthesis it gets elaborated through
the PEIdent path. On this path the type, width and signdess are not
reported for the method call. This leads to incorrect behavior in contexts
where those are important.

Correctly report the type, the same as when the method is called with
parenthesis.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-14 10:45:32 +02:00