5 Commits
Author SHA1 Message Date
Phillip Heller 1b953642e9 bytecode: add cod_file_load_buf (parse a .cod/.pgm from memory)
- Factor cod_file_load's parsing into cod_file_load_buf(data, size, name_hint),
  which does not take ownership of the buffer; cod_file_load reads the file and
  delegates. Lets callers parse objects loaded from an archive (STAGE.DAT) or
  other in-memory sources without a temp file. Behavior is unchanged.
2026-08-13 09:19:46 -06:00
Phillip Heller 1575bdb4c8 decompiler: don't let a mid-instruction CALL target split its procedure
- find_procedures collected a procedure entry from every CALL's jump_target (skipping only offset-0 calls), so a CALL whose target lands mid-instruction - a known compiler defect, e.g. QALCALLF's second CALL points inside a CJGT - registered a bogus entry at that address. The phantom boundary truncated the enclosing procedure right after the CALL, dropped the rest of its body, and emitted empty/misattributed procs.
- Skip CALL targets that are not on an instruction boundary (addr_is_instruction), the same condition the emitter uses to recover them as _invalid_target. The trailing instructions now stay in their true procedure.
- Extend call_recovery test: assert no bogus empty proc and that the post-CALL body (SUBSTR/LINK block) stays in the same procedure.
2026-08-13 08:58:16 -06:00
Phillip Heller 4436cfcfd6 compiler: fix MAKE_FORMAT mode-byte buffer overflow
- gen_make_format's extra-mode-byte buffer was uint8_t[8], but a format spec needs ceil((3*fields+1-8)/8) mode bytes - 9 once the operand count reaches 79 (>= 24 fields). With an extended-index destination forcing complex encoding, the write and emit both indexed extra_modes[8+], a stack-buffer-overflow (ASan/UBSan confirmed at codegen_verbs.c:389) whose garbage byte became a phantom mode byte and desynced the operand stream (bogus immediate + spurious BREAK on disassembly).
- Size the buffer for the real maximum: the count byte is a uint8_t, so field_count <= 255 -> total_operands <= 766 -> at most 95 extra mode bytes. Fix the symmetric latent cap in the decoder (mode_bytes[32] -> 96).
- Resolves the desync bytes in ceo_game FGCGHFHT (51 operands, dest RDA201); those offsets now match the shipped object. Add positive test mkfmt_ext_dest_many (extended dest + 26 fields).
2026-08-12 22:18:36 -06:00
Phillip Heller ca897ac080 Batch: compiler/formatter work in progress, decompiler TODO
- TODO.md: decompiler emits a truncated vars list when DATA contains a
  struct overlay (ENPHSTAC), breaking best-effort round-trip; fix is to
  size vars from the highest referenced register or the COD data-area
  size.
- Compiler/formatter/lexer modifications committed as-is with this batch.
2026-08-01 18:03:39 -06:00
Phillip Heller a432ef5b5f Initial commit. 2026-06-21 11:34:08 -06:00