Repository navigation
fpga(wasm_module): load a whole .wasm image: LEB128 pairs, section walk, function table, exports, data segments (Closes #12201) - #12278
Conversation
…aw tables that landed without rows (Closes #12051) Both reached master without rows (#11864, #11867), so the ratchet read them as NEW and the fpga-conformance step has been red on master since (run 40109127962: 431 against 276; 276 + 6 + 149 = 431, no other module moved). The note under the notes mark records the measured shape of each count: one ROWS line with 149 unsized zeros, and src_len unbound in 4 fns plus the 2 condition lines derived from them. No bless, no spec change, no gate change. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…7os, so fpga-lint and the elab ratchet pass (Refs #12171, Refs #12051) fpga-lint has been red on master since #10949 landed hdmi_grab (2026-10-22): gen-verilog copies a t27 char literal verbatim, Verilog reads '0 as an unsized literal, and yosys stopped at line 88 of hdmi_grab.v. Behind that line the same file carried its libc host part (getenv, fork, execve, fopen, main), which cannot be Verilog either, so a compiler fix alone would have moved the error, not removed it. #12171 keeps the compiler side open; this is the spec side. - specs/fpga/hdmi_grab.t27: the ten characters the checker compares bytes against are consts (CH_0 .. CH_SP), one home each; no char literal is left. The host tail (HG_BUF/HG_LIST/HG_CMD/HG_PATH, hg_cat, hg_env, hg_sh, hg_slurp, hg_path, main) left the file. test-report: 14 tests, 14 pass, 0 vacuous. - specs/t27os/hdmi_grab_main.t27 (new, module T27osHdmiGrabMain): that host tail, verbatim, importing hg_* / V_PASS / CH_0 from fpga::hdmi_grab by use, the way plist_main.t27 imports install/release. t27c gen splices the imports into one .zig (use_resolve.rs); zig build-exe -lc builds it (1.9 MB binary, no diagnostics). Two tests on the two helpers it adds (frame path, byte copy): 2 pass, 0 vacuous. - tools/elab_baseline.txt: hdmi_grab 57 -> 5 (431 -> 379), note dated 2026-10-25. The 5: 4 x pixel_at taken by use from vga_text_core (gen-verilog binds no imports) and 1 x nd_len, an unsized array param (#2410). Measured on the regenerated hdmi_grab.v with a master-equivalent t27c: yosys -p "read_verilog -sv -DSIMULATION hdmi_grab.v; hierarchy -top fpga_hdmi_grab" exits 0; grep -c "\$signed('" = 0; iverilog -g2012 -DSIMULATION: 5 error lines without the summary line, as the ratchet counts. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…lk, function table, exports, data segments (Closes #12201) The loader walks one module held in a [SRC_MAX]u8 array plus an explicit src_len and returns a ModuleDesc: per-function code ranges and locals vectors, the import function count, exports (name offset, length, kind, index), data segments as (destination, source offset, length) triples, memory and table limits, the start function, and the global and element payload ranges. Failures are named codes: ERR_BAD_MAGIC, ERR_BAD_VERSION, ERR_TRUNCATED, ERR_TOO_MANY, ERR_MALFORMED, ERR_UNSUPPORTED. Never indexes past the array. LEB128 u32, s32 and s33 readers return a (value, n) struct under the 5-byte limit. No new function takes a slice; the existing uleb_read and sleb32_read stay. Struct locals born in loops and branches are declared once at the top of the function body and assigned inside, because gen-verilog hoists only top-level locals. 15 new tests (21 in the spec): the spec appendix LEB vectors, four hand-encoded modules with offsets counted by hand, and the four error codes. Refs #9367; see Trinity-S-AI-DNA/trinity-fpga#917 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Summary by t27-beesChecked by the t27 compilert27c parse, parse-complete and typecheck on each changed .t27 file at
Read by the modelThis PR adds a complete WebAssembly module loader ( Worth a look
Read: 1 files, +861 -3, the whole diff. Head |
PR DashboardGenerated at: 2026-10-25 06:48:04 UTC
Summary
Seal Status
|
Closes #12201. Refs #9367 (WASM-on-AX7203 tracker). Epic: see Trinity-S-AI-DNA/trinity-fpga#917.
What
DOOM ships as one
.wasmimage; before this PRspecs/fpga/wasm_module.t27could read a LEB128 pair, check the 8-byte header and step to the next section, and nothing else. This PR adds the loader:load(src, src_len)walks a whole module held in a[SRC_MAX]u8array and returns aModuleDescwithsec_function,sec_code,func_lookup),sec_import,sec_limits,limits_read),export_findby name (sec_export),sec_data),sec_start,sec_counted),ERR_BAD_MAGIC,ERR_BAD_VERSION,ERR_TRUNCATED,ERR_TOO_MANY,ERR_MALFORMED,ERR_UNSUPPORTED.The array readers
leb_u32,leb_s32,leb_s33return a (value, n) struct under the 5-byte limit and never index pastsrc_len. No new function takes a slice; the existinguleb_readandsleb32_readstay. One spec file changes, nothing else: no baseline edit, no seal, nogen/.15 new tests (21 in the spec): the spec appendix LEB vectors, four hand-encoded modules with every offset counted by hand (minimal module with one function and
mainexported as 0, body at 0x41 of length 4; a data segment module; an import module where function 0 is the import; limits plus a start function), and the four error codes.Measured (commands as run, 2026-10-25, master-built t27c)
t27c test-report specs/fpga/wasm_module.t27t27c gen-verilog specs/fpga/wasm_module.t27iverilog -g2012 -DSIMULATION -o /dev/null wasm_module.vUnable to bind ... src_leninuleb_read,sleb32_read,header_ok,next_section; this is the class the baseline rowwasm_module 6already records, so the row is unchangedyosys -q -p "read_verilog -sv -DSIMULATION wasm_module.v; hierarchy -top fpga_wasm_module"python3 tools/dupe_scan.pygit diff --stat origin/masterspecs/fpga/wasm_module.t27, +861 -3Not measured: nothing was synthesised or flashed. The module is loaded from an array in simulation; the UART or flash path that fills that array on the AX7203 is the next step, not this one. Until a bitstream is loaded with
openFPGALoader -c digilent_hs2and the UART answers, every run is a simulation.Disclosure
The first shape of this spec declared its struct locals with untyped
const x = call(...)insidewhileandifbodies and elaborated with 82 error lines. Declaring the same 20 locals once at the top of each function as a typedvarwith a zero struct literal, and assigning inside the block, brought it to the 6 above with no change to the tests. That is a gen-verilog gap, not a property of the loader; it is filed as #12277 with the before/after counts, and the spec header says why the locals sit where they do.Next on this path:
wasm_board_ax7203takes theModuleDesc(code ranges, exports, data segments into linear memory from #12202) and the UART loader fillssrc.🤖 Generated with Claude Code