use crate::abi::{Abi, common_call_stub, mangle_macos_name};
use lamina_platform::TargetOperatingSystem;
pub struct AArch64ABI {
target_os: TargetOperatingSystem,
}
impl AArch64ABI {
pub fn new(target_os: TargetOperatingSystem) -> Self {
Self { target_os }
}
pub fn mangle_function_name(&self, name: &str) -> String {
match self.target_os {
TargetOperatingSystem::MacOS => mangle_macos_name(name),
_ => name.to_string(),
}
}
pub fn get_global_directive(&self, func_name: &str) -> Option<String> {
match self.target_os {
TargetOperatingSystem::MacOS => Some(format!(".globl _{}", func_name)),
_ => Some(format!(".globl {}", func_name)),
}
}
pub fn call_stub(&self, name: &str) -> Option<String> {
common_call_stub(name, self.target_os)
}
pub const ARG_REGISTERS: &'static [&'static str] =
&["x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"];
pub const CALLER_SAVED_REGISTERS: &'static [&'static str] = &[
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13",
"x14", "x15", "x16", "x17",
];
pub const CALLEE_SAVED_REGISTERS: &'static [&'static str] = &[
"x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x29", "x30",
];
pub fn target_os(&self) -> TargetOperatingSystem {
self.target_os
}
}
impl Abi for AArch64ABI {
fn target_os(&self) -> TargetOperatingSystem {
self.target_os
}
fn mangle_function_name(&self, name: &str) -> String {
AArch64ABI::mangle_function_name(self, name)
}
fn call_stub(&self, name: &str) -> Option<String> {
AArch64ABI::call_stub(self, name)
}
}