feat(parser,ir,backend): Fully support func params and disable r0-r3 alloc temporarily
This commit is contained in:
@@ -15,6 +15,7 @@ pub struct Generator {
|
||||
|
||||
const DEFAULT_VAR_ALIGN: usize = 4;
|
||||
|
||||
const ARG_REGS: [Register; 4] = [REG_R0, REG_R1, REG_R2, REG_R3];
|
||||
fn load_variable(variable: Variable, reg_allocator: &mut RegisterAllocator, var_index_to_stack_offset: &BTreeMap<usize, usize>, instrs: &mut Vec<ARMInstr>) -> RegisterAlloc {
|
||||
match variable.var_type {
|
||||
VariableType::Global => {
|
||||
@@ -27,8 +28,14 @@ fn load_variable(variable: Variable, reg_allocator: &mut RegisterAllocator, var_
|
||||
// }
|
||||
var_alloc
|
||||
},
|
||||
VariableType::ParamTemp => {
|
||||
todo!()
|
||||
VariableType::ParamTemp(param_index) => {
|
||||
if param_index < ARG_REGS.len() {
|
||||
let reg = ARG_REGS[param_index];
|
||||
let var_alloc = reg_allocator.alloc_reg(reg).expect("Ran out of registers");
|
||||
var_alloc
|
||||
} else {
|
||||
todo!("More than 4 parameters not supported yet");
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let stack_offset = var_index_to_stack_offset.get(&variable.index).expect("Variable not declared");
|
||||
@@ -48,7 +55,7 @@ fn save_variable(variable: Variable, reg: Register, reg_allocator: &mut Register
|
||||
instrs.push(LoadPseudoInstr::new(address_alloc.reg, format!("global_var_{}", variable.index)));
|
||||
instrs.push(StoreInstr::new(reg, address_alloc.reg, None));
|
||||
},
|
||||
VariableType::ParamTemp => {
|
||||
VariableType::ParamTemp(_) => {
|
||||
todo!()
|
||||
},
|
||||
_ => {
|
||||
@@ -199,7 +206,6 @@ impl Generator {
|
||||
if args.len() > 4 {
|
||||
todo!("More than 4 arguments not supported yet");
|
||||
}
|
||||
const ARG_REGS: [Register; 4] = [REG_R0, REG_R1, REG_R2, REG_R3];
|
||||
let mut arg_reg_allocs = Vec::new();
|
||||
for (i, arg) in args.into_iter().enumerate() {
|
||||
arg_reg_allocs.push(self.register_allocator.alloc_reg(ARG_REGS[i]).expect("Ran out of registers"));
|
||||
|
||||
Reference in New Issue
Block a user