Commit Graph

9541 Commits

Author SHA1 Message Date
Stephen Williams fa864156e4
Merge pull request #629 from steveicarus/always_comb-vs-void-func
Always comb vs void func
2022-02-27 16:17:53 -08:00
Stephen Williams 5b65a583a1
Merge pull request #628 from larsclausen/module-output-var-types
Make output ports with data type variables
2022-02-27 15:08:46 -08:00
Stephen Williams e0eed7146f
Merge pull request #627 from larsclausen/consolidate-task-function-item-rules
Consolidate task and function item parser rules
2022-02-27 14:35:37 -08:00
Stephen Williams 035325e9df Regression test for issue 576. 2022-02-27 14:21:22 -08:00
Stephen Williams 807fb2e5d1 always_comb and friends handle void functions similar to tasks
Void functions can be used in always_comb, but since the compiler
uses the check_synth() method to generate some warnings, make sure
that function is implemented for functions as well as tasks.
2022-02-27 08:56:30 -08:00
Lars-Peter Clausen f53a95840a Add regression tests for module output variable type ports
Check that a output port that has a explicit data type, but no explicit
net type is elaborated as a variable type port.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-27 13:28:26 +01:00
Lars-Peter Clausen 046893d97f Make output ports with data type variables
In SystemVerilog output ports are a variable if either:
 * They are explicitly declared a variable (with the `var` keyword)
 * There is no explicit net type, but a explicit data type

This is in detail described in section 23.2.2.3 ("Rules for determining port
kind, data type, and direction") of the LRM (1800-2017).

E.g.
```
output x // Net
output [1:0] x // Net
output signed x // Net
output wire x // Net
output wire logic x // Net
output var x // Variable
output logic x // Variable
output var logic x // Variable
output int x // Variable
output real x // Variable
output string x // Variable
output some_typedef x // Variable
```

At the moment the code checks for certain data types and only makes the
output port a variable for those. And it is even different data types
depending on whether the port is declared ANSI or non-ANSI style.

Change this so that if a data type is specified and it is not a implicit
data type (i.e. only ranges or `signed`) then the output is of type
variable.

This ensures consistent and correct behavior.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-27 13:28:26 +01:00
Lars-Peter Clausen bbe44deec2 Support all packed types for module ports
Currently module ports only support vectors, atom2, enum and struct packed
types, but not packed arrays.

Generalize the code so that any packed type is supported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-27 13:28:07 +01:00
Lars-Peter Clausen 28bbebf98c Consolidate task and function item parser rules
Task and function item rules are identical. Consolidate them into a single
set of rules to remove some duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-27 11:35:59 +01:00
Stephen Williams 70637db4d3
Merge pull request #626 from larsclausen/remove-netnet-get-isint
Remove NetNet::get_isint()
2022-02-26 13:00:10 -08:00
Lars-Peter Clausen 47b4621da1 Remove NetNet::get_isint()
NetNet::get_isint() is never used anywhere, remove it. The information
whether a signal is an integer is always directly queried from the signal
data type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-26 21:38:21 +01:00
Stephen Williams 85a4869ac3
Merge pull request #624 from steveicarus/vvp_stop_scopes
Add more types to vvp-stop
2022-02-26 12:14:31 -08:00
Stephen Williams de579f2650 Add more types to vvp-stop
Several scope types were not understood by the push command, and
a few types were not displayed reasonably. Flesh these out.
2022-02-26 11:12:50 -08:00
Stephen Williams 978717f914
Merge pull request #623 from larsclausen/task-ports-sv
Support SystemVerilog non-ansi task/function port declarations
2022-02-26 09:16:33 -08:00
Stephen Williams 83f1ea60b7
Merge pull request #620 from larsclausen/class-localparams
Support non-overridable parameters in classes
2022-02-26 09:09:00 -08:00
Stephen Williams cf5fb30c21
Merge pull request #619 from larsclausen/init-has-parameter-port-list
Initialize LexicalScope::has_parameter_port_list
2022-02-26 09:02:45 -08:00
Lars-Peter Clausen 5f71307ab4 Use data_type_t to pass `string` type information to signal elaboration
For signals that are declared in a block string_type_t is already used to
pass the type information to the signal elaboration.

But for task ports it is passed as IVL_VT_STRING. Switch this over to also
passing the type information as a data_type_t.

This allows to remove the special handling for IVL_VT_STRING in the signal
elaboration.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-25 10:43:28 +01:00
Lars-Peter Clausen 372e3eae25 Add regression test for SystemVerilog task port types
Check that it is possible to declare task ports with SystemVerilog types.
Both ANSI style and one for non-ANSI style.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-25 10:43:28 +01:00
Lars-Peter Clausen b0c386182a Support unpacked array dimensions on non-ansi style task ports
SystemVerilog allows unpacked array dimensions on non-ANSI style task and
function ports.

To support this refactor pform_make_task_ports() to accept a of
pform_port_t, which in addition to the identifier name also allows to
specify per port unpacked dimensions.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-25 10:43:28 +01:00
Lars-Peter Clausen c631ff2483 Support SystemVerilog types for non-ansi task port declarations
Tasks and functions support two types of port declarations. Either ANSI
style, in parenthesis after the task name, or non-ANSI style, as
declaration statements in the task body.

In the current implementation SystemVerilog types are only accept for ANSI
style port declarations, while non-ANSI style only accept Verilog types
(reg, integer, time, real).

Add support for SystemVerilog data types for non-ansi style ports.

This also makes the parsing rules simpler since we can use `data_type` to
match all data types and don't need a explicit rule for each supported data
type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-25 10:42:56 +01:00
Lars-Peter Clausen 2e845821a8 Add regression test for localparams in classes
Check that localparams and non-overridable parameters can be declared in a
class.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-19 13:45:22 +01:00
Lars-Peter Clausen d104e28dbf Support non-overridable parameters in classes
SystemVerilog allows `parameter` and `localparam` to declare constants
within a class scope.  E.g.

```SystemVerilog
class C;
localparam A = 10;
endclass
```

In this context both declare a local parameter that can not be overwritten.

Supporting this can be achieved for the most part by adding a parser
sub-rule in class declaration rule. In addition some extra support code is
needed to mark the parameter as non-overridable.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-19 13:45:22 +01:00
Lars-Peter Clausen 427091d3d3 Support access to class constants on objects
It is allowed to access a constant declared in a class scope, such as a
enum value or parameter, on an object of that class type. This is described
in section 8.5 ("Object properties and object parameter data") of the LRM
(1800-2017).

E.g.

```
class C
  enum { A } e;
endclass

C c = new;
c.e = c.A;
```

Support this by in addition of searching for class properties on the object
also search for constants in the class scope.

A bit of refactoring is needed around the parameter elaboration functions
since they expect a non-const NetScope, but for classes we only have a
const scope available.

The non-const scope is needed to be able to mark specparams as
non-annotatable. Since classes can't have specparams this part is factored
out into a separate function the NetScope parameter for the shared
functions is made const.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-19 13:45:14 +01:00
Lars-Peter Clausen ad23b08a10 Constify scope reference in NetEConstParam and NetECRealParam
Parameter expressions need to remember the scope they have been declared in
so that the code generator backends can insert the right parameter
reference, rather than a constant value.

Currently the scope is stored as a non-const reference. But that is not
needed. Mark the scope reference as const so NetEConstParam and
NetECRealParam can be created when only a const scope reference is
available.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-19 13:00:12 +01:00
Lars-Peter Clausen 892622bf64 Add helper function to get parameter line info
The NetScope class has a method called find_parameter() that looks up the
parameter and returns a iterator to it. This is only ever used to get the
line information of the parameter.

Refactor the function so that it only returns the line info. This will
allow to call this function on a const NetScope object.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-19 12:52:19 +01:00
Lars-Peter Clausen aa905a27cf Initialize LexicalScope::has_parameter_port_list
The has_parameter_port_list member of the LexicalScope class is not
initialized, which means its default value is undefined. This leads to
random failures where a parameter is marked as non-overridable when it
shouldn't.

Make sure has_parameter_port_list is properly initialized to false.

Fixes: 673b40b78c ("Elaborate `parameter` as non-overridable where required")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-19 08:50:23 +01:00
Stephen Williams cc0a8c8dd2
Merge pull request #618 from larsclausen/signal-decl-consolidation
Consolidate signal declaration
2022-02-18 08:27:52 -08:00
Stephen Williams afaaaed0a4
Merge pull request #617 from larsclausen/generate-invalid
Generate error for invalid declarations within generate block
2022-02-18 08:26:08 -08:00
Stephen Williams 21c769e1e1
Merge pull request #616 from larsclausen/parameter-non-overridable
Elaborate `parameter` as non-overridable where required
2022-02-18 08:25:30 -08:00
Lars-Peter Clausen ce8ee42619 Add regression test for class new initializer
Check that it is possible to use a class new as
an initializer for a variable or property declaration.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-18 11:59:09 +01:00
Lars-Peter Clausen f6394c5fe6 Consolidate variable declaration parsing rules
There are currently two rules for parsing variable declarations.
One that is used when declaring variables in as a block declaration item
and another that is use everywhere else.

Consolidate those into a single set of rules. This removes a fair bit of
duplicated code in the parser.

A side effect of this refactoring is that class new statements can be used
as variable initializers as allowed by the standard. E.g.

```
module test;
  class C;
  endlcass
  C c = new C;
endmodule
```

This previously was not supported for block item variable declarations.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-18 11:59:09 +01:00
Lars-Peter Clausen 9da057ceb1 Add helper function for creating variable declarations
Variables don't have a delay or strength and the NetNet::Type is known. Add
a small wrapper around pform_makewire() that can be used to create
variables. This will allow to reduce the boilerplate code for variable
declarations.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-18 11:59:09 +01:00
Lars-Peter Clausen 6708c0f6df pform_makewire(): Allow to specify attributes
There are a few places where pform_makewire() is used and attributes can be
attached to the created net or variable. At the moment pform_makewire()
doesn't allow to specify the attributes, and they either get dropped
silently or with a warning.

Add support for passing the attributes to pform_makewire() which will then
pass it on to pform_set_data_type() to attach it to the declared net or
variable.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-18 11:59:09 +01:00
Lars-Peter Clausen a5e9358d42 Consolidate pform_makewire() variants
There are currently two very similar implementations of pform_makewire().
One that takes a `net_decl_assign_t`, the other a `std::list<decl_assignment_t*>`.

The one that takes a `std::list<decl_assignment_t*>` is a superset of the
other. It can handle both wires and variables, while the other can only
handle wires.

Update the parser to generate a `std::list<decl_assignment_t*>` for wire
declarations. This allows to remove one of the two functions.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-18 11:58:31 +01:00
Lars-Peter Clausen 47b6ee714d Remove unused pform_makewire() variants
There are two versions of pform_makewire() that are not used anywhere,
remove them.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-18 10:40:53 +01:00
Lars-Peter Clausen b37636e4fc Add regression test for invalid declarations in generate blocks
Check that the following declarations inside a generate block generate an
error:
 * module, program or interface
 * specparam
 * specify block
 * timeunit

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-16 11:23:39 +01:00
Lars-Peter Clausen 6730ead119 Generate error for invalid declarations within generate block
Most things that can be declared in a module can also be declared in a
generate block.

But there are a few exceptions that can not be declared in generate block
 * module, program or interface declaration
 * specify block or specparam
 * timeunit

Some of these currently work while some of them trigger an assertion and
cause and application crash.

Add checks to make sure that all of them these are reported as an error and
do not cause a crash.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-16 11:23:39 +01:00
Lars-Peter Clausen bb74c6412d Refactor test for invalid parameter overrides
Split the test into multiple tests that each check one type of invalid
override rather than having one big tests that checks for everything.

This allow to check whether the test passes or fails by seeing if it
compiles or not. The one big test on the other hand relies on seeing the
exact error messages as recorded in the gold file.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-15 11:31:35 +01:00
Lars-Peter Clausen 673b40b78c Elaborate `parameter` as non-overridable where required
For modules, programs and interfaces that have a parameter port list, a
parameter declared inside the scope's body is supposed to be elaborated as
a local parameter.

TThis is described in the Verilog LRM (1364-2005) section 4.10.1 ("Module
parameters") and the SystemVerilog LRM (1800-2017) section 6.20.1
("Parameter declaration syntax").

Implement this by marking a parameter declared in such a way as
non-overridable.

Note that a parameter declared within a named block, function or task can
still be overridden, even if the module has a parameter port list.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-15 11:31:09 +01:00
Stephen Williams 96a1cbf7b2
Merge pull request #615 from zachjs/sv-edge
Restrict edge event to SV
2022-02-14 21:05:05 -08:00
Zachary Snow a4d7c3f94e Restrict edge event to SV 2022-02-14 17:54:28 +01:00
Stephen Williams 560129f0c6
Merge pull request #614 from steveicarus/logical-implication
Logical implication
2022-02-14 08:01:14 -08:00
Stephen Williams 6c04749a68 Add the l_impl test for the logical implication operator. 2022-02-13 18:48:40 -08:00
Stephen Williams 27d81bc610 Add support for logical implication
The "->" operator is rarely used, but exists. Unfortunately, the syntax
is tied up in a horrible mess with the System Verilog constraint list
syntax. Do some flex magic to make it all work.
2022-02-13 18:48:16 -08:00
Stephen Williams 3f048f266a
Merge pull request #613 from larsclausen/param-no-default
Support parameters without default value
2022-02-13 15:40:00 -08:00
Lars-Peter Clausen 91579c7c79 Add regression tests for parameters without default
SystemVerilog supports parameters without default values in parameter port
list. Add regression tests to check this feature.

Also add a regression test to check that modules without a default
parameter are not automatically picked as a toplevel module.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-13 18:21:56 +01:00
Lars-Peter Clausen 4a87bee3c0 Support parameters without default value
SystemVerilog allows to omit the default value of a parameter declared in a
parameter port list. In this case the parameter must be overridden for
every module instance. This is defined in section 6.20.1 ("Parameter
declaration syntax") of the LRM (1800-2017).

In addition a module that has a parameter without a default value does not
qualify for automatic toplevel module selection.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-13 18:21:56 +01:00
Stephen Williams b1fb4a6117
Merge pull request #611 from larsclausen/bits-types
Support calling $bits() with built-in data types
2022-02-13 08:15:46 -08:00
Stephen Williams 13aa782be2
Merge pull request #609 from larsclausen/sv-omit-param-keyword
Allow omitting `parameter` in module parameter port list
2022-02-13 08:13:11 -08:00
Stephen Williams 310fe6c4de
Merge pull request #610 from larsclausen/attrib-expr
Support full set of constant expressions in attributes
2022-02-13 08:08:25 -08:00