lamina_codegen/x86_64/
abi.rs1use crate::abi::{Abi, common_call_stub, mangle_macos_name};
4use lamina_platform::TargetOperatingSystem;
5
6pub struct X86ABI {
8 target_os: TargetOperatingSystem,
9}
10
11impl X86ABI {
12 pub fn new(target_os: TargetOperatingSystem) -> Self {
14 Self { target_os }
15 }
16
17 pub fn mangle_function_name(&self, name: &str) -> String {
19 match self.target_os {
20 TargetOperatingSystem::MacOS => mangle_macos_name(name),
21 TargetOperatingSystem::Windows => {
22 if name == "main" {
23 "main".to_string()
24 } else {
25 name.to_string()
26 }
27 }
28 _ => name.to_string(),
29 }
30 }
31
32 pub fn get_main_global(&self) -> &'static str {
34 match self.target_os {
35 TargetOperatingSystem::Windows => ".globl main",
36 _ => ".globl main",
37 }
38 }
39
40 pub fn arg_registers(&self) -> &'static [&'static str] {
45 match self.target_os {
46 TargetOperatingSystem::Windows => &["rcx", "rdx", "r8", "r9"],
47 _ => &["rdi", "rsi", "rdx", "rcx", "r8", "r9"],
48 }
49 }
50
51 pub const ARG_REGISTERS: &'static [&'static str] = &["rdi", "rsi", "rdx", "rcx", "r8", "r9"];
55
56 pub const CALLER_SAVED_REGISTERS: &'static [&'static str] =
58 &["rax", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11"];
59
60 pub const CALLEE_SAVED_REGISTERS: &'static [&'static str] =
62 &["rbx", "rbp", "r12", "r13", "r14", "r15"];
63}
64
65impl Abi for X86ABI {
66 fn target_os(&self) -> TargetOperatingSystem {
67 self.target_os
68 }
69
70 fn mangle_function_name(&self, name: &str) -> String {
71 X86ABI::mangle_function_name(self, name)
72 }
73
74 fn call_stub(&self, name: &str) -> Option<String> {
75 common_call_stub(name, self.target_os)
76 }
77}