Skip to content

fix(codegen): iverilog-clean gen-verilog + BPSK modem spec - #1250

Merged
gHashTag merged 1 commit into
masterfrom
fix/gen-verilog-on-master
Jul 1, 2026
Merged

gHashTag merged 1 commit into
masterfrom
fix/gen-verilog-on-master

Conversation

@gHashTag

@gHashTag gHashTag commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #1245. Makes t27c gen-verilog emit iverilog-compilable, simulatable RTL for datapath specs, and adds the trios-mesh BPSK modem core as specs/fpga/bpsk.t27.

Backend fixes (bootstrap/src/compiler.rs)

  1. const/var run drop — parse_const_decl now consumes the trailing ; (a stray ; made the module-body loop skip subsequent decls). uart: 1 -> 8 localparams, 31 -> 0 iverilog errors.
  2. literals — 0x/0b/_ integer literals render as decimal (valid Verilog).
  3. guarded early return — rewritten to if/else so the return is not clobbered (last-write-wins).
  4. struct-field regs — declared under the holding var name (matches field access).
  5. zero-arg functions — get an unused dummy input (Verilog forbids port-less functions).
  6. named begin blocks — Verilog-2001 forbids local decls in unnamed blocks.

Existing ExprCast cast handling kept as-is (master's validated version).

New specs/fpga/bpsk.t27 (ZeroDSP_BPSK)

BPSK serializer + Barker-13 preamble + integer correlator + threshold sync. iverilog-compiles AND simulates: 13 embedded test assertions pass; hierarchical checks give correlate(Barker)=13, inversion=-13, sidelobes -5/+5, sync gate, frame=21. uart/mac now iverilog-clean too (fpga clean 1 -> 3 of 34).

Validation

  • suite: parse / typecheck / gen(Zig/Rust/Verilog/C) 514/514.
  • No numeric/L6 change. Follow-up: committed seals for other specs whose Verilog changed need a reseal sweep (not included here to keep the diff focused).

phi^2 + phi^-2 = 3 | TRINITY

Port of the gen-verilog/parser fixes to master so datapath specs compile &
simulate: (1) parse_const_decl consumes trailing ';' -> consecutive const/var
runs no longer dropped (uart 1->8 localparams, 31->0 iverilog errors);
(2) integer literals render as decimal (0x/0b/_ -> valid Verilog); (3) guarded
early return rewritten to if/else; (4) struct-field regs named by the holding
var; (5) zero-arg functions get a dummy input; (6) function bodies use named
begin blocks. Existing ExprCast handling kept.

New specs/fpga/bpsk.t27 (ZeroDSP_BPSK, trios-mesh BPSK modem core) iverilog-
compiles AND simulates: 13 embedded test assertions pass; correlate(Barker)=13,
inversion=-13, sidelobes -5/+5, sync gate, frame=21. uart/mac clean too.

Closes #1245
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-07-01 19:07:10 UTC

Summary

Status Count
Total Open PRs 15
PRs with Failing Checks 9
PRs with All Checks Green 6
READY 4
FAILING 9
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=16664105c99c != manifest seal=49e55df6d444.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@gHashTag
gHashTag merged commit 701d79b into master Jul 1, 2026
26 of 28 checks passed
@gHashTag
gHashTag deleted the fix/gen-verilog-on-master branch July 1, 2026 19:11
gHashTag added a commit that referenced this pull request Jul 2, 2026
#1255)

Reseal every spec so suite seal-verify is green after the gen-verilog change
(#1250) shifted gen-hashes for most specs; also clears pre-existing spec-hash
drift + missing seals. Three spec pairs shared a module name and collided on
their <dir>_<Module>.json seal (FeedForward, String, malformed "[]const u8") ->
rename the second of each pair (FeedForwardNetwork / SacredGovernance /
FacultyBoard). Suite: parse/typecheck/gen(x4)/seal-verify 514/514.

Closes #1254

Co-authored-by: gHashTag <deborahnelson8788726@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
gHashTag added a commit that referenced this pull request Aug 27, 2026
* gen-c, gen: a module-level `var` is mutable (Refs #2161)

The parser records mutability in `extra_mutable`, and both backends
already branch on it for function LOCALS -- Zig `var` vs `const`, Rust
`let mut` vs `let`. The module-level paths never read it, so a `var` at
module scope was emitted as a constant:

    gen-c    #define counter 0     -> `counter = counter + 1` becomes
                                      `0 = (0 + 1)`, which is not C
    gen      const counter: u32    -> Zig refuses the assignment
    gen-verilog  reg [31:0] counter    correct all along

gen-c now emits `static <type> <name> = <init>;` for a mutable
module-level declaration and keeps `#define` / `static const` for real
constants. Zig writes `var` instead of `const`.

Measured over the 42 specs whose C output this changes:

    C compile errors (cc -fsyntax-only -std=c11)   537 -> 277
    specs whose generated C is clean                 0 -> 19

specs/fpga/bpsk.t27 -- the BPSK modem merged in #1250 -- goes 7 errors to
0. A probe spec compiles and RUNS: two calls to a function that
increments a module-level counter print `1 2`.

Immutable constants are untouched: `const K: u32 = 7` still emits
`#define K 7`.

gen-rust is NOT fixed here, and the reason is a language question rather
than an oversight. Rust has no safe module-level mutable: `static mut`
needs `unsafe` at every access, `AtomicU32` changes the access API to
load/store, and `thread_local!` changes the semantics. All three alter
the generated interface, so which one t27 means belongs to whoever owns
the datapath. Measured first: all 43 of these specs already produce Rust
that does not compile, for reasons beyond this one, so nothing regresses
by leaving it.

Parse count unchanged at 620/746; t27c tests unchanged at 1629 passed /
6 failed.

FROZEN_HASH resealed in the same commit (M5).

* docs/now: a module-level var was a constant in three backends (Refs #2161)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gen-verilog: 5 lowering defects block iverilog-clean RTL from non-trivial specs

1 participant