Commit Graph

9541 Commits

Author SHA1 Message Date
Stephen Williams a7c5eceeea ivtest: Document the ivest/regress-vNN.list file.
This is another bit that needs to be accounted for when changing versions.
2022-12-26 20:10:56 -05:00
Stephen Williams e088bee091
Merge pull request #832 from larsclausen/fix-windows-ci
ci: Windows: Add gperf to dependency list
2022-12-26 16:02:03 -08:00
Lars-Peter Clausen 8b0ace3726 ci: Windows: Add gperf to dependency list
msys2 removed the gperf package from the base-devel package collection[1].

Add gperf explicitly to the dependency list, without this the Windows
CI will fail.

[1] 085698dce3

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-26 15:07:34 -08:00
Lars-Peter Clausen 13ba780fe8 ci: Windows: Replace `MINGW_INSTALLS` with `MINGW_ARCH`
Currently the Windows build generates a warning

   => WARNING: MINGW_INSTALLS is deprecated, use MINGW_ARCH instead

Make this change to the CI workflow file.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-26 15:07:34 -08:00
Lars-Peter Clausen 42212cfb58 Add `regress-v13.list`
With the development version bumped to v13 the regression tests runner
expects a `regress-v13.list`. Provide one, which is just a copy of the
`regress-v12.list` for now.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-26 15:07:34 -08:00
Stephen Williams 43c85529af devel: Fix ci build vvp test
The vvp test expects a proper version stamp in the examples/hello.vvp file.
2022-12-26 17:16:26 -05:00
Stephen Williams 8a290830df devel: Step devel past v12 to v13 2022-12-26 12:56:19 -05:00
Stephen Williams 5347ba19cf
Merge pull request #829 from larsclausen/class-super
Add support for handling `super` keyword
2022-12-26 08:33:56 -08:00
Lars-Peter Clausen 295b65da2c Add regression tests for using `super` to access the base class
Check that it is possible to use the `super` keyword to access properties
and methods of the base class that exist with the same name in current
class.

Also check that `this.super` is supported as an alternative to `super` and
has the same behavior.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-25 09:19:21 -08:00
Lars-Peter Clausen 15fa24a664 Add support for `this.super`
SystemVerilog allows to use either `super` or `this.super` to access the
base class. Both have the same behavior. Currently only `super` is
supported, also add support for `this.super`.

To support it the parser has to be changed slightly and move the trailing
`.` after the `this` or `super` keywords into the `implicit_class_handle`
parser rule. This is necessary to avoid reduce conflicts in the grammar.

As a side effect `super` can no longer be used as a standalone identifier.
E.g. `return super;` But that's not legal SystemVerilog anyway, so that is
OK.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-25 09:19:21 -08:00
Lars-Peter Clausen c0adbd0deb Add support for handling `super` keyword
SystemVerilog allows to use the `super` keyword to access properties and
methods of a base class. This is useful if there is for example an
identifier with the same name in the current class as in the base class and
the code wants to access the base class identifier.

To support this a bit of refactoring is required. Currently properties are
internally referenced by name, this does not work if there are multiple
properties of the same. Instead reference properties always by index.

In addition when looking up an identifier that resolves to an object return
both the type and the object itself. This is necessary since both `this`
and `super` resolve to the same object, but each with a different type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-25 09:19:21 -08:00
Lars-Peter Clausen 7188f7b210 Pretty print THIS_TOKEN and SUPER_TOKEN
Internally the special THIS_TOKEN("@") and SUPER_TOKEN("#") are used
to represent the special `this` and `super` keywords in a component
name.

When printing an identifier replace the tokens with their keywords.
This generates nicer error and debug messages.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-25 09:19:21 -08:00
Lars-Peter Clausen 862b118098 PEIdent::elaborate_{expr,lval}(): Use new symbol_search()
The PEIdent elaborate_expr() and elaborate_lval() are sort of open-coding
the path traversal implemented by the new symbol_search() using the old
symbol_search().

Switch them over to use the new symbol search as it is better at handling
the corner cases and is also less code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-25 09:19:12 -08:00
Stephen Williams cc2ba4f8cb
Merge pull request #825 from larsclausen/typed-constructor
Add support for typed constructor calls
2022-12-24 17:36:01 -08:00
Stephen Williams 7b1fad78c3
Merge pull request #824 from larsclausen/class-lifetime
Fix variable initialization in class methods
2022-12-24 17:33:29 -08:00
Stephen Williams 507d8cc8ab
Merge pull request #826 from steveicarus/parser-cleanup
Parser cleanup
2022-12-24 17:31:17 -08:00
Martin Whitaker 0271602260 Use consistent format for compiler lexor warning messages.
Capitalise the first word of the main message unless it's a Verilog
keyword. Use VLwarn() in preference to yywarn or direct output to cerr.
2022-12-22 11:03:11 +00:00
Martin Whitaker 6b04d9795a Use consistent capitalisation for compiler parser warning messages. 2022-12-22 10:47:45 +00:00
Martin Whitaker 82aedbc36c Don't automatically add the "warning: " prefix in VLwarn().
One variant did, the other variant didn't. As well as being a trap for
the unwary, this gets in the way of using yywarn/VLwarn for non-fatal
"sorry" messages.
2022-12-22 10:34:56 +00:00
Martin Whitaker bb867480fc Use consistent name for all variant implementations of VLwarn().
The function prototypes both use the name VLwarn, with a macro definition
providing the alias to yywarn. But one of the variant implementations was
named yywarn. Make it consistent with the function prototype.
2022-12-22 10:21:25 +00:00
Martin Whitaker 3335138d16 Remove prototype for unimplemented variant of VLerror(). 2022-12-22 10:18:54 +00:00
Martin Whitaker 2e27b4393d Use consistent format for compiler lexor error messages.
Always prefix with "error: ". Capitalise the first word of the main
message unless it's a Verilog keyword. Use VLerror() in preference
to direct output to cerr.
2022-12-22 10:15:09 +00:00
Martin Whitaker a56ccabf7f Use consistent format for compiler parser error messages.
Always prefix with "error: " or "sorry: ". Capitalise the first word
of the main message unless it's a Verilog keyword.
2022-12-22 10:13:26 +00:00
Lars-Peter Clausen 6334839406 Add regression tests for typed constructor calls
Check that typed constructors calls are supported. Also check various
invalid usages of typed constructor calls and check that an error is
reported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-21 20:08:58 -08:00
Lars-Peter Clausen df82410a37 Add support for typed constructor calls
By default when creating a new class object the type of the object is
determined by the type of the target.

SystemVerilog also allows to explicitly specify the type of the object to
be created. The specified class still needs to be assignment compatible
with the target. This is e.g. useful to construct an object of a derived
class of the target. E.g.

```
class B; ... endclass
class C extends B; ... endclass
B b;
b = C::new;
```

Add support for this to the parser as well as handling it during
elaboration.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-21 20:03:33 -08:00
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