1
0
Fork 0
forked from koniifer/ableos

doing same for arguments

This commit is contained in:
mlokr 2024-05-16 12:42:11 +02:00
parent 589a30c8a3
commit 3127d04e41
7 changed files with 22 additions and 10 deletions

View file

@ -371,12 +371,18 @@ impl Func {
}
}
#[derive(Default, PartialEq, Eq, Debug)]
#[derive(Default, PartialEq, Eq)]
pub struct RegAlloc {
free: Vec<Reg>,
max_used: Reg,
}
impl std::fmt::Debug for RegAlloc {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RegAlloc").finish()
}
}
impl RegAlloc {
fn init_callee(&mut self) {
self.free.clear();
@ -564,18 +570,19 @@ impl<'a> Codegen<'a> {
}
let fn_label = self.labels[frame.label as usize].clone();
self.gpa.borrow_mut().init_callee();
log::dbg!("fn-args");
let mut parama = 3..12;
for (arg, &ty) in args.iter().zip(fn_label.args.iter()) {
let loc = self.load_arg(ty, &mut parama);
let refed = arg.last.is_some_and(|l| l.get() & parser::REFERENCED != 0);
let loc = self.load_arg(refed, ty, &mut parama);
self.vars.push(Variable {
id: arg.id,
value: Value { ty, loc },
});
}
self.gpa.borrow_mut().init_callee();
self.ret = fn_label.ret;
log::dbg!("fn-body");
@ -1630,10 +1637,15 @@ impl<'a> Codegen<'a> {
}
}
fn load_arg(&mut self, ty: Type, parama: &mut Range<u8>) -> Loc {
fn load_arg(&mut self, referenced: bool, ty: Type, parama: &mut Range<u8>) -> Loc {
let size = self.size_of(ty);
match size {
0 => Loc::Imm(0),
..=8 if !referenced => {
let reg = self.alloc_reg();
self.code.encode(instrs::cp(reg.0, parama.next().unwrap()));
Loc::Reg(reg)
}
..=8 => {
let stack = self.alloc_stack(size as _);
self.store_stack(parama.next().unwrap(), stack.offset, size as _);

View file

@ -1,3 +1,3 @@
code size: 758
code size: 678
ret: 0
status: Ok(())

View file

@ -1,3 +1,3 @@
code size: 388
code size: 320
ret: 33
status: Ok(())

View file

@ -1,3 +1,3 @@
code size: 347
code size: 293
ret: 55
status: Ok(())

View file

@ -1,3 +1,3 @@
code size: 347
code size: 296
ret: 55
status: Ok(())

View file

@ -1,3 +1,3 @@
code size: 437
code size: 382
ret: 0
status: Ok(())

View file

@ -1,3 +1,3 @@
code size: 530
code size: 483
ret: 3
status: Ok(())