wave-28: t27c gen-verilog const-array aggregate initializer no longer emits unparseable localparam comment-only initializer (Closes #743)#744
Merged
Conversation
… emits unparseable localparam comment-only initializer (Closes #743) R-CA-1 fix: const declarations whose initializer is an array literal or struct literal previously emitted Verilog of the form localparam [31:0] mac_units = /* array ... */; which is unparseable by Yosys/iverilog (syntax error, unexpected ';'). This was the root cause of the fpga-synthesis CI failure on PR #742. This wave updates VerilogCodegen::gen_verilog_const in both the is_array and the scalar fall-through branches to detect NodeKind::ExprArrayLiteral and NodeKind::ExprStructLit children and emit a placeholder zero value with an explanatory TODO comment: localparam [31:0] mac_units = 0 /* TODO: array literal initializer not yet lowered to Verilog */; The placeholder is valid Verilog and unblocks the synthesis frontend. A future wave will implement proper lowering of aggregate initializers. Constitution checklist: L1 TRACEABILITY: Closes #743 L2 GENERATION: edits only in bootstrap/, docs/NOW.md, new bootstrap/tests/ L3 ASCII: ASCII source, English doc-comments L4 TESTS: 2 new #[test]s in bootstrap/tests/verilog_const_array.rs, both passing locally (2 passed; 0 failed) L5 TRINITY: numeric kernel untouched; phi^2 + 1/phi^2 = 3 preserved L6 SPEC/KERNEL: zero changes under specs/, coq/, trios-coq/, proofs/, conformance/, architecture/, rings/, gen/ L7 NO BASH: no new *.sh files Files: - bootstrap/src/compiler.rs (+50 / -2) - bootstrap/tests/verilog_const_array.rs (+173 new) - docs/NOW.md (+16 wave-28 section) Closes #743
2426e32 to
3783ad9
Compare
|
📓 NotebookLM Notebook linked to this PR
This notebook contains session context, decisions, and artifacts for this work. |
gHashTag
pushed a commit
that referenced
this pull request
May 23, 2026
…begin (R-VD-1 fix) (Closes #745) R-VD-1 fix: Verilog-2005 forbids variable declarations inside procedural blocks. The previous emitter wrote `integer _bench_cycles = 0;` between `initial begin` and `end`, which Yosys/iverilog reject with "syntax error, unexpected TOK_INITIAL". This was observed on uart.v:213 in the CI log of PR #744 (Wave 28 R-CA-1 fix unblocked mac.v and exposed this next downstream emitter bug). This wave updates the bench-section loop in VerilogCodegen::gen_verilog (bootstrap/src/compiler.rs around line 3721) to: 1. Emit a module-scope `// synthesis translate_off ... translate_on` band containing one `integer _bench_<sanitized_name>_cycles = 0;` declaration per bench, BEFORE any `initial begin`. 2. Inside each `initial begin ... end` block, only assign and use the pre-declared counter; never re-declare it. Each counter gets a unique per-bench sanitized name to avoid collisions when a module contains multiple benches. Before: initial begin : uart_tx_ready_latency_bench // synthesis translate_off $display("[BENCH] uart_tx_ready_latency : starting"); integer _bench_cycles = 0; // <-- R-VD-1 violation ... end After: // synthesis translate_off integer _bench_uart_tx_ready_latency_cycles = 0; integer _bench_uart_rx_ready_latency_cycles = 0; integer _bench_uart_reset_latency_cycles = 0; // synthesis translate_on initial begin : uart_tx_ready_latency_bench // synthesis translate_off $display("[BENCH] uart_tx_ready_latency : starting"); _bench_uart_tx_ready_latency_cycles = 0; ... end Constitution checklist: L1 TRACEABILITY: Closes #745 L2 GENERATION: edits only in bootstrap/, docs/NOW.md, new bootstrap/tests/ L3 ASCII: ASCII source, English doc-comments L4 TESTS: 2 new #[test]s in bootstrap/tests/verilog_initial_decl.rs, both passing locally (2 passed; 0 failed). Wave 27 regression test still green (2 passed; 0 failed). L5 TRINITY: numeric kernel untouched; phi^2 + 1/phi^2 = 3 preserved L6 SPEC/KERNEL: zero changes under specs/, coq/, trios-coq/, proofs/, conformance/, architecture/, rings/, gen/ L7 NO BASH: no new *.sh files Files: - bootstrap/src/compiler.rs (single hunk, bench section) - bootstrap/tests/verilog_initial_decl.rs (+225 new) - docs/NOW.md (+wave-29 section, date bumped) Closes #745
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
R-CA-1 fix in t27c VerilogCodegen.
Before this PR, const declarations whose initializer was an array literal or struct literal emitted unparseable Verilog of the form:
Yosys/iverilog reject this with syntax error, unexpected ';'. This was the root cause of the fpga-synthesis CI failure on PR #742.
This PR updates
VerilogCodegen::gen_verilog_const(in both the is_array branch and the scalar fall-through branch) to detectExprArrayLiteralandExprStructLitchildren, and emit a placeholder zero value with an explanatory TODO comment:The placeholder is valid Verilog and unblocks the synthesis frontend on
mac.v. A future wave will implement proper lowering of aggregate initializers.Before / After on line 21 of
mac.vBefore:
After:
Tests
Two new
#[test]s inbootstrap/tests/verilog_const_array.rs:r_ca_1_emitter_does_not_emit_comment_only_initializer— synthetic spec asserting nolocalparam ... = /* ... */;pattern is emitted.r_ca_1_emitter_on_real_mac_spec— regression test that runs the emitter onspecs/fpga/mac.t27and asserts the same.Local result: 2 passed; 0 failed. Wave 27 tests (
verilog_r_si_1) also still pass post-rebase: 2 passed; 0 failed.CI delta vs Wave-27 baseline (HONEST)
Confirmed by CI on commit 3783ad9:
mac.vnow parses through Yosys successfully — the synthesis log shows "Generating RTLIL representation for module ZeroDSP_MAC ... Successfully finished Verilog frontend" — the R-CA-1 fix worked end-to-end on the real spec.However
fpga-synthesisis still red because Yosys then fails onuart.v:213withsyntax error, unexpected TOK_INITIAL. Root cause: the emitter placesinteger _bench_cycles = 0;declarations insideinitial begin ... endblocks, which Verilog-2005 forbids (variable declarations must be at module scope). This is a separate emitter bug (call it R-VD-1: variable-declaration-inside-initial-block) distinct from R-CA-1, exposed because the R-CA-1 fix unblockedmac.vand let synthesis proceed to the next file.R-VD-1 is out of scope for this PR (Wave 28 was scoped to R-CA-1 only) and will be the target of a follow-up wave.
Out of scope (explicit, honest)
integer X = 0;insideinitial beginblock inuart.v:213and analogous bench blocks elsewhere. Separate emitter fix.pip install sbyno matching distribution (infrastructure).error: unexpected argument '--board' found(CLI drift, infrastructure).0 + TODOplaceholder preserves symbol existence and makes the gap explicit. Real lowering needs an HIR-level refactor with consistent flattened-name generation (e.g.cells[i].accumulator -> cells_i_accumulator).Constitution checklist
bootstrap/,docs/NOW.md, newbootstrap/tests/#[test]s, passing locallyspecs/,coq/,trios-coq/,proofs/,conformance/,architecture/,rings/,gen/*.shfilesCloses #743