790 Commits
Author SHA1 Message Date
Irmen de Jong f7529dbd2a Fix direct struct instance array fields on IR backends; drop debug prints 2026-11-22 16:57:06 +01:00
Irmen de Jong 5dcf746d98 Fix struct instance access on IR/new6502 backends and namespaced struct types 2026-11-22 16:21:48 +01:00
Irmen de Jong e92a79c887 Add memory-mapped single struct instances 2026-11-21 12:29:32 +01:00
Irmen de Jong 6842239900 Support typed address-of struct instances in static initializer data
Taking the address of a direct struct instance in static initializer data
(pointer arrays and pointer-typed struct fields) worked on 6502 only. The
typed `&&` operator already provides the needed type, but the IR path broke
on targets without symbol prefixes:

- The virtual target skips symbol prefixing, so address-of symbols kept
  their plain scoped names (`main.p1`) while the struct instance storage is
  registered as `prog8_struct_instances.main_p1`. IRUnusedCodeRemover then
  crashed with "no chunk with label 'main.p1'" (only when optimizing).
  StConvert now resolves both the plain scoped form and the p8i_->p8v_
  prefixed form used on 6502 and m68k targets.

- Both symbol prefixers rebuilt PtAddressOf nodes for static initializer
  elements without their typed/msb flags; the flags are now preserved.
2026-11-20 00:52:52 +01:00
Irmen de Jong 074bc2ce91 Fix address-of references in static initializer data
`&p1` inside static initializer data (pointer arrays of struct instances
and pointer-typed struct fields) produced broken symbol references.
2026-11-19 23:35:46 +01:00
Irmen de Jong e954d8b705 Add real struct instance variables on IR/m68k and virtual targets
Allow `Point p` declarations with direct field access, initialization and
whole-struct copy (`q = p` lowers to sys.memcopy) on 32-bit and virtual
targets. 6502 targets reject with a clear error and keep using pointers or
arrays of struct instances.

Direct variables are represented as StStructInstance nodes with static
storage; field access resolves via PtrDereference and address-of/field
addresses use the struct-instances symbol labels. Adds array-literal-to-
struct-initializer lowering and avoids false frame-address-escape warnings.
2026-11-19 00:32:50 +01:00
Irmen de Jong 19a8d45a0f Fix SymbolPrefixer crash on struct-array field access in no-prefix blocks 2026-11-18 03:02:23 +01:00
Irmen de Jong a59929fa90 IR: don't truncate 32-bit pointer constants
amiga: add ECS 16-color (attached) sprite support
2026-11-17 01:35:53 +01:00
Irmen de Jong fec84d50bd m68k: fix mixed float multi-return returns and frame slot collision
- multi-value returns containing floats crashed the compiler: the FPx
  return slots were routed through the int-register store path (passing
  a -1 register number), and float forwarding ("return multi(...)") threw
  "unexpected FP return register". Route FPx through the float path and
  handle them in the generic load/store forwarding.
- the fp0 float staging register is also the first float return slot, so
  storing later float return values clobbered an already-written fp0.
  Defer the FP0-targeted float store until all other return stores are done.
- per-subroutine vreg renumbering compacted ints and floats into the same
  numbers, and the A5 frame spill slots are keyed by number only, so an
  int vreg and a float vreg could share one frame slot. Renumber floats
  into a range disjoint from the ints.
2026-11-14 14:55:13 +01:00
Irmen de Jong 0d0b565d28 m68k: fix multi-return value corruption; optimize lineclip
- m68k codegen: multi-value returns were corrupted because the caller's
  capture moves and the callee's epilogue both clobbered the return
  registers d2-d4. Record the hardware return slots on the call site,
  force-spill the transfer temporaries on both sides, and exclude a
  subroutine's own return registers from its save set.
2026-11-14 14:37:46 +01:00
Irmen de Jong 4772644056 Address codegen bug review findings
Fixes:
- M68K optimizer: prove index-register liveness before deleting scale
  instructions in optimizeIndexedPointerLea.
- M68K optimizer: reject staged-add pair fold when the staged register is
  also the add destination.
- M68K optimizer: prove removed flag-setting moves are dead before folding
  staged adds or replacing pushes with pea.
- M68K optimizer: only treat full .l writes as redefinitions in the deadness
  proof; byte/word partial writes keep the staged value live.
- M68K optimizer: treat add/sub/addq/subq to address registers as flag-
  preserving (ADDA/SUBA semantics).
- M68K FPO: reject subroutines whose inline assembly mentions A5 (reads as
  well as writes) and subroutines containing PUSH/POP/PUSHST/POPST.
- ADPCM wavc example: stop byte-swapping already-native m68k decoder output;
  add deinterleave_16bit_stereo_be helper.
- M68K/new6502 backends and IR codec: preserve ImmediateOperand.SymbolAddress
  offsets instead of dropping them; fix codec round-trip with type suffix.
- Clean up M68kMnemonics allFlagOverwriters classification for address-register
  arithmetic.
- Remove unnecessary d1-d2 register saves in deinterleave_16bit_stereo_be.
2026-11-07 14:30:37 +01:00
Irmen de Jong 5f9446499e m68k: implement phase 1 of frame-pointer omission (functional but phase 2 remains tbd) 2026-11-06 17:34:08 +01:00
Irmen de Jong c669246a73 ir: pass immediates directly into call hardware register slots 2026-11-06 14:42:46 +01:00
Irmen de Jong abbf471bce allow for loop iteration over str-parameter akak ^^ubyte pointer 2026-11-05 06:34:42 +01:00
Irmen de Jong c1bedc6176 m68k: faster codegen, faster horizontal blitter lines, added math.mul32 2026-11-05 04:48:48 +01:00
Irmen de Jong 9553d91990 various things 2026-11-04 22:32:43 +01:00
Irmen de Jong 72b322e2f4 Extract single status-flag returns before register returns
A multi-assign returning one status flag plus register values used to
read the registers first, wrapped in PUSHST/POPST. That crashes the
68000 backend, which cannot save/restore CCR, and wastes two
instructions everywhere else. Extract the flag first instead: nothing
can clobber the status bits before it is captured, so no
preservation is needed. Multi-flag calls keep the old behavior.
2026-11-01 16:50:20 +01:00
Irmen de Jong 0a53343694 give a warning when only an asmbinary blob is loaded inside an asmsub 2026-11-01 16:15:07 +01:00
Irmen de Jong 52bd103295 emit .binary / incbin for %asmbinary blobs instead of dumping the actual bytes into the asm 2026-11-01 15:46:29 +01:00
Irmen de Jong d687497a4e fix m68k codegen for augmented assignments 2026-10-31 00:34:29 +01:00
Irmen de Jong 119a499819 m68k: promote eligible locals and parameters to vregs 2026-10-27 05:59:39 +01:00
Irmen de Jong 5d9a0c1f7b m68k optimizations fixes, update optimization docs 2026-10-27 04:30:18 +01:00
Irmen de Jong 780af71452 implement F1 store/load fold 2026-10-27 02:00:26 +01:00
Irmen de Jong 5daa4bd613 Merge branch 'master' into m68k-register-alloc
# Conflicts:
#	codeGenM68k/src/prog8/codegen/m68k/AsmOptimizer.kt
#	codeGenM68k/src/prog8/codegen/m68k/InstrArithmetic.kt
#	codeGenM68k/src/prog8/codegen/m68k/InstrBitwise.kt
2026-10-27 01:09:06 +01:00
Irmen de Jong 9daab16ece Optimize redundant frame zero stores safely 2026-10-26 22:54:00 +01:00
Irmen de Jong 4427f986cc fuse extending loads into single IR load opcodes
add 8 IR opcodes (LOADMZ/LOADMS/LOADMZL/LOADMSL and the indexed
LOADI variants) and a peephole fusion pass that replaces
loadm/indexload followed by ext/exts/extl/extls with a single
extending load. Implemented for m68k, new6502 and the VM; run
deduplicateAddressComputations before fusion so it still sees the
unfused loadm+ext pairs.
2026-10-26 21:12:11 +01:00
Irmen de Jong 52e5535ec5 enable bias-corrected signed div by power of two for m68k 2026-10-25 21:56:59 +01:00
Irmen de Jong b820d32507 m68k: fix spill-slot alignment after vreg reuse and complete clobber audit
appendSpillSlotsToFrame() now builds a per-subroutine type map because
renumberVregsPerSubroutine() reuses vreg numbers across subroutines with
different types. Using the global virtualRegisterTypes map caused spilled
pointer vregs to be sized as byte/word, producing unaligned stack slots
like -9(a5) and crashing 68000 / corrupting saved registers on 68020.
2026-10-22 19:43:24 +02:00
Irmen de Jong da2288db93 improved variable source line position 2026-10-19 22:16:53 +02:00
Irmen de Jong e3ca9ae4a8 Fix virtual target typed pop results 2026-10-17 02:12:17 +02:00
Irmen de Jong 38c60a2d75 harden AstWalker detached-subtree skipping and extract shared canSkipExplicitCmpi helper 2026-10-17 01:46:35 +02:00
Irmen de Jong 5e83c44300 fix wrong result for short-circuit boolean and/or on the virtual target 2026-10-17 01:43:08 +02:00
Irmen de Jong 6cac707fd1 code cleanups 2026-10-13 22:40:19 +02:00
Irmen de Jong 0b902f06b5 m68k: word-packed stack argument slots 2026-10-13 21:37:43 +02:00
Irmen de Jong eda21a6ebf Fix in operator on arrays larger than 255 elements 2026-10-11 02:05:21 +02:00
Irmen de Jong 592637856f m68k: cleaner recursive defer errors 2026-10-10 02:02:25 +02:00
Irmen de Jong 233ca21492 m68k: frameable inline asm, word-sized sys.exit, and sys.die alerts 2026-10-10 00:19:22 +02:00
Irmen de Jong 3d78415088 better vm error for %asm 2026-10-08 04:37:19 +02:00
Irmen de Jong 0189903a63 m68k: pin @shared variables to static storage 2026-10-08 04:17:40 +02:00
Irmen de Jong 9c9552174e m68k: stackful coroutines fixed with per-task stacks, new %option noframe 2026-10-08 01:59:50 +02:00
Irmen de Jong 70bb199e12 m68k: pop frame on jumps leaving subroutine; reject dispatch to subs with parameters 2026-10-07 23:46:48 +02:00
Irmen de Jong 5e709fca7e m68k: stack-frame zero-clear coalescing 2026-10-07 19:06:16 +02:00
Irmen de Jong cc8df33418 m68k: plan for optimized stack frame zeroing 2026-10-07 19:06:16 +02:00
Irmen de Jong a1a48405b0 m68k: fix a5 frame pointer register clobbering 2026-10-07 19:06:16 +02:00
Irmen de Jong acc8705ea8 bugfix for m68k stack memory model 2026-10-07 19:06:16 +02:00
Irmen de Jong bbff472457 doc cleanup 2026-10-07 19:06:16 +02:00
Irmen de Jong 353b0c84b7 slice 5 for m68k stack memory model
(slice 4 was skipped)
2026-10-07 19:06:16 +02:00
Irmen de Jong 329b3df4a3 slice 3 for m68k stack memory model 2026-10-07 19:06:16 +02:00
Irmen de Jong fe90ca572d slice 2 for m68k stack mememory model 2026-10-07 19:06:16 +02:00
Irmen de Jong 26bbd6c1fe vertical slice prototype for m68k stack mememory model 2026-10-07 19:06:16 +02:00