← board

ARM32 text-assembler (EmitAsmArm32) for cleaner ARM32 codegen

Motivation

ir_codegen_arm32.inc is 1904 lines of raw word emission. Same readability / maintenance win as the other target emitters; last of the three.

New vs the x86/xtensa precedent

No typed encoder layer exists for ARM32 (like AArch64). Grow a thin compiler/arm32enc.inc (typed EncodeArm32* over the byte sink) under EmitAsmArm32, or share the front-end built for EmitAsmA64. A32 is also fixed-width 32-bit, so the AArch64 emitter's structure largely carries over — the encoding fields differ.

Operand model

mnem dst, src, …. Registers r0..r15 (sp=r13, lr=r14, pc=r15). Loads/stores ldr r3, [r2, #8]. Data-processing immediates are the ARM32 quirk: 8-bit value rotated by an even amount (imm8 + rot4), not a flat imm12 — the encoder must find a valid rotation or reject. Markers % / .label: / @data / @glob as elsewhere.

Scope (incremental — mix freely)

  1. Cover what converted blocks use first: mov mvn add sub and orr eor cmp (imm8-rot + register forms), ldr str ldrb strb (base+imm), bx lr, branches b/bl (rel24 <<2) and condition-coded beq/bne/… (the [31:28] condition field). Grow on demand.
  2. Labels + branch offset resolution back+forward (rel24, word-scaled).
  3. Convert ≥1 real branch/label-bearing block. Leave dynamic blocks on inline word emission.

Landmines

Acceptance

Deferred

Thumb/Thumb-2, ldr rd,=imm literal-pool sugar, shifted-register operands beyond what blocks need, the full ir_codegen_arm32.inc conversion.

Log