Commit Graph

125 Commits

Author SHA1 Message Date
Cary R 860761f9c6 More cppcheck fixes - part 2 2025-10-20 23:54:15 -07:00
Lars-Peter Clausen 5547858372 Add initial support for packed arrays/vector assignment pattern
SystemVerilog allows to use assignment patterns to assign a value to a
packed array.

This is similar to using a concatenation, with the difference that for
concatenations the values are evaluated in a self-determined context and
for assignment patterns they are evaluated in a context defined by the
element type of the packed array. This means that the value is for example
automatically width expanded or truncated if it does not have the same size
as the element type. Automatic type conversion is also done when allowed. E.g.

```
bit [3:0][3:0] x = '{1'b1, 32'h2, 3.0, "TEST"};
$display("%x", x); // -> 1234
```

Nested assignment patterns are also supported. E.g.
```
bit [1:0][3:0][3:0] x = '{'{1, 2, 3, 4.0}, '{5, 6, 7, 8}};
$display("%x", x); // -> 12345678
```

Add support for using assignment patterns as the right hand side value.
Since the complete type of the target variable is required to correctly
evaluate the assignment pattern it is handled as a special case in
`elab_rval_expression()`. For other types of expressions for packed values
only the total width of the target value is provided to the rvalue
elaboration function.

SystemVerilog also supports assignment patterns for the left hand side in
assignments. This is not yet supported.

Also not yet supported is specifying array elements by index, including
`default`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2023-02-04 14:32:44 -08:00
Cary R dc8b7d0184 Cleanup some cppcheck warnings 2022-12-28 00:00:31 -08:00
Lars-Peter Clausen 5ef847ea87 Support type parameters
SystemVerilog supports type parameters. These are similar to value
parameters, but they allow to pass a type to a module or similar when
instantiating it.

E.g.

```
module A #(parameter type T = int);
endmodule

module B;
  A #(.T(real)) i_a;
endmodule
```

Add support for handling type parameters.

For the vlog95 and vhdl backends type parameters, similar to typedefs, get
replaced with their actual value. For modules with non-local type
parameters for each module instance a unique module or architecture is
generated with the actual type.

Querying type parameters through VPI is not yet supported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-12-11 13:50:14 -08:00
Martin Whitaker 2ceb90b95e Fix assertion failure on multiple instantiation of implicitly real-typed parameter declaration (issue #732)
If the parameter has no explicit type, the type is inferred from the RHS
expression. The first time the parameter is evaluated, the RHS hasn't yet
been elaborated, so the type is unknown. This causes the evaluation to be
performed by NetScope::evaluate_parameter_logic_, which correctly handles
both logic and real types. However, on subsequent evaluations of the
parameter, the expression type is now known, so the evaluation was being
performed by NetScope::evaluate_parameter_real_. This function requires
the parameter to have an explicit type.

For now, rather than add more code to NetScope::evaluate_parameter_real_
to handle an implicit type, force NetScope::evaluate_parameter_logic_ to
be used whenever we have an implicit type. This should probably be reworked
if support for more complex types is added.
2022-08-24 15:21:16 +01:00
Lars-Peter Clausen 37f9cde49f Handle scalar typed parameters
Parameters without any type or range specification inherit the type from
the value that has been assigned to it. Similarly a parameter with just an
`signed` or `unsigned` keyword will inherit its range from the value
assigned to it.

In the current implementation any vector type parameter that does not have
a range specification inherits the type form the assigned value. That
includes parameters with an explicit scalar vector type. E.g.

```
parameter bit X = 10
```

Make sure that a parameter only uses the width from the assigned value if
the parameter does not have an explicit data type.

To support this we need to remember whether a `netvector_t` was declared as
an explicit or implicit data type. Currently this information is only
available on the unelaborated `vector_type_t`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-02 14:33:31 +02: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
Lars-Peter Clausen 0ab1ed916f Report error when trying to override non-existing parameter
Overriding a parameter that does not exist will only generate a warning at
the moment. This can hide programming mistakes such as an typo in a
parameter override.

There is nothing in the LRMs to support that this should only be warning,
so elevate this to an error. This is consistent with how an error is
generated when trying to reference a non-existing port or variable.

The generated error message differentiates between whether the parameter
does not exist at all, or whether it is a localparam.

There are two regression tests that rely on that only a warning is
generated, these have been updated to expect an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-01 22:50:21 +01:00
Martin Whitaker 0e3682a127 Remove buggy assertion.
If this assert fires, the "this" pointer we pass to it will be a
null pointer, so will cause a null pointer dereference. We've
tested it is not null earlier, so we don't need the assertion.
2021-11-04 17:07:30 +00:00
Martin Whitaker ecbbb60fb6 Remove "using namespace std" from compiler header files and fix the fallout. 2021-11-04 16:55:03 +00:00
Martin Whitaker 829d361b17 Fix null pointer warning from latest GCC. 2021-11-03 18:07:15 +00:00
Stephen Williams eaa3a10e8c Elaborate parameter types in the scope of the paramter. 2020-12-29 10:29:15 -08:00
Stephen Williams a286764c1d Add support for string parameters
Parameters can have string type and do the usual string stuff,
and also implement some of the string methods on string parameters
so that they evaluate down to constants.
2020-12-27 21:17:57 -08:00
Stephen Williams 16646c547c Rework parsing of parameter types
Use the common data_type_or_implicit rules to support type
definitions for parameters. This eliminates a bunch of special
rules in parse.y, and opens the door for parameters having
more complex types.
2020-12-27 21:17:57 -08:00
Martin Whitaker 55219773fd Allow nested scopes to use their parent's imports. 2019-09-27 22:19:30 +01:00
Martin Whitaker 988816c0b1 Support separate compilation units in SystemVerilog.
The compilation unit scope is now treated as a specialised form of
package (with an automatically generated name). All items declared
outside a design element are added to the current compilation unit
package. Apart from when searching for a symbol, once we get into
elaboration we can treat these just like any other package.
2017-10-31 20:38:59 +00:00
Cary R 399384d81b Fix some cppcheck warnings and bugs 2015-12-19 17:19:19 -08:00
Martin Whitaker 0e66e9781a Add support for non-constant default subroutine arguments.
Input ports only at the moment. Output "sorry" message for other
port types.
2015-06-20 21:39:45 +01:00
Martin Whitaker b400532169 Added support for interface declaration and instantiation.
modport and extern tf declarations are not yet supported.
2014-12-19 23:10:14 +00:00
Stephen Williams a98f21aa65 Merge branch 'master' into vec4-stack
Conflicts:
	elab_lval.cc
	netmisc.cc
	tgt-vvp/eval_object.c
	tgt-vvp/vvp_process.c
	vvp/codes.h
	vvp/compile.cc
	vvp/opcodes.txt
	vvp/vpi_tasks.cc
	vvp/vpi_vthr_vector.cc
	vvp/vthread.cc
2014-10-21 09:12:02 -07:00
Stephen Williams 338a0eb11a Get $root scope tasks/fuctions down to the ivl_target API. 2014-10-02 14:09:27 -07:00
Stephen Williams c5fee8bdb9 Elaborate root tasks/functions. 2014-09-30 16:06:32 -07:00
Stephen Williams 480668fee6 Add support for classes defined in $root scope. 2014-09-15 17:37:30 -07:00
Stephen Williams be5bfeb172 Elaborate widths of parameters correctly for unsigned values
If there is no size in the parameter type declaration or on the
value itself, then give the parameter value a minimum width of
integer bits.
2014-02-11 18:24:12 -08:00
Stephen Williams 44cd9158e8 Elaborate parameters, tasks and functions in packages.
Get the elaboration to happen all the way to the ivl_target
interface.
2013-04-08 18:20:39 -07:00
Martin Whitaker faece5816c Fix implicit casts in assignments (part 3).
This patch adds support for bool/bit vector types on the LHS of
a parameter declaration and ensures implicit casts in parameter
declarations are performed where necessary.
2013-03-24 13:50:53 -07:00
Stephen Williams 60cb78e4ab Add packages and their own scope.
This makes <pkg>::<name> work properly, and also makes the
package descriptions available through VPI.
2013-02-17 17:00:15 -08:00
Stephen Williams a14b8c517c Clean up Design::find_scope method use. 2012-09-03 16:00:10 -07:00
Arun Persaud f5aafc32f9 updated FSF-address 2012-08-29 10:12:10 -07:00
Cary R 7ce8a9b01c Fix some cppcheck warnings in the main directory 2012-08-08 11:28:20 -07:00
Stephen Williams 8154ce2a4a Reword how we enforce program block constraints
Making the scope type NESTED_MODULE was just plain wrong, because
it didn't really encapsulate the meaning of program blocks OR
nested modules. So instead create nested_module() and program_block()
flags and use those to test scope constraints.
2012-05-27 18:26:53 -07:00
Stephen Williams 2d0c786bfb Remove excess evaluate_parameters method calls. 2012-05-18 08:07:27 -07:00
Martin Whitaker 44c5a37ab8 Allow specparam declarations outside specify blocks.
This patch extends the compiler to support all specparam declarations
allowed by the 1364-2005 standard. For compatibility with other
simulators, it allows specparam values to be used in any constant
expression, but outputs a warning message and disables run-time
annotation of a specparam if it is used in an expression that must
be evaluated at compile time.
2012-05-17 16:18:38 -07:00
Cary R 142f661737 Fix the compiler to keep the original file/line information.
For a parameter we want to keep the base definition file/line information
not the file/line information for the override.
2012-01-02 10:23:08 -08:00
Martin Whitaker 831b6d3ad6 Fix for crash when real value assigned to signed type parameter.
A declaration of the form "parameter signed a = 1.0" causes a
compiler crash. The standard is somewhat contradictory on what
type "a" should have, but testing with other compilers shows a
majority in favour of it being a real value.
2011-12-13 15:04:10 -08:00
Martin Whitaker 37be84483c Add support for parameter declarations with type but no range.
The standard allows a parameter (or localparam) declaration of the
form "parameter signed my_param = ...". The parser currently rejects
this. A small adjustment is also required in the parameter evaluation
code to correctly apply the type.
2011-12-06 09:42:29 -08:00
Martin Whitaker 1e9f9685cc First step towards supporting constant user functions.
This patch allows the compiler to perform early elaboration
of functions if they are encountered in expressions that are
elaborated before the function would normally be elaborated.
This makes the function available for constant evaluation.
Suitable error messages are generated if a function that is
used in a constant expression is not a valid constant function.
2011-04-13 18:40:19 -07:00
Martin Whitaker 93067149f1 Rework of constant expression error reporting.
This patch changes the method used to signal that a constant expression
is being elaborated from flags stored in global variables to flags
passed down the call chain. It also generates more informative error
messages when variable references are found in a constant expression.
2011-04-06 18:50:53 -07:00
Larry Doolittle e9fda22ad9 Spelling fixes
Mostly then/than confusion.  All comments or README files,
except for one user-visible change in a tgt-vlog95 error message.
2011-03-14 16:28:36 -07:00
Cary R 2a0d33608f Fix spacing problems.
This patch fixes spacing problems in the source code, space/tab at
the end of line and space before tab.
2011-03-03 11:21:31 -08:00
Martin Whitaker 312b4da46f Expression width rework.
This patch is a major rework of expression elaboration and
evaluation in the compiler, aimed at better compliance with
the IEEE standard.
2011-03-01 18:13:26 -08:00
Cary R 20f3d7c26c Remove some more cppcheck warnings.
This patch removes some more simple cppcheck warnings and updates two of
the cppcheck suppression files.
2011-01-12 16:34:42 -08:00
Martin Whitaker 275dde7712 Rework of parameter expression elaboration.
The compiler currently performs parameter expression elaboration before
performing parameter overrides. This means that the information needed
to correctly determine the expression type and width may not be available
at the time elaboration is performed. This patch reworks the code to
delay elaboration until after all overrides have been performed. It
also provides a new -g option that controls how the width of parameter
expressions is calculated when the parameter itself is unsized.
2010-12-06 14:56:50 -08:00
Cary R 225ca1e205 Change iterators to use prefix ++ since it is more efficient.
This patch changes all the iterator code to use a prefix ++ instead
of postfix since it is more efficient (no need for a temporary). It
is likely that the compiler could optimize this away, but lets make
it efficient from the start.
2010-11-02 10:43:16 -07:00
Stephen Williams ec49f10e2d Revert bad merge from vhdl branch 2010-10-02 11:02:27 -07:00
Cary R 86653ddff9 Remove some cppcheck warnings.
This patch modifies the code to remove some more cppcheck warnings.
2010-07-30 18:50:52 -07:00
Cary R e241586bcf Add support for passing the delay selection to vvp.
This patch adds support for passing the delay selection to vvp.
It adds a new header :ivl_delay_selection "<value>"; that has
the values TYPICAL, MINIMUM or MAXIMUM depending on the -T
flag to iverilog. This information is needed by $sdf_annotate
to select that appropriate value for a triplet when
"TOOL_CONTROL" is specified (default).
2010-03-16 15:43:06 -07:00
Stephen Williams b1d9d1bda2 Dramatically improve NetScope child lookup.
In physical models, there are often very many child scopes in any
given scope. The lookup for child scope needs to be optimized.
2009-12-08 15:14:55 -08:00
Cary R 464310f522 Report an error when trying to take the concatenation of a real value.
This patch adds checks in various places to prevent the user from
taking a concatenation of a real value.
2009-04-02 18:20:50 -07:00
Stephen Williams 33044876dd Handle errors in parameter handling.
Don't crash if the user typed in an invalid parameter.
2008-12-19 16:32:44 -08:00