summary_m2comp_step7.md 1.6 KB

m2comp step 7 — backend listing (tag: m2comp-step7)

MGen.DumpImage prints the assembled image to StdOut after every successful emit: global layout per scope (name/slot/size), the procedure table (number/address/depth), then disassembled code with resolved labels. Unknown bytes degrade to DB (never fail). A full sweep over all test sources shows zero unknowns. Suite 65/65 (61 inherited + 4 listing checks).

What was built

  • src/MGen.def/.mod: DumpImage + helpers (WrS/WrI/WrHex2/ WrHexQ/WrOp/OpLen/LabelAt). Instruction sizes: 1, 2 (u8/ext), 9 (immW/jp/jpfalse); imm0..15, signed local slots, loadParam for 03H..07H; jumps resolve to L<n> (else +rel); immW payloads as 16 hex digits.
  • Driver (compiler.frm): DumpImage after a successful EmitModule (listings already written, verdict last).
  • run_tests.sh: expect_code (compile + grep backend listing): realCmp in r_real (listing-level guard for the step-5.2 D5 fix), proc-table entry in r_proc, jpfalse in t_case, storeIndir0 in t_with.

Bugs found (all fixed, all covered)

  • immW printed 32 hex digits (nibble helper already emits two chars each — dropped the manual split).
  • 84H/85H leaves take a u8 param count (undocumented in the local table); missing size broke alignment and swallowed a label. Same class of latent defect the listing exists to catch.

Limits

  • No source-line mapping (AST nodes carry no positions — needs grammar + AST + backend work; future step).
  • Listing goes to StdOut only (one emit per run, after the per-file dumps).