Commit Graph

10116 Commits

Author SHA1 Message Date
Lars-Peter Clausen 748d6d8de2 Add regression tests for class methods with static lifetime
Check that trying to specify a class method with static lifetime results in
an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-21 19:28:46 -08:00
Lars-Peter Clausen da4ac3607a Add regression test for var init in class method
Check that variable initialization as part of the declaration works as
expected in class methods.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-21 19:28:46 -08:00
Lars-Peter Clausen 3302ced608 Report error when trying to declare class methods with static lifetime
Class methods with static lifetime are not allowed in SystemVerilog. Report
an error when such a method is declared.

Note that this is different from static class methods
E.g.
```
class C;
  task static t; endtask // Class method with static lifetime, forbidden
  static task t; endtask // Static class method, allowed
```

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-21 19:28:46 -08:00
Lars-Peter Clausen 54a4e7ff0b Fix variable initialization in class methods
Up to 1800-2017 the grammar in the LRM allowed an optional lifetime
qualifier for class declarations. Icarus supports this and uses this as the
default lifetime for methods of the class. But the LRM never specified what
this qualifier should do actually actually. Starting with 1800-2023 the
qualifier will be removed from the grammar[1].

Furthermore the LRM states that methods of a class are supposed to have
automatic storage and static storage is forbidden.

This currently works in Icarus for the most part since the liftime attached
to class methods is ignored during elaboration in most places. Where it
does not work is for variable initializers where it results in broken code
being generated and vvp crashes at runtime. E.g.

```
class C;
  task t;
    int x = 10;
  endtask
endclass
```

Keep the optional lifetime qualifier for classes in the grammar for now, to
ensure backwards compatibility in case somebody is actually using it. But
ignore it and print a warning if it is specified.

In addition set the default lifetime for all classes to automatic. This
makes sure that variable initialization in classes works as expected.

[1] https://accellera.mantishub.io/view.php?id=3561

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-21 19:28:35 -08:00
Stephen Williams 580d79eae3
Merge pull request #820 from larsclausen/array-compatibility
Add error checking for continuous unpacked array assignments
2022-12-21 11:38:15 -08:00
Martin Whitaker 01378fbdb0 Clean up indentation in compiler parse.y.
Convert the remaining old-style indentation to the new style.
2022-12-21 14:11:47 +00:00
Martin Whitaker 32f66511e0 Fix spelling of `pragma in scanner.
This does prove nobody is using it :-)
2022-12-21 12:11:41 +00:00
Martin Whitaker 7914f8ad9d Add a few comments in the compiler scanner. 2022-12-20 18:14:18 +00:00
Martin Whitaker 968f0d943e Catch unrecognised compiler directives in the compiler scanner.
Normally the preprocessor will catch these and report them as undefined
macros. But in case the compiler is run without the preprocessor, also
catch them in the compiler scanner. This will ensure the scanner properly
rejects directives that have additional garbage characters tacked on the
end.
2022-12-20 18:14:18 +00:00
Martin Whitaker cd0b360575 Support free-form `default_net_type directives. 2022-12-20 18:14:18 +00:00
Martin Whitaker 79a3d08d69 Support free-form `begin_keywords and `end_keywords directives. 2022-12-20 18:14:18 +00:00
Martin Whitaker 52f269649a Support free-form `(end)cell_define and `reset_all directives.
Also use VLerror for reporting errors.
2022-12-20 18:14:18 +00:00
Martin Whitaker 0dc64b99f3 Support free-form `(no)unconnected_drive directives.
Also use VLerror for reporting errors.
2022-12-20 18:14:18 +00:00
Martin Whitaker 59d70cad45 Support free-form `timescale directives with interspersed comments (issue #782)
Verilog compiler directives are free-form and, subject to semantic rules,
can appear anywhere in the source code. Whilst it is common practice to
write them on a separate line, we should handle all legal syntax.
2022-12-20 18:14:17 +00:00
Stephen Williams 46e1a21d7b
Merge pull request #819 from larsclausen/class-compatiblity
Allow objects to be assigned to a variable of a base class
2022-12-18 09:03:44 -08:00
Stephen Williams 9d2244abb4
Merge pull request #818 from larsclausen/void-cast
Add support for void cast function call
2022-12-18 09:00:41 -08:00
Stephen Williams deb4ff4ca8
Merge pull request #821 from steveicarus/steveicarus/cleanup-warnings
Clean up warnings
2022-12-18 08:57:33 -08:00
Stephen Williams 03f912dc55 Clean up warnings
Clean up warnings that show up on newer compilers. Many of these warnings
are related to obsolete c library features or language features. This does
not clear up warnings in code generated by bison or flex.
2022-12-18 10:18:10 -05:00
Martin Whitaker c8a85877c2 Allow io-range-error warnings to be disabled (issue #788)
It was common practice in the past to just declare a port direction
and declare it as a vector in a subsequent type declaration. Versions
of the standard up to and including 1364-2005 include an example that
does this (e.g. 1364-2005 section 12.3.7). Users may have old or
third-party code that they can't or don't want to modify, so allow
the warning to be suppressed by including it in the anachronisms
category.
2022-12-18 12:12:26 +00:00
Lars-Peter Clausen 4ef5b02bcd Add regression tests for continuous array assign compatibility
Check various different scenarios for array compatibility in continuous
array assign. Both testing cases that should work and cases that should
fail.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 15:47:18 -08:00
Lars-Peter Clausen 5ec72f4cc8 Add error checking for continuous unpacked array assignments
Currently there is no error checking for continuous assignments to unpacked
arrays. If the lvalue and rvalue net are not compatible undefined behavior
occurs. For some types of incompatibility it will crash during elaboration,
for others it will crash during simulation, and for some it will just work,
even though the assignment is not allowed by the standard.

Implement checking to ensure the two nets are compatible as required by the
standard and report an error otherwise.

Two arrays are considered to be compatible if their element types are
equivalent, they have the same number of ranges and each range has the same
number of elements.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 15:29:38 -08:00
Lars-Peter Clausen 4cfba91d65 Add regression tests for class compatibility
Check that it is possible to assign an object to another object that is of
a type of any of its base classes. Also check that an error is reported if
this is not the case.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 14:27:38 -08:00
Lars-Peter Clausen 9b68c5776b Allow objects to be assigned to a variable of a base class
SystemVerilog allows objects to be assigned to a variable that is a base
type of the objects type.

E.g.
```
class B; endclass
Class C extends B; endclass

C c = new
B b = c;
```

Add a type_compatibility() method for netclass_t that allows these kinds of
assignments.

This already works fine in vvp since, as SystemVerilog does not support
multiple inheritance, properties will always be at the same offset in the
base class and the inheriting class.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 14:16:47 -08:00
Lars-Peter Clausen 269e1ca88d Add regression tests for void casts
Check that it is possible to use a function with a return type as a
statement by using a void cast.

Also check that trying to void cast a void function, a task or an
expression results in an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 11:38:07 -08:00
Lars-Peter Clausen 0e62ff153d Add support for void cast function call
SystemVerilog has explicit support for calling a function
as a statement. This is allowed when the function call is encapsulated in
`void'(...)`. E.g. `void'(f(1, 2, 3));`

We already support calling function calls as statements without the void
cast and emit a warning when doing so.

Adding support for void casts only requires to update the parser to handle
the void cast and then do not emit the warning if a function is called as
a statement as part of a void cast.

Void casting a task or void function call is not allowed and will generate
an elaboration error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-17 11:19:30 -08:00
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