Commit Graph

9421 Commits

Author SHA1 Message Date
Lars-Peter Clausen ad9f5a3aa6 Add parser helper rule for optional task port list
There are a few places in the grammar where it is possible to specify a
task/function port list in parenthesis or nothing. E.g. task and function
prototypes. Factor this out into a common rule to be able to remove some
duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-28 10:11:37 +02:00
Lars-Peter Clausen 1a95dafc8d Add regression tests array base type elaboration scope
Check that for typedefs of array, dynamic array and queue types the base
type is elaborated in the right scope. There are separate tests for vector
base type and other base types since these take different paths internally.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-28 09:17:24 +02:00
Lars-Peter Clausen c96a6bfa09 Elaborate base type of array types in the right scope
The base type of an array type needs to be elaborated in the scope where
the array type is declared. At the moment it is elaborated in the scope
where the signal is declared, which can cause incorrect results.

E.g. in the example below the width of the array base type would be 4
instead of 8.

```
localparam A = 8;
typedef reg [A-1:0] T[1:0];

module test;
  localparam A = 4;
  T x;
endmodule
```

If an unpacked array type is specified use the scope of the array type as
the default scope for the base type. Note that the base type can still be a
typedef in a different scope than the array scope, but we need to start
searching for it in the array scope.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-28 09:14:28 +02:00
Stephen Williams d480c4d7d0
Merge pull request #659 from larsclausen/typedef-overwrite
Support typedef overwrites with unpacked dimensions and in classes
2022-03-27 15:49:55 -07:00
Stephen Williams 658d4f5eee
Merge pull request #658 from larsclausen/class-in-module
Handle multiple instances of modules with class definitions
2022-03-27 15:48:56 -07:00
Stephen Williams 4f971ea4f9
Merge pull request #657 from larsclausen/enum-base-type
Support type identifier base type for enum
2022-03-27 15:47:34 -07:00
Martin Whitaker 7dcde37475 Fix iverilog-vpi on Windows to handle more than one source file (issue #602)
Use the string containing the current source file path to derive the
object file name, not the string containing the space-separated list
of source files.

(thanks to DavidC-75 for pointing out the error)
2022-03-26 18:13:18 +00:00
Martin Whitaker 8a19380a5d Add multi-file VPI test. 2022-03-26 16:44:57 +00:00
Martin Whitaker 673b0d3066 vvp: Only support one path separator in IVERILOG_VPI_MODULE_PATH (issue #608)
Previously both ':' and ';' were recognised as path separators on all
platforms, but ':' can't be used in Windows. So now we only recognise
';' when running in Windows and ':' when running in any other OS.
2022-03-25 22:04:43 +00:00
Lars-Peter Clausen 315bc1908a Add regression tests for enum base type
Check that the behavior for all sorts of base types for enums is correctly
implemented. Both for valid as well as invalid base types.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-25 21:55:34 +01:00
Lars-Peter Clausen 4bf0d62cd1 Support type identifier base type for enum
The base type for an enum type can be a type identifier for a typedef as
long as it resolves to a vector or integer type with at most one packed
dimension. This is described in section 6.19 ("Enumerations") of the LRM
(1800-2017). E.g.

```
typedef bit [3:0] T;
enum T {
 A
} e;
```

Add support for this by allowing to specify a type identifier as the base
type for an enum in the parser. During elaboration it is checked whether
the type identifier resolves to a valid enum base type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-25 21:55:34 +01:00
Martin Whitaker 4c36b2a8a7 vvp: Fix implementation of strndup for Windows (issue #608).
The maximum length to copy, n, does not include the terminating null
character.
2022-03-25 20:34:11 +00:00
Martin Whitaker 3c58ca908d vvp: Fix error message output when a VPI module can't be found. 2022-03-25 20:23:47 +00:00
Martin Whitaker 2bf753fd8f vvp: Accept either \ or / as path separators in the -m option (issue #606).
Windows system calls will accept either of these. This is already done in
the iverilog driver.
2022-03-25 20:14:20 +00:00
Lars-Peter Clausen 252174d15a Add additional regression tests for typedef overwrites
Check that it is possible to create a typedef of an array type that shadows
an existing typedef in a higher level scope.

Also check that it is possible to create a typedef in a class scope that
shadows an exiting typedef in a higher level scope.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-23 10:53:56 +01:00
Lars-Peter Clausen b30d3fc8d7 Support typedef overwrites in class scopes
It is possible to declare a new typedef that shadows an existing typedef in
a higher level scope. E.g.

```
typedef int T;
class C;
  typedef real T;
endclass
```

In the current implementation this works for scopes that are not class
scopes.

Update the parser to also support this in class scopes by re-using the
existing parser rule that is used for the other scopes.

Reusing the existing rule also adds support for class forward typedes
inside classes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-23 10:53:56 +01:00
Lars-Peter Clausen 23e1143ad6 Support unpacked dimensions on typedef overwrites
It is possible to declare a new typedef that shadows an existing typedef in
a higher level scope. E.g.

```
typedef int T;
module M;
  typedef real T;
endmodule
```

In the current implementation this only works as long as the new type is
a not an array type.

Update the parser to allow to specify unpacked dimension when overwriting
a typedef from a different scope.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-23 10:53:56 +01:00
Cary R 86a7707482 Update vlog95 regress for some recent test changes 2022-03-23 00:07:30 -07:00
Cary R af7c3043d8 Update to the latest from GTKWave 2022-03-22 23:32:25 -07:00
Lars-Peter Clausen abe5e692ce Add regression test for classes defined in modules
Check that it is possible to have multiple instances of a module
that declares a class and that the class in each module instance
is a unique type that can have dependencies on module parameters.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-22 11:53:47 +01:00
Lars-Peter Clausen eed38bd14a Handle multiple instances of modules with class definitions
For classes declared inside a module each module instance creates a new
unique class type. These types are not compatible to each other. This is
necessary since module parameters can change the class implementation.
This is defined in section 6.22 ("Type compatibility") of the LRM (1800-2017).

In the current implementation when a class is elaborated the elaborated
type is stored in the class_type_t so it is possible to look up the
elaborated class type. But this class_type_t is shared among elaborated
class types. As a result when creating multiple instances of a module with
a class definition an internal assert is triggered.

To support multiple module instances with class definitions instead of
storing the elaborated type in the type definition look up the type in the
scope in which the type definition is references.

This is similar to how the same problem is solved for enum types.

For packages we still need to remember the elaborated type otherwise scoped
class type references wont work. Since there is only one instance of a
package this doesn't have the same problem as classes in modules.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-22 11:53:47 +01:00
Lars-Peter Clausen 583a7ddc35 netclass: Make pointer to base class const
The base class type is not owned by a class and is shared. For this reason
it must not be modified. To ensure this mark the base class pointer as
const.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-22 11:42:54 +01:00
Martin Whitaker b3f7ce6020 vvp: ensure array ports are added to the correct context (issue #621)
Array ports are created via a resolve list. We need to detect and
record whether they need to be created in an automatic context at
the point they are declared, not at the time they are created.
2022-03-21 19:57:05 +00:00
Martin Whitaker 2c505f0040 Add regression test for issue #621. 2022-03-21 19:55:15 +00:00
Stephen Williams fc80465b87
Merge pull request #656 from larsclausen/enum-compatibility
Restrict enum compatibility to the same scope
2022-03-20 19:13:56 -07:00
Stephen Williams f73af99ce7
Merge pull request #655 from larsclausen/fix-udp-output-reg
parser: Fix UDP registered output syntax
2022-03-20 19:12:34 -07:00
Stephen Williams 1de38dde12
Merge pull request #651 from larsclausen/consolidate-pform-set-datatype
Consolidate most pform_set_<type>_data_type() functions
2022-03-20 19:11:49 -07:00
Stephen Williams af09d86113
Merge pull request #647 from larsclausen/non-ansi-ports
Allow to declare direction after data type for non-ANSI ports
2022-03-20 19:10:49 -07:00
Lars-Peter Clausen 83da384df3 Add regression test for enum compatibility across module boundaries
Check that the compatibility of signals of enum data type across module
boundaries.

If the enum data type is declared at a higher level scope or imported from
a package the signals are compatible between different module instances. If
the enum data type is declared within the module itself though the signals
are not compatible.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-19 17:17:21 +01:00
Lars-Peter Clausen fabff5ef5f Restrict enum compatibility to the same scope
An enum data type declared in a module is not compatible between different
instances of the module. The type is unique in each hierarchical instance
scope. The type can for example depend on module parameters which would
result in conflicting definitions. This is defined in section 6.22 ("Type
compatibility") of the LRM (1800-2017).

At the moment enum compatibility is checked by comparing the enum_type_t.
But the enum_type_t is shared among the netenum_t that are created for each
module instance and gives the wrong result.

Since there is exactly one netenum_t created for each enum and each
instantiated scope use this to check if the data type of two enum type
signals is compatible.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-19 17:17:21 +01:00
Martin Whitaker b7f948193a Report correct net name in synthesis "sorry" message (issue #649). 2022-03-19 12:17:44 +00:00
Lars-Peter Clausen c5e160f1dd Add regression test for `output reg` syntax for UDPs
Check that it is possible to declare a registered output of a user defined
primitive using the `output reg` syntax.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-19 13:00:04 +01:00
Lars-Peter Clausen aaffceff42 parser: Fix UDP registered output syntax
The parser currently expects `reg output` for UDP registered output. But
the correct syntax is `output reg`. Fix this to accept the correct syntax.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-19 12:59:20 +01:00
Martin Whitaker e53b2e774b Further fixes for vvp code generation for c. assign of an array word.
The draw_net_input() function can write additional statements to the output
file, so must not be called in the midst of writing a statement.
2022-03-19 10:22:49 +00:00
Stephen Williams 59b3e220ad
Merge pull request #645 from larsclausen/elaborate-type-const
data_type_t::elaborate_type(): Make return type const
2022-03-16 22:11:07 -07:00
Lars-Peter Clausen a4eb971655 Remove unused parameter from pform_set_net_range()
The `net_type` and `dt` parameter of `pform_set_net_range()` always get
passed the same value, NetNet::NONE and IVL_VT_NO_TYPE respectively. Both
these values are ignore by the function. So these parameters don't do
anything useful, remove them.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-16 11:42:53 +01:00
Lars-Peter Clausen aa7e253026 Consolidate most pform_set_<type>_data_type() functions
There are a couple of different functions for the different data types that
are called when the type of a signal is set. But they all effectively do
the same.

Consolidate this code by moving the common code into the main
pform_set_data_type() function.

This allows to remove most of the type specific functions and eliminates
some duplicated code. It ensures consistent and data type independent
behavior at the parser level. Something that will be required to eventually
support type parameters.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-16 11:41:27 +01:00
Lars-Peter Clausen 962c0af1b6 Don't set information not needed on enum signals
When creating a PWire for a enum type the signedness as well as whether
the base type is an integer is assigned to the wire.

But this information is never queried again. When creating the netenum_t
this information is directly taken from the enum_type_t.

The signedness and integer information of the PWire is only used when
elaborating a netvector_t.

Removing this makes the pfrom_set_enum() function similar to those for
other types and will allow us to consolidate them in follow up patches.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-16 11:09:01 +01:00
Lars-Peter Clausen db33dbfbcc Add regression tests for task non-ANSI port declarations
Check that it is possible to define the data type of a non-ANSI task port
in a separate declaration from the port direction. Add tests for both the
type declared before the port direction and for the type declared after the
port direction.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-16 09:17:55 +01:00
Lars-Peter Clausen ee81ac2f85 Add regression tests for module non-ANSI port declarations
Check that it is possible to define the data type of a non-ANSI module port
in a separate declaration from the port direction. Add tests for both the
type declared before the port direction and for the type declared after the
port direction.

Note that this doesn't work yet correctly for integer type module ports
yet, so there are no tests for this. This will be addressed in follow up
work.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-16 09:17:55 +01:00
Lars-Peter Clausen 53284b95af Allow to declare direction after data type for non-ANSI ports
When using non-ANSI ports (System)Verilog allows to have separate
declarations for the port direction and data type. E.g.

```
input x;
reg x;
```

It is also allowed to first declare the data type and then the port type.
E.g.

```
reg x;
input x;
```

Currently this fails with an error message. Add support for handling this
by allowing to change the port type of a signal from `NOT_A_PORT` to port
direction.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-15 11:18:56 +01:00
Martin Whitaker 831db5a0d7 Fix vvp code generation for c. assign shift of array word (issue #632) 2022-03-14 23:24:20 +00:00
Lars-Peter Clausen 7f4013ac66 data_type_t::elaborate_type(): Make return type const
For some data types the value returned by the `elaborate_type()` method is
shared among different signals of that type. E.g. all string or real types
get elaborated to the same ivl_type_s. This means the returned value must
not be modified, otherwise the data type for unrelated signals might get
changed.

To enforce this and protect against accidental breakage make the return
type of the `elaborate_type()` and the related `elaborate_type_raw()`
methods const.

Note that `ivl_type_t` is used for the new return type which is a typedef
for `const ivl_type_s*`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-14 22:06:12 +01:00
Stephen Williams 15e1a7a3f2
Merge pull request #644 from larsclausen/port-range-mismatch-recover
Recover from port and signal vector range mismatch
2022-03-13 14:36:31 -07:00
Stephen Williams 5bc1c08c67
Merge pull request #641 from larsclausen/lineinfo
parser: Consistently pass line information as `vlltype`
2022-03-13 14:35:09 -07:00
Stephen Williams d7e4d209b8
Merge pull request #640 from larsclausen/darray-packed-array
Support dynamic arrays and queues of packed arrays
2022-03-13 14:33:27 -07:00
Stephen Williams 6c4a676bc1
Merge pull request #639 from larsclausen/class-empty-item
Handle empty class item declarations in parser
2022-03-13 14:25:49 -07:00
Stephen Williams 77afa1774c
Merge pull request #637 from mmicko/micko/no-date
Add option to skip writing date to output file
2022-03-13 14:25:04 -07:00
Lars-Peter Clausen a9c0469b2b Add regression test for task port range mismatch
Check that a range mismatch is detected for non-ANSI task ports when
port direction and data type are declared separately.

An error should be reported and no crash should occur.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-13 11:17:27 +01:00
Lars-Peter Clausen 026d552be1 Add regression test for module port range mismatch
Check that a range mismatch is detected for non-ANSI module ports when port
direction and data type are declared separately.

An error should be reported and no crash should occur.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-03-13 11:07:10 +01:00