refactor(backend): modularize x86_64 codegen
- Moves x86_64 backend implementation from a single file into a structured module (`codegen`, `types`, `mod`). - Introduces a dedicated `Codegen` helper to enforce x86-64 hardware constraints (e.g., preventing memory-to-memory moves). - Implements strongly-typed register formatting and operand width handling. - Renames `Instruction::Assign` to `Instruction::Copy` across the IR and all optimization passes to better reflect semantic intent. - Updates the x86 backend to handle ABI-compliant stack alignment and register allocation more robustly.
This commit is contained in:
+10
-10
@@ -20,9 +20,9 @@ fn fold_function_constants(func: &mut Function) {
|
||||
// 2. Evaluate and rewrite instructions where possible
|
||||
match inst {
|
||||
Instruction::Alloc { .. } => {}
|
||||
Instruction::Assign { register, operand } => {
|
||||
if is_constant(operand) {
|
||||
known_constants.insert(*register, *operand);
|
||||
Instruction::Copy { dest, src } => {
|
||||
if is_constant(src) {
|
||||
known_constants.insert(*dest, *src);
|
||||
}
|
||||
}
|
||||
Instruction::Binary {
|
||||
@@ -36,9 +36,9 @@ fn fold_function_constants(func: &mut Function) {
|
||||
known_constants.insert(*dest, folded);
|
||||
|
||||
// Rewrite the evaluated Binary instruction into a clean Assign
|
||||
*inst = Instruction::Assign {
|
||||
register: *dest,
|
||||
operand: folded,
|
||||
*inst = Instruction::Copy {
|
||||
dest: *dest,
|
||||
src: folded,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,9 @@ fn fold_function_constants(func: &mut Function) {
|
||||
known_constants.insert(*dest, folded);
|
||||
|
||||
// Rewrite the evaluated Unary instruction into a clean Assign
|
||||
*inst = Instruction::Assign {
|
||||
register: *dest,
|
||||
operand: folded,
|
||||
*inst = Instruction::Copy {
|
||||
dest: *dest,
|
||||
src: folded,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ fn substitute_constants_in_inst(inst: &mut Instruction, constants: &HashMap<Regi
|
||||
|
||||
match inst {
|
||||
Instruction::Alloc { .. } => {}
|
||||
Instruction::Assign { operand, .. } => replace(operand),
|
||||
Instruction::Copy { src, .. } => replace(src),
|
||||
Instruction::Load { src, .. } => replace(src),
|
||||
Instruction::Store { dest, src, .. } => {
|
||||
replace(dest);
|
||||
|
||||
Reference in New Issue
Block a user