Commit Graph

9051 Commits

Author SHA1 Message Date
martinwhitaker 18cc3b91a1
Merge pull request #573 from larsclausen/short-circuit-logical-operator
Short circuit logical operator
2021-12-31 09:16:35 +00:00
Lars-Peter Clausen 957e3d482f Short circuit logical operator to constant if possible
If the left-hand side of a logical operator is a constant that causes the
right-hand side to be short-circuited the right-hand side can be discarded
even if it is not constant.

In this case replace the expression by a constant.

E.g.
 * `0 && expr` will be replaced by a constant 0.
 * `1 || expr` will be replaced by a constant 1.
 * `0 -> expr` will be replaced by a constant 1.

Note that it is not possible to replace the expression by a constant if
only the right-hand side is a constant, even when the value of the
expression is constant. The left side still has to be evaluated for side
effects.

E.g. it is known at elaboration that `a++ && 0` will yield 0, but the
increment on `a` has to be executed regardless.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2021-12-30 19:05:18 +01:00
Lars-Peter Clausen d4334139d3 tgt-vvp: Short circuit logical operators
Section 11.4.7 of the SystemVerilog LRM states

```
The && and || operators shall use short circuit evaluation as follows:
  - The first operand expression shall always be evaluated.
  - For &&, if the first operand value is logically false then the second operand shall not be evaluated.
  - For ||, if the first operand value is logically true then the second operand shall not be evaluated.
```

vvp currently evaluates both operands of a logical operator. This works
fine as long as the right-hand side does not have a side effect. But if it
has the result might be incorrect.

E.g. for `a && b++` `b` must not be incremented if `a` evaluates to false.

The Verilog LRM mentions that it is allowed to short circuit any expression
"if the final result of an expression can be determined early". But there
is no requirement to do so.

So the new and the old behavior are both correct implementations in
Verilog.

Use the new behavior in both Verilog and SystemVerilog mode to make sure
the behavior is consistent when an expression has side effects.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2021-12-30 18:56:39 +01:00
Martin Whitaker a6e71f30d6 Fix CI on Windows (2nd attempt). 2021-12-30 11:05:11 +00:00
Martin Whitaker 9bcee6c2c8 Fix CI on Windows.
autoconf has been removed from the MSYS2 base-devel group.
2021-12-30 10:33:41 +00:00
Lars-Peter Clausen 2fa7260a4c tgt-vvp: Consolidate vec4 logical `and` and `or` generation
The code for generating the logical `and` and `or` operators is identical
except for the final opcode to combine the two results.

Consolidate this into a single function to reduce the code a bit.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2021-12-29 16:20:22 +01:00
Michael Singer 6c60851558 Fix unique0 keyword/token mapping 2021-12-26 06:47:37 +01:00
Martin Whitaker 668f9850bc Warn when a negative value is assigned to a genvar (-g2001 only) (issue #567) 2021-12-13 21:30:31 +00:00
Martin Whitaker e1d6fd78f4 Fix genvar increment/decrement operations to be signed (issue #568) 2021-12-13 20:45:57 +00:00
Martin Whitaker 67b9374c69 Change compiler's generate loop counter from int to long.
This matches the type of the values assigned to it, and exposes a bug that
was previously only showing up under Windows.
2021-12-13 20:28:41 +00:00
Martin Whitaker 71c36d1289 Improve error message on assignment to an array or array slice (issue #562).
This is valid SystemVerilog, but not something we support yet.
2021-11-12 21:43:24 +00:00
Martin Whitaker 61aed6882c Fix an assertion failure when a variable name is replicated in the same list. 2021-11-11 19:02:40 +00:00
Martin Whitaker 3c23180af3 Remove unreachable code.
pform_get_or_make_wire() should always return a valid pointer. Replace the
existing unreachable code with an assertion.
2021-11-11 19:02:40 +00:00
Cary R c6ef2ba809 Fix valgrind compile to work with new using std reorg 2021-11-10 18:21:14 -08: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 dbf55da0f5 Clean up indentation. 2021-11-05 21:49:51 +00: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 9cc09b8513 Remove "using namespace std" from vvp header files and fix the fallout. 2021-11-04 17:02:07 +00:00
Martin Whitaker 23390c1ba3 Remove "using namespace std" from tgt-vhdl header files and fix the fallout. 2021-11-04 17:01:16 +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 19e44d79ec Revert "Reorder header file inclusion to avoid "byte" name collision."
This reverts commit 4c4b09947f.

This didn't completely fix the problem, so try a different tack.
2021-11-04 10:58:49 +00:00
Martin Whitaker 4c4b09947f Reorder header file inclusion to avoid "byte" name collision.
When using the latest mingw64 header files, rpcndr.h (which is indiretly
included by windows.h) defines a type named "byte" which collides with a
definition in cpp_type_traits.h (included indirectly by the STL). This is
only a problem if "using namespace std" is declared prior to including
windows.h.
2021-11-03 18:36:13 +00:00
Martin Whitaker 829d361b17 Fix null pointer warning from latest GCC. 2021-11-03 18:07:15 +00:00
Martin Whitaker 3dda39bce3 Handle run-time out-of-bounds access for wire real arrays (issue #556). 2021-11-03 17:50:45 +00:00
Cary R e3c2234893 Update fstapi.c to the latest from GTKWave 2021-10-26 19:41:29 -07:00
Martin Whitaker ef01dd1e81 Fix signedness of non-ANSI port declarations (issue #540).
For non-ANSI port declarations that have both a port declaration and
a corresponding variable declaration, the signed attribute may be
attached to either the port declaration or the variable declaration,
or both declarations.
2021-09-10 23:09:03 +01:00
Martin Whitaker 7ee7a48310 Check that a genvar is not shadowed when used in a generate loop construct.
This also ensures the same genvar cannot be used in two nested loops
(issue #533), because the implicit localparam with the same name
shadows the genvar declaration.
2021-08-04 14:35:38 +01:00
Martin Whitaker cefcffecda Include named events in checks for name collisions. 2021-08-04 14:14:09 +01:00
Martin Whitaker a17557575d Include typedefs in checks for name collisions.
This requires us to make a copy of the typedefs map when adding it to
a NetScope object, because the pform data is deleted before we are
finished with it.
2021-08-04 14:00:33 +01:00
Martin Whitaker 7445b424f1 Avoid name collisions when naming unnamed generate blocks.
As specified in the IEEE standard, the automatically generated name
must not conflict with any explicitly declared name (not just scope
names).
2021-08-04 12:07:52 +01:00
Martin Whitaker ceb2581368 Fix naming of unnamed generate blocks (issue #528)
The IEEE standard specifies that the numbering of generate blocks
restarts at 1 in each new scope, and that the 'else' part of an 'if'
construct is part of the same constuct, so has the same number.
2021-08-04 11:58:18 +01: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 389e2a3a94 Use a list instead of a set for storing the potential package imports.
This eliminates some indeterminism in the error messages, which was
causing occasional failures in CI. We don't expect this list to be
very large, so the O(n) insertion time should not be a problem.
2021-07-31 18:36:18 +01:00
Martin Whitaker 83d9b5deda Rework PEIdent::test_width() to use new-style symbol_search().
This fixes issue #527.
2021-07-31 14:18:52 +01:00
Martin Whitaker e547a8355d Rework PEIdent::elaborate_expr() to use new-style symbol_search(). 2021-07-31 13:19:12 +01:00
Martin Whitaker b9863b4fde Store user-supplied path to object in symbol_search results.
(wanted by next commit)
2021-07-31 12:42:53 +01:00
Martin Whitaker 3b1b611a18 Fix evaluation of out-of-bounds bit/part-select in constant function (issue #531). 2021-07-30 20:34:47 +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 6b127432da Cleanup space 2021-06-20 22:51:32 -07:00
Cary R c07a6ec8fd Correctly dump case items 2021-06-20 22:39:43 -07:00
Cary R eb5b04626d Handle elaboration tasks with a single string argument 2021-06-20 22:03:55 -07:00
Cary R 31e3155426 Fix fprintf display type 2021-06-17 22:46:24 -07:00
Cary R bb2c51a174 Update fstapi files to latest from GTKWave 2021-06-17 21:41:36 -07:00
Martin Whitaker 1f8876be1c Fix .event/or connectivity when inputs have multiple fanout (issue #508).
The old implementation connected all inputs to the same vvp_net_t port,
on the basis that we don't care about the data values or what port they
arrived on. But if one or more of the inputs fans out to multiple nets,
the chains get tangled, which either results in connections being lost
or inappropriate connections being made, depending on the order that
the inputs are linked.

This could have been fixed by using a standard wide functor. But as we
don't care about the data values, that would be unnecessary overhead.
We just need separate vvp_net_t objects to handle the input connectivity
and can keep using a single shared functor.
2021-05-18 08:36:04 +01:00
Martin Whitaker 711623f682 Remove redundant elab_and_eval_lossless(). 2021-05-16 17:31:59 +01:00
Martin Whitaker a040ddc070 Do not force lossless calculation for index expressions (issue #515)
The standard Verilog expression bit length rules must be used.
2021-05-16 17:19:13 +01:00
Miodrag Milanovic 1341dee0e6 Fix for cross compile build 2021-05-12 09:16:11 +02:00
Martin Whitaker cf0bf4d9aa Record the actual data type when a module port has an enum type.
This fixes assignment compatibility problems (issue #498).
2021-04-28 20:18:04 +01:00
Martin Whitaker a7cb93842e Fix waveform dumpers to use vpiInstance when dumping all variables. 2021-04-21 09:23:19 +01:00
Martin Whitaker d2521878d7 Add support for vpiInstance as the type code in calls to vpi_iterate().
This is needed for the waveform dumpers now that vpi_iterate(vpiModule, NULL)
has been ficed to only return modules.

This includes recognising vpiProgram and vpiInterface, although the compiler
and vvp currently incorrectly classify them as modules.
2021-04-21 09:01:50 +01:00