lamina_codegen/aarch64/
abi.rs1use crate::abi::{Abi, common_call_stub, mangle_macos_name};
4use lamina_platform::TargetOperatingSystem;
5
6pub struct AArch64ABI {
8 target_os: TargetOperatingSystem,
9}
10
11impl AArch64ABI {
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 _ => name.to_string(),
22 }
23 }
24
25 pub fn get_global_directive(&self, func_name: &str) -> Option<String> {
27 match self.target_os {
28 TargetOperatingSystem::MacOS => Some(format!(".globl _{}", func_name)),
29 _ => Some(format!(".globl {}", func_name)),
30 }
31 }
32
33 pub fn call_stub(&self, name: &str) -> Option<String> {
35 common_call_stub(name, self.target_os)
36 }
37
38 pub const ARG_REGISTERS: &'static [&'static str] =
40 &["x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"];
41
42 pub const CALLER_SAVED_REGISTERS: &'static [&'static str] = &[
44 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13",
45 "x14", "x15", "x16", "x17",
46 ];
47
48 pub const CALLEE_SAVED_REGISTERS: &'static [&'static str] = &[
50 "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x29", "x30",
51 ];
52
53 pub fn target_os(&self) -> TargetOperatingSystem {
55 self.target_os
56 }
57}
58
59impl Abi for AArch64ABI {
60 fn target_os(&self) -> TargetOperatingSystem {
61 self.target_os
62 }
63
64 fn mangle_function_name(&self, name: &str) -> String {
65 AArch64ABI::mangle_function_name(self, name)
66 }
67
68 fn call_stub(&self, name: &str) -> Option<String> {
69 AArch64ABI::call_stub(self, name)
70 }
71}