Commit Graph

811 Commits

Author SHA1 Message Date
Lars-Peter Clausen d97c1bc6db Insert drivers for undriven nets
Trying to add a drive strength or delay to a undriven net will result in an
assertion. Make sure that a driver is added to undriven nets.

A driver is already added for all NetESignals, which covers most expression that
can produce a raw net rvalue. But there are other ways we can end up with just a
net as the rvalue, e.g.  when applying a sign cast to a net. The following
example triggers the issue

```
wire [7:0] a;
wire [7:0] b = $signed(a);
```

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-11-29 20:28:03 -08:00
Lars-Peter Clausen 85edd8bb18 Handle calling void function from class method
Calling a void function (or a regular function and ignoring the result)
from within a class method will currently result in an error unless the
void function itself is a method of the same class.

This is because we add the implicit `this` as an object on which to search
for the function and if we do not find it print an error. Change this to
only print an error if the implicit this was not added and it was a method
call on an object identifier.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-10-15 00:15:20 +02:00
Lars-Peter Clausen 246a0d3ce8 Allow inputs to be variables in SystemVerilog
SystemVerilog allows input ports to be variables. If something is connected
to the input port it will be converted to an unresolved wire.

This is handled the same as having a continuous assignment on a
SystemVerilog varibale.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-09-10 21:39:10 +02:00
Martin Whitaker 310e239637 Fix expansion of unbased unsized literal in port assignment (issue #756) 2022-08-27 16:16:49 +01:00
Henner Zeller 05a0622154 Add missing <algorithm> header, needed to use std::transform().
Signed-off-by: Henner Zeller <h.zeller@acm.org>
2022-08-04 09:40:17 -07:00
Lars-Peter Clausen e15b125da8 Replace svector with std::vector
The custom `svector` class is essentially a subset of `std::vector`. There
is no inherent advantage to using `svector`. Both have the same memory
footprint.

`svector` was designed to be of static size, but there are a few places in
the parser where it has to grow at runtime. Handling this becomes a bit
easier by switching to `std::vector` since it is possible to use its
methods which take care of resizing the vector.

This also allows to remove the unused parameter of the `lgate` struct
constructor, which was only needed for compatibility with `svector`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-05-15 21:56:48 +02:00
Lars-Peter Clausen f19ba64614 trash 2022-04-17 09:58:11 +02:00
Lars-Peter Clausen ff8a44b025 Add variant of elaborate_rval_expr() that only takes a data_type_t
The `elaborate_rval_expr()` function takes a `data_type_t`, a
`ivl_variable_type_t` and a `width` parameter. In most places the
ivl_variable_type_t and width are directly derived from the data_type_t.
This slightly simplifies the code.

The only place where this is currently not possible is when assigning to a
compound expression like a concatenation, e.g. `{a,b} = c;`.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-17 09:58:03 +02:00
Lars-Peter Clausen 156f08a1c5 Set default signedness of return types for built-in methods of SV types
The result for the built-in methods for the SystemVerilog types is
currently always unsigned. This can lead to incorrect behavior if the value
is sign extended or passed as an argument to a system function (e.g.
$display).

For most built-in methods this does not matter, since even though they have
a signed return type, they will not return a negative value. E.g. the
string `len()` or queue `size()` functions.

It does make a difference though for the queue `pop_front()` and
`pop_back()` methods. Their return type is the element type of the queue.
If the element type is signed and the value in queue is negative is will be
handled incorrectly.

E.g. the following will print `4294967295` rather than `-1`.
```
int q[$];
q.push_back(-1);
$display(q.pop_front());
```

To correctly support this consistently assign the actual data type of the
built-in method's return value to the `NetESFunc`, rather than just the width
and base type. The width, base type and also the signedness can be derived
from the data type.

Note that this only fixes the default signedness, but not the case where
the signedness of the expression is changed by its context (e.g. in
arithmetic expression). Handling this will require some additional work.

Also note that assigning the actual data type is also required to support type
checking on the return value, e.g. as needed for enum types.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-14 10:43:59 +02:00
Lars-Peter Clausen 84c3c72563 Support recursive functions using `return` statement
A `return` statement in a function gets translated into a vvp `%disable`
instruction. This works fine as long as no recursion is involved. The
`%disable` instruction will stop execution of all active threads of a
particular scope. For recursive functions this means as soon as the inner
most function returns all containing outer function calls get disabled as
well. This results in incorrect behavior.

To make recursive functions using the `return` statement work use the new
vvp `%disable/parent` instruction. This instruction will only disable the
closest thread in the thread hierarchy that matches the target scope.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-04-11 22:03:02 +02:00
Stephen Williams e6bab92274 Implement the string val-to-a methods
These methods are tasks that write into the "this" object the value
passed as an argument, converted using the appropriate base.
2022-02-27 20:28:30 -08:00
Lars-Peter Clausen 1207e908b1 PScope: Keep parameter and localparams in the same list
During parsing parameters and localparams are kept in a separate list only
to be collected into the same list during elaboration.

Store them in the same list during parsing as well, this allows to remove
some duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2022-02-10 11:07:03 +01:00
Martin Whitaker dcc9b59f6d Support SV [size] dimension for module and gate instances (issue #553).
Also output a proper error message if multiple dimensions are supplied
instead of failing an assertion.
2021-11-06 00:02:38 +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 c34167b2c0 Fix detection of directly nested generate constructs.
If a generate construct is enclosed in a begin-end pair, it can't
be directly nested (1364-2005 section 12.4.2).
2021-08-04 10:37:26 +01:00
Martin Whitaker 061121203b Fix segfault in wildcard port connection with unnamed port (issue #530).
A module port list may contain unnamed entries, e.g.

  module dut(a,);

When performing a wildcard connection, these entries should be skipped,
as there is no name to match.
2021-07-30 17:42:16 +01:00
Cary R eb5b04626d Handle elaboration tasks with a single string argument 2021-06-20 22:03:55 -07:00
Martin Whitaker 45db0db8b3 Check that port default values are constant expressions. 2021-03-12 23:27:19 +00:00
Martin Whitaker c7eaa06a2b Add support for module input port default values (issue #489). 2021-03-10 08:21:42 +00:00
Cary R 60a77b08d2 Add compiler and the start of vvp support for ->> 2021-02-19 23:21:51 -08:00
Cary R 753bf516d6 Update the symbol search to find class properties 2021-02-16 23:46:02 -08:00
Cary R 18392a464d Some clean up and add initial support for elaboration system tasks 2021-02-01 00:22:01 -08:00
Cary R 8484ff71ac Program supports NBA and BA to module variables 2021-01-30 14:28:48 -08:00
Stephen Williams 38b3c8efb2 Rework symbol_search function.
There are too many ad hoc handlers of symbol_search partial results.
Rewrite symbol_search to clean up things like partial results and
member/method detections. Use this reworked symbol_search function
to rewrite expression elaborate for the PECallFunction expressions.
2021-01-17 19:33:52 -08:00
Cary R 1bffc649cb Fix some cleanup code in the compiler 2021-01-07 23:53:53 -08:00
Cary R 5442f3fee7 Add sorry messages for missing array methods 2021-01-07 22:26:47 -08:00
Cary R 32787bb973 Add support for SV edge 2021-01-07 01:22:49 -08:00
Martin Whitaker ba25b55f53 Elaborate package scopes in textual order (fix for issue #461)
When elaborating a subclass, the base class scope needs to be elaborated
before the subclass scope. If the base class and subclass are defined in
different packages, this requires the package scopes to be elaborated in
the correct order. SystemVerilog reqires packages to be defined before
they are used, so that is the order we should elaborate them in.
2021-01-03 18:45:08 +00:00
Cary R da7484eea1 Update compiler with suggestions from cppcheck 2021-01-02 14:04:46 -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
Cary R cf53584733 Check if no argument task calls are allowed in the current context 2020-12-27 12:05:54 -08:00
Martin Whitaker a019994513 Fix search for class imported from another package (issue #437). 2020-12-23 19:16:14 +00:00
Cary R 71843a66f8 Add support for calling queue/darray functions as tasks 2020-12-20 16:50:11 -08:00
Martin Whitaker f8c49469fa Report a call to an unknown task as an error, not an internal error.
This error can certainly be triggered by invalid user code - see
issue #419.
2020-12-13 22:12:02 +00:00
Martin Whitaker fbd87b4fee Add extra debug output. 2020-12-13 21:49:42 +00:00
Martin Whitaker 393236a9a8 Fix assertion failure when elaborating a void function call (issue #318)
Depending on the order of elaboration, a function may not have been
elaborated before a call to it is elaborated, so don't assert that it
has been. As an optimisation, try to elaborate it on the fly, so we can
elide the call if the function body is empty.
2020-12-13 21:42:13 +00:00
Martin Whitaker 94b503fc64 Fix assertion failure for function body with single null statement (GH issue #411) 2020-12-10 17:40:30 +00:00
Cary R c37f1c9309 An input port driven by a variable is not collapsible 2020-11-30 22:48:39 -08:00
Martin Whitaker 55e06db693 Support calls to inherited methods without "this." prefix (GitHub issue #388). 2020-11-23 22:03:59 +00:00
Stephen Williams 156644d91e Detect and complain about some constructor chain errors
This.new is not allowed.

super.new beyond the first statement is not allowed.

And while I'm at it, clean up the use of "@" and "#" in
the code as tokens for this and super.
2020-11-22 15:31:40 -08:00
Martin Whitaker 1b3f0dd689 Add enumeration assignment compatibility check for continuous assignments. 2020-11-20 17:34:55 +00:00
Cary R a2ba8a16b1 Add support for inserting into a queue 2020-07-29 23:00:19 -07:00
Cary R 6ecd43d947 Add/update queue compile time error messages 2020-07-25 16:33:30 -07:00
Cary R 1a4345cce9 Add the ability to delete an element of a queue 2020-07-25 00:49:42 -07:00
Purdea Andrei 8889886efd Add assert to protect against potentially dereferencing null pointer.
Assert is apropriate, since it's not expected that the returned value is NULL in this case.
2020-07-11 03:54:29 +03:00
Martin Whitaker b36bca1f1b Add support for return statements in void functions. 2020-07-10 23:34:11 +01:00
Purdea Andrei 01ee6bd5b4 Fix how explicitly unconnected ports are handled in the presence of .*
See this PR: https://github.com/steveicarus/ivtest/pull/15
Which adds test implicit-port7
2020-05-18 22:49:05 +03:00
Martin Whitaker e19109e58f Fix GitHub issue #316 - isolate modpath delays from multi-driven nets.
When module ports are collapsed, we can't tell which of the nexus drivers
are associated with a given module port and should be routed through an
associated modpath delay. Work round this by inserting a transparent
buffer or tran_vp if an output or inout port has a modpath delay. The
target code generator can elide this once it has handled the modpath
delays.
2020-05-07 22:51:38 +01:00
Martin Whitaker 8da7a14800 Fix elaboration and evaluation of SV queue push arguments.
These are assignments to a queue element, so need to consider the
element base type when determining the expression width.
2020-05-01 15:30:44 +01:00
Martin Whitaker 3f49dfcd97 Fix translation of module path connection type in vlog95 target.
The target API needed to be changed to pass the connection type
through to the target code generator.
2020-04-02 12:40:59 +01:00
Martin Whitaker a8f71d3c92 Additional cleanup of void function elaboration. 2019-11-09 20:15:31 +00:00
Stephen Williams 7feb26ff6b Cleaner elaboration of void functions.
This fixed githun issue # 281.
2019-11-07 14:25:51 -08:00
Martin Whitaker de54a58991 Fix issue #265 - emit a sensible error message when an explicit cast is needed. 2019-10-06 17:54:44 +01:00
Stephen Williams befc91340c Parse and elaborate unique and priority case statements
The unique, unique0, and priority keywords can decorate case statements
to tell the run time (or synthesis) to do extra tests (or make extra
assumptions). These tests are not implemented in the vvp run time, but
now the decorations make it to the code generators.
2019-10-05 16:23:04 -07:00
Martin Whitaker 862010ac19 SV does not require constant expression in variable initialisation. 2019-10-05 20:11:38 +01:00
Martin Whitaker 9bb2147fb5 Merge branch 'package-imports-rework' 2019-10-01 23:04:23 +01:00
Stephen Williams da36cee8f0 Detect errors elaborating delay expressions. 2019-10-01 09:29:13 -07:00
Martin Whitaker c5c264400e Add support for package scope resolution for named events. 2019-10-01 09:07:54 +01:00
Martin Whitaker 1e26a808ad Fix error message for failed elaboration of event expression. 2019-10-01 09:07:30 +01:00
Martin Whitaker f69eccf903 Merge remote-tracking branch 'origin/master' into package-imports-rework 2019-10-01 09:06:15 +01:00
Cary R ba82ef463e Fix some always_* issues 2019-09-29 16:59:59 -07:00
Martin Whitaker d3bced57cc Correctly handle explicit and wildcard package imports.
Explicit imports should always conflict with local declarations using
the same name. Wildcard imports only conflict if they are referenced
before a local declaration with the same name.

This also unifies the detection of identifier conflicts.
2019-09-27 22:19:30 +01:00
Martin Whitaker 55219773fd Allow nested scopes to use their parent's imports. 2019-09-27 22:19:30 +01:00
Martin Whitaker 02ee1c65d0 Support dynamic array initialisation in variable declarations. 2019-09-16 20:35:27 +01:00
Martin Whitaker a8318db21c Fix assertion failure when top level module has array ports.
Reported by Kustaa Nyholm on iverilog-devel, 2017-10-17.
2019-08-03 18:52:49 +01:00
Martin Whitaker 6309674a8d Fix GitHub issue #231 - support packed array indexing in foreach statement. 2019-07-25 11:10:08 +01:00
Martin Whitaker 0cb1ebddf1 Fix for GitHub issue #239 - segfault when library file has syntax errors.
If there are errors when parsing a file, it is not safe to elaborate any
modules that have been found in that file.
2019-07-24 10:22:55 +01:00
Cary R 3f24557e90 Add some more always_ff synth checks 2018-09-23 22:32:22 -07:00
Martin Whitaker caf83b02c1 Enable variable declarations/initialisations in the compilation unit scope. 2018-02-18 14:09:03 +00:00
Cary R e7a9662b3d A #0 is not allowed in a final block 2018-01-01 21:35:26 -08:00
Cary R 2bbd077dc9 Add some synthesis checks for the always_comb/ff/latch blocks 2017-12-27 14:51:17 -08:00
Cary R f17992bcd0 Report the lines that have delay or event control in an always_comb/ff/latch process 2017-12-06 00:22:43 -08:00
Cary R cb0ffd734e Check to see that always_comb/ff/latch do not have delays/events 2017-12-05 22:10:43 -08:00
Cary R 575aa9b0fb Fix spelling in always_comb 2017-12-03 20:17:42 -08:00
Cary R 84d0df8a8a Pass to the targets if an implicit T0 trigger event is needed. 2017-12-03 20:17:42 -08:00
Cary R 585a0232cb Add preliminary support for always_comb, always_ff and always_latch 2017-11-20 07:50:05 -08:00
Martin Whitaker fd807a7700 Rework handling of timescales in parser.
This implements and enforces the full set of rules for determining
timescales in SystemVerilog. The previous relaxation of the rules
that allowed timescales to be redefined within the compilation unit
scope has been removed. Time unit and precision redeclarations are
now recognised after a nested module declaration.
2017-11-05 17:50:05 +00:00
Martin Whitaker 9382d22063 Factor out common code for warning about inconsistent timescales.
Also reword the warning for SystemVerilog, where `timescale is not
the only (or indeed preferred) way of specifying timescales.
2017-11-05 09:39:21 +00: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
Mikael Tuomisalo c967ed238c Added option for ignoring errors about missing modules 2017-03-21 17:34:44 +02:00
Martin Whitaker 002f118bb5 Fix for GitHub issue #130 part 1 - null dereference when assigning int to enum. 2016-11-25 21:53:35 +00:00
Martin Whitaker 080dd0323d Fix for GitHub issue #127 - coerce output ports to inout when necessary. 2016-09-17 19:20:48 +01:00
Martin Whitaker 7bed181f68 Support timescales in design units that aren't inside a module.
SystemVerilog allows tasks, functions, and classes to be defined at the
root level or inside packages, so we can't rely on an enclosing module
being present to provide the timescale.
2016-07-22 22:48:20 +01:00
Martin Whitaker e316cc708b Fix assignment of outputs from class methods.
As for inputs, skip over the implicit 'this' parameter.
2016-07-21 19:06:21 +01:00
Martin Whitaker 20104c92c8 Fix for GitHub issue #96 - support mixed constant/variable delays in vvp.
If all three rise/fall/decay delay values are constant, we can use
the vvp .delay statement variant that takes three literal numbers.
If not, we have to use the variant that takes three net inputs. If
some of the delay values are constant, we need to create constant
drivers for those delay inputs.
2016-04-02 19:55:56 +01:00
Martin Whitaker 72bb63cf42 Variable initialization blocks should be unamed.
Also add file/line info to initial process.
2016-03-19 14:21:10 +00:00
Martin Whitaker 54feb89bf5 For SystemVerilog, run variable initialization before main simulation starts. 2016-03-19 13:46:09 +00:00
Martin Whitaker 635adfc01e Fully support variable initialization in tasks/functions/named blocks. 2016-03-19 13:04:38 +00:00
Martin Whitaker c4b3f256af Don't mislabel signals as ports when casting port connections.
The original signal should retain the port type. Moving it to the cast
signal was confusing the vlog95 and stub targets.
2016-03-12 23:17:54 +00:00
Martin Whitaker a7066e3686 Fix expression/operator type for compressed assignment/shift. 2016-02-23 20:57:30 +00:00
Martin Whitaker 0199ad129d Fix expression type for compressed assignment statements.
A compressed assignment statement should give exactly the same
result as the equivalent uncompressed statement. This means
that the type (signed/unsigned) of the LHS affects the type of
the RHS expression (unlike in normal assignments). We need to
take care that bit/part selects and concatenations are correctly
identified as unsigned values, even in the cases where they
reduce to a single whole signal.
2016-02-23 16:53:01 +00:00
Martin Whitaker 1a78784205 Removed some dead code. 2016-02-23 11:58:27 +00:00
Christian Taedcke 6d5aabd4f0 Make a few constructors explicit.
This removes cppcheck warnings.
2015-10-22 12:33:33 +02:00
Stephen Williams 81f54ec0cb Have scope auto-rename generate names that use the index numbers
In generate blocks such as for loops, there may be many generated
scopes that have the same generated name. But in these cases, there
is an index number in the hname that can be used. So do so.
2015-09-29 17:44:28 -07:00
Martin Whitaker 5dc8edef84 Fix for br991 - compiler crashes due to null statements.
The reported problem was caused by a null statement in a case statement,
which caused the check for an infinite loop to fail. Further testing
exposed more problems with null statements in loop statements - these
caused crashes earlier in elaboration.
2015-08-17 21:52:31 +01:00
Martin Whitaker e6be9dec08 Improve error reporting for unnamed module ports.
Implicit ports may be unnamed, either because the port expression
is not a simple/escaped identifier, or because there is no port
expression. To handle these cases, error messages should report
the port position as well as the port name.
2015-07-10 23:02:27 +01:00
Martin Whitaker bdd0657140 Reject default task/function arguments when parsing traditional Verilog. 2015-06-21 09:05:39 +01:00
Martin Whitaker 1d279798d8 Fix for br982 - detect and report missing output arguments in task calls. 2015-06-20 22:39:55 +01: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
Larry Doolittle 2739f83702 Spelling fixes in C and C++ comments 2015-06-04 15:00:29 -07:00