Skip to content

refactor(asm): unify backend naming, register constants, and printer surface - #18

Open
Boreas618 wants to merge 1 commit into
mainfrom
refactor/asm-backend-cleanup
Open

refactor(asm): unify backend naming, register constants, and printer surface#18
Boreas618 wants to merge 1 commit into
mainfrom
refactor/asm-backend-cleanup

Conversation

@Boreas618

@Boreas618 Boreas618 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

AArch64-backend unification from the cross-layer audit:

  • Name collisions removed: FunctionGeneratorAsmFunctionGenerator, OperandInstOperand, BinOpInstBinOp (also killing the Inst::BinOp { op: BinOp } self-shadowing); IR types keep their names.
  • One home for register/ABI constants: new aarch64::regs module (arg regs x0-x7, frame pointer x29, link register x30, scratch x16/x17, allocatable set, 16-byte stack alignment); duplicated SCRATCH0/1 definitions and all raw Physical(29|30|16|17|0) literals eliminated.
  • Overlapping operand enums merged: IndexOperand::{Reg, Imm} was isomorphic to InstOperand::{Register, Immediate} and existed only for Inst::Gep's index — folded into InstOperand.
  • Dead surface removed: unused public re-exports in asm/aarch64.rs; the single-implementor AsmPrint trait folded into inherent AsmPrinter methods; duplicate Inst::Label printing paths merged.
  • Printer-boundary parity with the ir layer: AArch64AsmGenerator::output now delegates wholesale to AsmPrinter::emit_program, like ir's output() delegates to IrPrinter::emit_module — emitted assembly is byte-identical.
  • //! module docs for all files under src/asm/**.

No instruction-selection or register-allocation behavior changes. Verified: cargo test 30/30 green.

Re-author onto the asmt-4 skeleton (the old three-commit series cannot survive a mechanical rebase).  Re-applies the PR's goals where the skeleton does not already achieve them.

Rename the backend-local types that collide with front-end names: FunctionGenerator -> AsmFunctionGenerator (ir::function defines the same name), Operand -> InstOperand (vs ir::Operand), and BinOp -> InstBinOp, which also removes the Instruction::BinOp { op: BinOp } self-shadowing.  The float types (FBinOp, RegisterSize, RegisterClass) keep their names; none collide.  IndexOperand::{Reg, Imm} was isomorphic to InstOperand::{Register, Immediate} and existed only for Instruction::Gep's index field, so Gep now takes an InstOperand and the redundant enum is gone.  IR types keep their names throughout.

Fold the single-implementor AsmPrint trait into inherent AsmPrinter methods and reuse emit_label in the Instruction::Label arm.  Whole-program orchestration (sections, globals, per-function symbol/uses_fp/prologue emission) moves from AArch64AsmGenerator::output into AsmPrinter::emit_program / emit_function, so output() delegates wholesale, mirroring how the ir layer's output() delegates to IrPrinter::emit_module.  Drop the dead public re-exports of Instruction/types from asm::aarch64 (nothing outside the backend consumes them) and let the register allocator import InstBinOp from its defining module.

Add the missing //! module docs across src/asm and sweep all backend comments against the comment spec: rewrite the "asks you to implement" audience leak and first-person narration into declarative why-form, delete the floating section header in the rewriter and the what-restatements in lower_ptr, and fix stale RegSize / B { Cond, label } references that contradicted the code.

Already achieved by the skeleton and deliberately not redone: SCRATCH0/SCRATCH1 and the AAPCS register-role constants are centralized in types.rs, and aapcs.rs / frame.rs carry their own module docs.  Float / aapcs / frame functionality is untouched; emitted assembly is unchanged (byte-for-byte orchestration order preserved).

cargo test: 30/30 golden end-to-end green.
@Boreas618
Boreas618 force-pushed the refactor/asm-backend-cleanup branch from bfc5d0d to a04f318 Compare August 1, 2026 11:09
@Boreas618
Boreas618 changed the base branch from assign3 to main August 1, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant