Skip to content

Commit

Permalink
[FIX] fixed caller saved registers (fixes #50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Nov 5, 2024
1 parent 86eb9e7 commit ac42bd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/CodeGen/calling_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ impl MachineCallingConvention {
return match arch {
Arch::X86_64 => vec![
Reg::x64(X64Reg::Xmm0), Reg::x64(X64Reg::Xmm1), Reg::x64(X64Reg::Xmm2),
Reg::x64(X64Reg::Xmm3), Reg::x64(X64Reg::Xmm4), Reg::x64(X64Reg::Xmm5),
Reg::x64(X64Reg::Xmm6), Reg::x64(X64Reg::Xmm7)
Reg::x64(X64Reg::Xmm3)
],

_ => todo!(),
Expand Down Expand Up @@ -184,4 +183,22 @@ impl MachineCallingConvention {
pub fn align(&self, _: Arch) -> i64 {
8 // ygen (currently) only supports x64 which has an alignment of 8
}

/// Returns the fp registers which are saved by the caller
pub fn caller_saved_fps(&self, arch: Arch) -> Vec<Reg> {
match (arch, self.call_conv) {
(Arch::X86_64, CallConv::SystemV) => Vec::new(),
(Arch::X86_64, CallConv::WindowsFastCall) => vec![Reg::x64(X64Reg::Xmm0), Reg::x64(X64Reg::Xmm1), Reg::x64(X64Reg::Xmm2), Reg::x64(X64Reg::Xmm3), Reg::x64(X64Reg::Xmm4), Reg::x64(X64Reg::Xmm5)],
_ => Vec::new(),
}
}

/// Returns the gr registers which are saved by the caller
pub fn caller_saved_grs(&self, arch: Arch) -> Vec<Reg> {
match (arch, self.call_conv) {
(Arch::X86_64, CallConv::SystemV) => vec![Reg::x64(X64Reg::Rax), Reg::x64(X64Reg::Rcx), Reg::x64(X64Reg::Rdx), Reg::x64(X64Reg::Rsi), Reg::x64(X64Reg::Rdi), Reg::x64(X64Reg::R8), Reg::x64(X64Reg::R9), Reg::x64(X64Reg::R10), Reg::x64(X64Reg::R11)],
(Arch::X86_64, CallConv::WindowsFastCall) => vec![Reg::x64(X64Reg::Rax), Reg::x64(X64Reg::Rcx), Reg::x64(X64Reg::Rdx), Reg::x64(X64Reg::R8), Reg::x64(X64Reg::R9), Reg::x64(X64Reg::R10), Reg::x64(X64Reg::R11)],
_ => Vec::new(),
}
}
}
4 changes: 2 additions & 2 deletions src/CodeGen/compilation/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ impl CompilationHelper {
let mut reg_args = 0;
let mut fp_reg_args = 0;

let args = self.call.args(self.arch, TypeMetadata::i64);
let fp_args = self.call.args(self.arch, TypeMetadata::f64);
let args = self.call.caller_saved_grs(self.arch);
let fp_args = self.call.caller_saved_fps(self.arch);

let mut saved = HashMap::new();

Expand Down

0 comments on commit ac42bd4

Please sign in to comment.