Commit Graph

10116 Commits

Author SHA1 Message Date
Stephen Williams 0ac3997142
Merge pull request #858 from larsclausen/class-prop-shadow
Consolidate class property handling
2023-01-16 11:23:44 -08:00
Stephen Williams 46a11f4b67
Merge pull request #845 from wmlye/wmlye/assertion-issue823
Clean up assertions in #823 and #840
2023-01-16 10:35:00 -08:00
Lars-Peter Clausen fe5e60840f Add regression test for function calls with empty arguments
Check that function calls with empty arguments are supported. Check the
general case and special cases such as calling a function with empty
arguments as part of a module port binding or force statements in automatic
contexts.

Also check that calling a function with too many trailing empty arguments
as well as passing an empty argument for a port without a default value is
an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-16 08:07:03 -08:00
Lars-Peter Clausen 4cc3c7b08f Add regression tests for shadowing class properties
Check that class properties can be shadowed by local symbols in class
methods and also check that a package scoped identifier with the same name
as class property can be accessed in a class method.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-16 07:13:42 -08:00
Lars-Peter Clausen 07e20376d7 Consolidate class property handling
There are currently two mechanisms for handling class properties. One that
is used when a class property is accessed through an object and other when
a class property is used freestanding in a class method.

Both are very similar, but there are some small differences. E.g. one
supports arrays, the other supports nested properties.

```
class B;
  int x;
endclass

class C;
  B b;
  B ba[2];
  task t;
    ba[0] = new; // Does work
    this.ba[0] = new; // Does not work
    b.x = 10; // Does not work
    this.b.x = 10; // Does work
  endtask
```

There is another problem where free standing properties take precedence
over local variables. E.g.

```
class C;
  int x = 1;
  task t();
    int x = 2;
    $display(x); // Should print 2, will print 1
  endtask
endclass
```

The class property elaboration also ignores the package scope of the
identifier resulting in access to a class property being elaborated if
there is a property of the same name as the scoped identifier. E.g.

```
package P;
  int x = 2;
endpackage

class C;
  int x = 1;
  task t;
    $display(P::x); // Should print 2, will print 1
  endtask
endclass
```

Consolidate the two implementation to use the same code path. This is
mainly done by letting the symbol search return a result for free standing
properties as if the property had been specified on the `this` object. I.e.
`prop` and `this.prop` will return the same result from the symbol search.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-16 07:13:42 -08:00
Lars-Peter Clausen 6cf19ec964 Fixup empty function/task argument lists in a consistent way
As a quirk of the (System)Verilog grammar a function or task argument list
with no arguments can not be distinguished from a argument list with a
single empty argument. The iverilog parses it as the latter. There are
currently many places in the code base where this is fixed up in slightly
different ways.

Fix this up in the parser in a central way before passing the arguments to
the elaboration stage.

The existing implementation in some cases removes all empty trailing
arguments. While this works to handle the case for zero arguments it also
hides some errors that should be detected. E.g. in the following 3
arguments are passed to a function which only takes two arguments. But no
error is reported since the explicitly specified empty arguments are
removed.

```
function f(integer a, integer b = 2); ... endfunction
f(1,,);
```

In the new implementation the empty argument will only be removed if there
is exactly one empty argument in the argument list.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-16 04:01:49 -08:00
Lars-Peter Clausen aea202b2e9 PECallFunction: Handle empty parameters in has_aa_term() and declare_implicit_nets()
A function parameter can be an empty value, in which case its expression is
a nullptr and can not be dereferenced. Make sure this case is handled in
the has_aa_term() and declare_implicit_nets() methods.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-16 04:00:13 -08:00
Lars-Peter Clausen c90265351b Duplicate default function/task argument expressions
The default value for a function or task argument is elaborated once and
then used for each function invocation where no actual value is provided.

This means if a function or task is called multiple times the same NetExpr
is passed as a sub-expression to multiple statements or expressions such as
the function call.

This is causing problems because each expression or statement expects to
have exclusive ownership over its sub-expressions. It can for example
result in a double free or other undefined behavior.

To mitigate this duplicate the default argument expression before it is
given as a sub-expression to another expression or statement.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-16 04:00:13 -08:00
Lars-Peter Clausen dc10710198 Remove cls_val parameter from old symbol_search
There are no users of the old symbol_search that need the cls_val result.
Remove it as a output parameter of the function.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-15 22:55:57 -08:00
Stephen Williams b74059eaa9
Merge pull request #855 from steveicarus/steveicarus/loop-control-support
Add break and continue loop control statements support
2023-01-15 22:21:55 -08:00
Stephen Williams 7b105a696d
Merge pull request #857 from larsclausen/import-hier-fail
Don't allow access to imported identifiers through hierarchical names
2023-01-15 22:18:46 -08:00
Stephen Williams d25af1451c
Merge pull request #856 from larsclausen/ps-method-call
Support method calls on package scoped signals
2023-01-15 22:17:49 -08:00
Stephen Williams 557bb61d10 ivtest: add br_gh191_break and br_gh191_continue tests 2023-01-15 21:47:52 -08:00
Stephen Williams 47283bdad7 Fix pform dump of GE expression. 2023-01-15 21:47:52 -08:00
Stephen Williams 6c9c876c83 Add compiler support for break and continue
This includes support at the parser (pform) through enaboration
and the netlist format for the break and continue statements.

Elaboration actually already worked for for-loops, but since the code
generators need more information, this is a rewire of that support to
be explicit about for-loops. This means they are not rewritten as fancy
while loops. The code generators will have to handle that.

Given the elaboration of for-loops now work, write the vvp code generator
support needed to implement it.

Now that for-loops are presented as for-loops to the code generator, the
vlog95 code generator doesn't need to infer them anymore. Generate the code
more directly.

Also update the tests list so that the vlog95_reg tests all pass.
2023-01-15 21:46:20 -08:00
Lars-Peter Clausen 535c09db62 Add regression test for package scoped method call
Check that it is possible to call a method on a package scoped identifier.
Both for built-in types as well as class objects.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-08 07:59:20 -08:00
Lars-Peter Clausen c1f2e0c21f Support method calls on package scoped signals
Currently package scoped function calls are supported. Update the parser
and elaboration to also allow method calls on packaged scoped variables.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-08 07:59:20 -08:00
Lars-Peter Clausen f9a0e2f401 Add regression tests for accessing imported identifiers through hierarchical names
Check that an error is reported when trying to access an imported
identifier through a hierarchical name.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-07 10:31:02 -08:00
Lars-Peter Clausen f4d55081ed Don't allow access to imported identifiers through hierarchical names
Imported identifiers should only be visible in the scope they have been
imported too. They should not be accessible through hierarchical names into
that scope. This is defined in section 26.3 ("Referencing data in
packages") of the LRM (1800-2017).

Modify the symbol search to not look at imports if the name is part of a
hierarchical path.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-07 10:30:55 -08:00
Stephen Williams 45bd0968c3
Merge pull request #853 from larsclausen/ci-parallel
ci: Use parallel build
2023-01-06 20:22:25 -08:00
Stephen Williams 08f2c88fcf
Merge pull request #852 from larsclausen/vvp-string-vpi
vvp: Handle null-bytes in a conistent way when reading through VPI
2023-01-06 20:21:03 -08:00
Stephen Williams 97b897cb38
Merge pull request #851 from larsclausen/str-literal-to-str-remove-null-byte
vvp: Remove null-bytes when converting string literals to SV strings
2023-01-06 20:19:33 -08:00
Stephen Williams 9931d92c70
Merge pull request #843 from larsclausen/ps-array-cassign
Handle continuous array assignments from package scoped indentifiers
2023-01-06 20:18:44 -08:00
Stephen Williams 53854bb064
Merge pull request #842 from larsclausen/class-static-prop-base
Allow access to static properties of base classes
2023-01-06 20:17:31 -08:00
Stephen Williams 09e841eee2
Merge pull request #841 from larsclausen/ps-func-call-error-handling
Improve error handling for package scoped function calls
2023-01-06 20:16:20 -08:00
Lars-Peter Clausen 9fcec0186c ci: Use parallel build
The github CI VM has multiple CPUs. 2 for Linux and Windows, 3 for macOS.
Make use of parallel build to speed up the CI tests a bit.

For Windows the `makepkg-mingw` command already schedules a parallel
build, so no changes are made to the Windows build.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 16:53:33 -08:00
Lars-Peter Clausen 71bb011597 Add regression tests for string formatting of null-bytes through VPI
Check that null-bytes get removed when reading a value through the VPI API
as a vpiStringVal. Also check that null-bytes are not removed from string
literals when string literals are read through the VPI API as a non
vpiStringVal.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 16:22:46 -08:00
Lars-Peter Clausen 56efec8ed1 tgt-vlog95: Don't strip null-bytes from string literals in structural elements
The vlog95 backend currently strips null-bytes from strings in structural
elements. E.g. `assign y = "a\000b"` gets translated to `assign y = "ab"`.

This changes the behavior of the generated output compared to the input.
Don't ignore the null-bytes to make sure the behavior stays the same.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 16:22:46 -08:00
Lars-Peter Clausen 2e12e47a2b tgt-vlog95: Don't strip leading null-bytes from string literals
When a string literal is used in a context where it needs to be wider than
it is it will get left-padded with null-bytes. When the vlog95 backend
emits the string literal it will strip the leading null-bytes as it results
in much more legible code.

Unfortunately there are some corner cases where this results in a change of
behavior of the generated code compared to the original. E.g. if the
context that caused the width expansion has been removed by optimization.
`$display(0 ? "Yes" : "No")` should print " No" due to width expansion, but
when running through the vlog95 backend it will print "No".

Another scenario where there is a change in behavior is when a null byte
was explicitly added at the front of a string literal. E.g. $bits("\000ab")
should print 24, but will print 16 when running through the vlog95 backend.

To mitigate this remove the stripping of the leading null-bytes from the
vlog95 backend. This results in slightly less legible code being generated
in some cases, but makes sure that the code is always correct.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 16:22:33 -08:00
Lars-Peter Clausen 3cfbd7345f vvp: Only ignore leading null-bytes when reading as string through VPI
Currently when reading a number literal through the VPI API as a
vpiStringVal all null-bytes in the literal get ignored. This behavior is
different from when reading a signal through the VPI API as a vpiStringVal.
The latter will only ignore leading null-bytes and replace other null-bytes
with a space. E.g. the following two will print different values.

```
$display("%s", "a\000b"); // -> " ab"
reg [23:0] x = "a\000b";
$display("%s", x); // -> "a b"
```

For consistency modify the number literal formatting code so that it has
the same behavior as the signal value formatting code and only replaces
leading null-bytes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 15:36:02 -08:00
Lars-Peter Clausen b8ddeb8848 vvp: Handle null-bytes in the string literal VPI support
The VPI API for string literals does not correctly handle the case where a
null-byte ('\0') appears in the string literal. It uses strlen() to
calculate the length of the literal, which will give the wrong result if
there is a null-byte in the string literal. Instead of using strlen() use
the stored length to fix this.

In addition when formatting a string literal as a string ignore any
null-bytes. The LRM is not entirely clear what should happen to null-bytes
when formatting a value as a string. But the behavior of ignoring the
null-bytes is consistent with the rules of SystemVerilog for converting a
string literal to a SV string.

This problem can occur when a string literal gets null-byte left-padded due
to width of its context of its expression, but then optimization removes
part of the expression and only leaves the padded string literal.

E.g.
```
$display(0 ? "Yes" : "No");
```

will be transformed into

```
$display("\000No");
```

There is also one subtle change in behavior associated with this. The empty
string ("") is supposed to be equivalent to 8'h00. So e.g.
`$display(":%s:", "")` should print ": :" since the width of the empty
string is 1 byte and the %s modifier prints a string with the width of the
value, left-padding with spaces if necessary. The current implementation
will print "::" though. This change requires to update the marco_with_args
gold file.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 15:35:34 -08:00
Lars-Peter Clausen 56baae11cc Add regression tests for null-byte handling when assigning to SV strings
Check that when assigning or casting a string literal or vector to a SV
string type that null-bytes are removed.

Also check that writing a null-byte to an element of a string variable is
ignored.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 13:20:11 -08:00
Lars-Peter Clausen 4ddf234c32 vvp: Remove null-bytes when converting string literals to SV strings
The `%pushi/str` and `%concati/str` instructions should remove null-bytes
from the string literal when converting it to a string. This is defined in
section 6.16 ("String data type") of the LRM (1800-2017).

This is already handled correctly when converting a vector from the stack
to a SV string, just not when converting a string literal to SV string.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-01-02 13:19:40 -08:00
Bill Lye 66f5db1fb8
Merge branch 'steveicarus:master' into wmlye/assertion-issue823 2023-01-02 12:13:59 -08:00
Bill Lye b277f07b3a Typo 2022-12-31 13:39:58 -08:00
Bill Lye 696c5d5d12 Renamed testcases from "*.sv" to "*.v" 2022-12-31 13:37:45 -08:00
Bill Lye 6f1165a628 Added regression tests for issues #823 and #840 2022-12-31 11:57:33 -08:00
Martin Whitaker 23e51ef7a8 Fix compilation with -Werror=format-security. 2022-12-31 16:51:28 +00:00
Bill Lye 56eb91ea9e Fix for assertion failure in Issue #823 2022-12-30 11:12:29 -08:00
Bill Lye ee0c6bb5e4 Modifications to give error messages rather than assertions 2022-12-30 10:36:38 -08:00
Lars-Peter Clausen f42bb35c3e Add regression tests for packed scoped continuous array assign
Check that continuous array assignments from package scoped identifiers are
supported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-30 10:35:35 -08:00
Lars-Peter Clausen e88f9c52ea Handle continuous array assignments from package scoped indentifiers
Make sure the package scope is considered when elaborating identifiers for
continuous unpacked array assignments.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-30 10:35:28 -08:00
Lars-Peter Clausen c8044bddf0 Add regression test for access to static property of base class
Check that it is possible to access a static property of a base class.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-29 11:17:43 -08:00
Lars-Peter Clausen 8a807695e5 Allow access to static properties of base classes
Classes are allowed to access properties of the base class. This also
includes static properties. Currently when looking up a static property
only those of the class itself are considered. Extend this to also consider
properties of the base classes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-29 11:17:43 -08:00
Lars-Peter Clausen 5563dc6250 Add regression tests for package scoped function call errors
Check that an error is reported, rather than crashing, when trying to do a
package scoped function call when the function does not exist in the
package or is not a function.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-29 10:54:42 -08:00
Lars-Peter Clausen 43443dd7d1 Improve error handling for package scoped function calls
Currently a package scoped function call will result in an assert if the
function does not exist in the package scope.

For non-package scoped function calls instead a proper error is reported.

Refactor the code to share the same code paths between package scoped and
non-package scoped function calls. This makes sure that errors are reported
in both cases. It also makes the code slightly smaller.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-29 10:53:16 -08:00
Stephen Williams 0958621ad1
Merge pull request #839 from larsclausen/package-scope-member-sel
Elaborate member selects in the scope where they are used
2022-12-29 10:30:23 -08:00
Lars-Peter Clausen b07a66b8a3 Add regression tests for member selects on package scoped identifiers
Check that indices to package scoped identifiers are evaluated in the scope
where the identifier is accessed and not in the scope where the identifier
is declared.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-28 17:54:59 -08:00
Lars-Peter Clausen 710267e9bb Elaborate member selects in the scope where they are used
There are a few cases where a member select on a package scoped identifier
is evaluated in the scope of the package rather than the scope where the
identifier is referenced.

This leads to incorrect behavior if a local symbol is used as an index in a
part select of the referenced member select. E.g.

```
package P;
  localparam N = 1;
  struct packed {
    logic [3:0] x;
  } s = 4'b0101;
endpackage

module test;
  localparam N = 2;
  initial $display(P::s.x[N]); // Will print 0, should print 1
endmodule
```

Use the scope where the member select is used, rather than the scope where
the identifier is defined, to fix this.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-28 17:54:48 -08:00
Stephen Williams a582f66089
Merge pull request #838 from larsclausen/ps-func-call-fix-width
Fix width and sign determination for package scoped function calls
2022-12-28 17:38:35 -08:00