Skip to content

wave-29: R-VD-1 — t27c gen-verilog emits integer declaration inside initial block (Yosys syntax error) #745

Closed

Description

@gHashTag

Summary

t27c gen-verilog emits integer _bench_cycles = 0; inside an initial begin ... end block. Verilog-2005 forbids variable declarations inside procedural blocks (must be at module scope), so Yosys rejects the generated uart.v (and other specs with bench blocks) with:

uart.v:213: ERROR: syntax error, unexpected TOK_INITIAL

This is the next downstream emitter bug exposed by the Wave 28 R-CA-1 fix (PR #744). It blocks the fpga-synthesis CI check from going green.

Location

bootstrap/src/compiler.rs, in the "Section: Bench → initial blocks with timing" loop (around line 3729):

for b in &benches {
    self.write_line(&format!(
        "initial begin : {}_bench // synthesis translate_off",
        Self::sanitize_identifier(&b.name)
    ));
    self.indent();
    self.write_line(&format!("$display(\"[BENCH] {} : starting\");", b.name));
    self.write_line("integer _bench_cycles = 0;");   // <-- R-VD-1 violation
    ...
}

Emitted (broken)

initial begin : uart_tx_ready_latency_bench // synthesis translate_off
    $display("[BENCH] uart_tx_ready_latency : starting");
    integer _bench_cycles = 0;                     // <-- not allowed here
    $display("[BENCH] uart_tx_ready_latency : %%0d cycles", _bench_cycles);
    $display("[BENCH] uart_tx_ready_latency : DONE");
end // synthesis translate_on

Proposed fix

Hoist the integer declaration to module scope before the bench-block group, with a per-bench unique name to avoid collisions:

// Benchmark counters (simulation only)
integer _bench_uart_tx_ready_latency_cycles = 0;
integer _bench_uart_rx_ready_latency_cycles = 0;
integer _bench_uart_reset_latency_cycles    = 0;

initial begin : uart_tx_ready_latency_bench // synthesis translate_off
    $display("[BENCH] uart_tx_ready_latency : starting");
    $display("[BENCH] uart_tx_ready_latency : %%0d cycles", _bench_uart_tx_ready_latency_cycles);
    $display("[BENCH] uart_tx_ready_latency : DONE");
end // synthesis translate_on

This is valid Verilog-2005 and parses cleanly through Yosys/iverilog.

Acceptance

  • uart.v regenerates with no integer ... = ...; lines inside any initial begin ... end block.
  • Two regression tests in bootstrap/tests/verilog_initial_decl.rs:
    1. Synthetic spec: assert emitter never emits integer inside an initial begin block.
    2. Real uart.t27: same assertion against the real spec.
  • fpga-synthesis CI gate parses past uart.v:213 and proceeds further (or goes green if no other emitter bugs surface).

Constitution

  • L1: Closes #N (this issue)
  • L2: edits only under bootstrap/, docs/NOW.md, new bootstrap/tests/
  • L3: ASCII source
  • L4: 2 new tests
  • L5: numeric kernel untouched
  • L6: zero spec/kernel changes
  • L7: no new *.sh

Activity

  1. added 2 commits that reference this issue on May 23, 2026
    d3d5f59
    8d9744b
  2. added 6 commits that reference this issue on Jun 1, 2026
    c0263d2
    29f8456
    d4dcecd
    8cca334
    b396587
    316c471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions