forked from AbleOS/ableos
doing same for arguments
This commit is contained in:
parent
589a30c8a3
commit
3127d04e41
|
@ -371,12 +371,18 @@ impl Func {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Eq, Debug)]
|
#[derive(Default, PartialEq, Eq)]
|
||||||
pub struct RegAlloc {
|
pub struct RegAlloc {
|
||||||
free: Vec<Reg>,
|
free: Vec<Reg>,
|
||||||
max_used: 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 {
|
impl RegAlloc {
|
||||||
fn init_callee(&mut self) {
|
fn init_callee(&mut self) {
|
||||||
self.free.clear();
|
self.free.clear();
|
||||||
|
@ -564,18 +570,19 @@ impl<'a> Codegen<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let fn_label = self.labels[frame.label as usize].clone();
|
let fn_label = self.labels[frame.label as usize].clone();
|
||||||
|
self.gpa.borrow_mut().init_callee();
|
||||||
|
|
||||||
log::dbg!("fn-args");
|
log::dbg!("fn-args");
|
||||||
let mut parama = 3..12;
|
let mut parama = 3..12;
|
||||||
for (arg, &ty) in args.iter().zip(fn_label.args.iter()) {
|
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 {
|
self.vars.push(Variable {
|
||||||
id: arg.id,
|
id: arg.id,
|
||||||
value: Value { ty, loc },
|
value: Value { ty, loc },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self.gpa.borrow_mut().init_callee();
|
|
||||||
self.ret = fn_label.ret;
|
self.ret = fn_label.ret;
|
||||||
|
|
||||||
log::dbg!("fn-body");
|
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);
|
let size = self.size_of(ty);
|
||||||
match size {
|
match size {
|
||||||
0 => Loc::Imm(0),
|
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 => {
|
..=8 => {
|
||||||
let stack = self.alloc_stack(size as _);
|
let stack = self.alloc_stack(size as _);
|
||||||
self.store_stack(parama.next().unwrap(), stack.offset, size as _);
|
self.store_stack(parama.next().unwrap(), stack.offset, size as _);
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 758
|
code size: 678
|
||||||
ret: 0
|
ret: 0
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 388
|
code size: 320
|
||||||
ret: 33
|
ret: 33
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 347
|
code size: 293
|
||||||
ret: 55
|
ret: 55
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 347
|
code size: 296
|
||||||
ret: 55
|
ret: 55
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 437
|
code size: 382
|
||||||
ret: 0
|
ret: 0
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 530
|
code size: 483
|
||||||
ret: 3
|
ret: 3
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
Loading…
Reference in a new issue