Commit Graph

10542 Commits

Author SHA1 Message Date
Cary R. 78750c51d0
Merge pull request #1402 from larsclausen/real-unary-minus-opcode
vvp: Add opcode for unary real minus
2026-06-22 10:00:17 -07:00
Lars-Peter Clausen 0e7c62d579 Add regression tests for unary real minus special values
Check that unary real minus preserves the sign or bit pattern for zero,
NaN, and infinity. Each test starts with the positive value, negates it,
and then negates the result back to the positive value.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-22 07:43:02 -07:00
Lars-Peter Clausen 5311c0cd38 vvp: Add opcode for unary real minus
Currently the vvp target emits unary real minus as `0.0 - value`.
This is not the same operation for all real values. It loses the
negative zero result for `-(+0.0)` and does not reliably flip the sign
bit for NaN values whose bits are visible through `$realtobits`.

Add `%neg/wr` and use it for unary real minus. This performs a direct
negation of the real stack value, so zero, NaN and infinity all use the
same operation as unary minus instead of a binary subtraction from zero.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-22 07:43:02 -07:00
Cary R 8c7f8f3f7b Fix gold file to fix error message change 2026-06-21 23:04:23 -07:00
Cary R 1babbc0c92 Fix segmentation fault when the input file is missing 2026-06-21 22:53:15 -07:00
Cary R. e9bc3488fb
Merge pull request #1401 from larsclausen/fix-bad-member-lval-proc-crash
Handle bogus member l-value paths
2026-06-21 21:12:43 -07:00
Cary R. f472a77e3a
Merge pull request #1400 from larsclausen/fix-lval-indexed-part-invalid-base-crash
Handle invalid l-value indexed part select bases
2026-06-21 21:11:37 -07:00
Cary R. 8c27786a27
Merge pull request #1398 from larsclausen/vlog95-unsigned-concat-context
tgt-vlog95: Use concatenation for unsigned expression contexts
2026-06-21 21:09:50 -07:00
Cary R. e31c441dbe
Merge pull request #1387 from flaviens/patch-2
Preserve sign of negative zero
2026-06-21 21:07:05 -07:00
Cary R. ff0b269ce9
Merge pull request #1397 from larsclausen/draw-net-input-mux-array-port
tgt-vvp: Avoid interleaving array ports into mux output
2026-06-21 21:05:16 -07:00
Flavien Solt c53e4245b9 Add regression test for negative zero sign preservation
Check that the vvp code generator emits a -0.0 real constant with its
sign bit set, so the compiled value matches the runtime real value. The
sign used to be detected with (value < 0), which is false for IEEE 754
-0.0, and a -0.0 constant was turned into +0.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 10:38:26 +08:00
Lars-Peter Clausen 3c7250eb51 Add regression test for bogus member l-values
Check that bogus member access on a procedural l-value is rejected with a
normal compile error instead of aborting during elaboration.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 18:39:21 -07:00
Lars-Peter Clausen 9fb607d98e Add regression test for indexed part select l-value bases
Check that an invalid indexed part select base on a procedural l-value is
reported as a normal compile error instead of crashing after the bind error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 18:39:21 -07:00
Lars-Peter Clausen eaa7197602 Handle bogus member l-value paths
Currently the procedural l-value path asserts if symbol lookup leaves a
member tail for a variable that is not a struct or class. For example,
`r.bad = 1'b1;` where `r` is a scalar variable aborts during elaboration
instead of reporting a normal error.

Report an error for the leftover member path before the assertion. This
matches the r-value path behavior for the same kind of invalid member access.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 18:39:21 -07:00
Lars-Peter Clausen 9004d10df4 Handle invalid l-value indexed part select bases
The l-value indexed part select path elaborates the base expression with
`elab_and_eval()`. If the base expression can not be bound this returns a
nullptr, but the l-value path dereferenced it while checking the expression
type. For example, `a[does_not_exist -: 2] = 2'b00;` reported the bind error
and then crashed.

Return early when base elaboration fails. This matches the r-value indexed
part select path and leaves the existing bind error as the reported
elaboration error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 18:39:21 -07:00
Lars-Peter Clausen 4e168a4d1f ivtest: Detect execution errors in vvp_reg.py
Currently vvp_reg.py uses `returncode >= 256` to distinguish execution
errors from ordinary compile or simulation failures. That matches the encoded
status returned by wait(), but subprocess.run() does not expose that value. Its
returncode is the decoded process exit status, or `-N` if the process was
terminated by signal N. Shell wrappers can also report signal termination as
`128 + N`.

As a result a compiler crash can be reported as `-11` or `139`. Both values
pass the old check and a CE test can be accepted as a normal compiler error.

Treat negative return codes and return codes greater than or equal to 128 as
execution errors before accepting CE and EF results. Also make sure that CE gold
mismatches are reported as failures.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 17:23:52 -07:00
Lars-Peter Clausen e75b0d7968 tgt-vlog95: Use concatenation for unsigned expression contexts
The vlog95 backend currently emits `$unsigned()` when it needs to create a
self-determined unsigned expression context. `$unsigned()` is part of the
optional signed expression support in this backend and is only available when
the signed support flag is enabled.

Concatenation is part of the baseline Verilog-95 output and also creates a
self-determined unsigned expression context. Use `{expr}` for the unsigned case
and keep using `$signed()` when a signed context is needed.

Remove `-pallowsigned=1` from the existing vlog95 regression tests that now
pass without the optional signed support flag.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 12:48:00 -07:00
Lars-Peter Clausen 167a6bbcdb Add regression test for case muxes with array word inputs
Check that synthesized case statement muxes can use array words as inputs.
This used to generate invalid VVP because .array/port statements were emitted
in the middle of .functor statements.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 11:44:15 -07:00
Lars-Peter Clausen a5bf5e145f tgt-vvp: Avoid interleaving array ports into mux output
Currently draw_lpm_mux_nest() calls draw_net_input() while printing a
.functor statement. For array word inputs draw_net_input() emits an
.array/port statement as a side effect, which interleaves the .array/port
text into the middle of the .functor line and generates invalid VVP.

draw_lpm_substitute() has the same pattern. Collect the input labels before
starting to print the consuming statement so any side-effect output appears
as a separate statement first.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 11:44:15 -07:00
Cary R. a615ee03e7
Merge pull request #1395 from larsclausen/sv-generate-class
Support classes in generate blocks
2026-06-21 10:00:54 -07:00
Lars-Peter Clausen bb8b05bb5d Add regression test for classes in generate blocks
Check that a class declared in a conditional generate block can be used.
Also check that classes declared in a generate loop get separate class scopes
for each generated instance.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 09:30:28 -07:00
Lars-Peter Clausen 7934ab9eeb Support classes in generate blocks
SystemVerilog allows class declarations as module and generate items.
Currently a class declaration in a generate block triggers an assert because
`pform_push_class_scope()` only records classes in `PScopeExtra` scopes.

Add class storage to `PGenerate` and elaborate those classes like module and
package classes. When registering task, function or class declarations, only
use the current `PGenerate` object as the target if it is also the current
lexical scope. This distinction matters for generated classes because
`pform_cur_generate` remains set while the class body is parsed, but the
current lexical scope has changed to the `PClass`. This records the class
declaration in the generate block while leaving methods and constructors in
the class scope.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-21 09:29:54 -07:00
Cary R. daadc38f18
Merge pull request #1394 from larsclausen/class-task-method-expression-error
Report error for class tasks used as expressions
2026-06-21 07:23:17 -07:00
Cary R. a5b9879ada
Merge pull request #1393 from larsclausen/netassignnb-dump-rval-error
NetAssignNB: Fix dump fallback for invalid rval
2026-06-21 07:21:37 -07:00
Cary R. 72833b9570
Merge pull request #1392 from larsclausen/fix-negative-packed-slice-width
Fix width calculation for packed array bounds
2026-06-21 07:20:43 -07:00
Lars-Peter Clausen 449abb6bda Add regression test for class tasks used as expressions
Check that using a class task through an object method call in expression
context reports a compile/elaboration error instead of triggering an assert.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 17:06:36 -07:00
Lars-Peter Clausen 0637afd284 Report error for class tasks used as expressions
Class object method calls in expression context call func_def() without first
checking that the resolved class method is a function. If the method is a task,
func_def() triggers an assert instead of reporting a normal elaboration error.

Check the method scope type before accessing the function definition and report
an error for tasks.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 17:06:36 -07:00
Lars-Peter Clausen c124abaa3e NetAssignNB: Fix dump fallback for invalid rval
Currently NetAssignNB::dump() prints a malformed fallback marker when
there is no rval expression. The leading '<' is missing, making it
inconsistent with the blocking assignment dump output.

Print the complete error marker.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 15:15:52 -07:00
Lars-Peter Clausen 03f1bbdd37 Consolidate net up/down part select
The methods for handling up and down part select are nearly identical
and only differ in a hand full of lines.

Consolidate them into a single method to remove the duplicated code.
This makes it easier to maintain the code and add future changes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 14:25:16 -07:00
Lars-Peter Clausen e9d3fe4ea3 Consolidate parameter up/down part select
The methods for handling up and down part select are nearly identical
and only differ in a hand full of lines.

Consolidate them into a single method to remove the duplicated code.
This makes it easier to maintain the code and add future changes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 14:25:16 -07:00
Lars-Peter Clausen 10349287a0 Add regression tests for enum typedefs in nested scopes
Check that enum literals declared by enum typedefs in generate blocks, named
blocks, tasks and functions can be referenced from the same scope.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 14:24:53 -07:00
Lars-Peter Clausen 9bc86af284 elab: Elaborate enum types in nested scopes
Enum types declared inside nested scopes are stored separately from typedefs.
The enum sets need to be elaborated when the `NetScope` is created so enum
literals are available for declarations and statements in the same scope.

Module, package and class scopes already do this. Generate, task, function and
named block scopes can also declare enum typedefs, but did not elaborate their
enum sets. Elaborate them while setting up these scopes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 14:24:53 -07:00
Lars-Peter Clausen 593a97bede vvp: Bound VPI label scanset parsing
The VPI label resolver parses word and string labels into a 32 byte
temporary buffer. The scansets used by sscanf() did not specify a width,
so malformed labels could write past the end of the buffer.

Limit the scansets to the size of the buffer.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 13:13:24 -07:00
Lars-Peter Clausen d5a16b31a1 Add regression test for empty old-style UDP table
Check that an empty old-style UDP table reports the parser error and the
invalid primitive error instead of crashing.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 13:13:05 -07:00
Lars-Peter Clausen 20a969bf38 Handle invalid old-style UDP tables
An empty old-style UDP table leaves the parsed table pointer unset after
the parser reports the table error. The old-style UDP creation path still
passed the null pointer to process_udp_table(), which crashes.

Report an invalid UDP table instead and do not register the primitive.
Also keep the new-style invalid-table diagnostic formatting consistent.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-20 13:13:05 -07:00
Cary R 4b9675abd7 Update unused function in lz4 2026-06-20 08:53:42 -07:00
Cary R 8caa3af689 Update to the latest GTKWave files. 2026-06-20 07:57:16 -07:00
Lars-Peter Clausen 6326c5b1ba Add regression test for negative packed array bounds
Check that variable selects of a packed array with negative bounds use the
correct index width and can read back assigned elements.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-19 22:08:17 -07:00
Lars-Peter Clausen 128c621e85 Fix width calculation for packed array bounds
Variable select base normalization extends the base expression to cover
the packed array bounds. The current code compared min_wid against
num_bits() of each bound, but then assigned the bound value itself to
min_wid.

For positive bounds this can make the generated index expression much
wider than required. For negative bounds the effect is much worse since
min_wid is unsigned. Assigning a negative bound converts it to a huge
width, causing elaboration to try to pad the expression to that size and
abort or run out of memory for otherwise valid variable selects.

Use the bit width of the bound instead of the bound value.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-19 22:08:12 -07:00
Flavien Solt f963322076
Preserve sign of negative zero 2026-06-19 16:00:16 +08:00
Lars-Peter Clausen de415b2f03 Add regression tests for nested function and final contexts
Check that statements that are not allowed in functions or final procedures
are still rejected when they are placed in a named block scope.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-09 21:34:34 -07:00
Lars-Peter Clausen 5b512e4f1e Preserve function and final context in nested scopes
Currently checks for statements that are not allowed in functions or final
procedures only inspect the immediate scope. If the statement is inside a
named block or a block with declarations, the current scope is the block and
the context is lost.

Make `NetScope::in_func()` and `NetScope::in_final()` preserve the context
through begin-end, fork-join and generate block scopes. Other scope types are
treated as context boundaries so function and final state does not leak across
subroutine or definition scopes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-09 21:34:34 -07:00
Lars-Peter Clausen c5c0b09ef6 Add regression tests for queue method argument count errors
Check that queue push_back(), push_front() and insert() report errors when
called with too few or too many arguments.

These tests are expected to fail as compile/elaboration errors. They also make
sure the invalid calls do not crash during elaboration while reporting the
argument count error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-09 21:33:58 -07:00
Lars-Peter Clausen aa3d804b72 Fix out-of-bounds write for missing queue method arguments
When a method argument is missing, the error path stores a nullptr in the
argument vector for that missing slot. The vector was sized from the number of
arguments that were present in the source, so calls such as `q.push_back()` or
`q.insert(0)` wrote those nullptr placeholders past the end of the vector.

Size the vector from the number of arguments required by the queue method
instead. This gives the error path slots for the missing arguments while
leaving valid calls unchanged.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-09 21:33:58 -07:00
Lars-Peter Clausen 2fc9d27190 Add regression test for multi-dimensional packed class properties
Check that multi-dimensional packed vector class properties can be emitted,
assigned, and read back through a class object.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-09 21:33:18 -07:00
Lars-Peter Clausen 1e6e69ee7f Support multi-dimensional packed vectors as class properties
Currently multi-dimensional packed vector class properties will cause an
assert and only single dimensional or scalar vectors will pass.

But just as for regular vectors there is nothing special about class
property multi-dimensional vectors as they will be represented in vector
form in vvp.

Removing the asserts allows multi-dimensional packed vectors to be used for
class properties. Indexed access to these properties is not supported yet;
that requires follow-up work to elaborate packed property selects and to
support partial stores to vector class properties.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-06-09 21:33:18 -07:00
Lars-Peter Clausen c7530dbcc1 Add regression test for assignment patterns as queue method arguments
Check that assignment patterns are evaluated in the queue element type
context when they are passed to the queue `push_front()`, `push_back()` and
`insert()` methods.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-05-31 18:32:44 -07:00
Lars-Peter Clausen e47160c6a8 Evaluate queue method arguments in assignment-like contexts
The arguments of the queue `push_front()`, `push_back()` and `insert()`
methods are passed to subroutine input ports. This makes them
assignment-like contexts with the declared argument type as target type.

Use `elaborate_rval_expr()` instead of `elab_and_eval()` for these
arguments. This evaluates the item argument with the queue element type and
the `insert()` index argument with `integer`, so target-type-dependent
expressions such as assignment patterns work and enum compatibility checks
use the queue element type.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2026-05-31 18:32:44 -07:00
Cary R. 311c22e4de
Merge pull request #1373 from MrCookieeeee/Ignore-configure-generated-files
Ignore configure generated files
2026-05-22 10:15:55 -07:00
Cary R. 2d3502f4b7
Cleanup .gitignore organization and files 2026-05-22 10:14:31 -07:00