use crate::abi::{Abi, common_call_stub, mangle_macos_name};
use lamina_platform::TargetOperatingSystem;
pub struct RiscVAbi {
target_os: TargetOperatingSystem,
}
impl RiscVAbi {
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_main_global(&self) -> &'static str {
".globl main"
}
pub fn get_data_section(&self) -> &'static str {
".data"
}
pub fn get_text_section(&self) -> &'static str {
".text"
}
pub fn get_print_format(&self) -> &'static str {
match self.target_os {
TargetOperatingSystem::MacOS => "__mir_fmt_int: .asciz \"%lld\\n\"",
_ => ".L_mir_fmt_int: .string \"%lld\\n\"",
}
}
pub const ARG_REGISTERS: &'static [&'static str] =
&["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7"];
pub fn call_stub(&self, name: &str) -> Option<String> {
common_call_stub(name, self.target_os)
}
}
impl Abi for RiscVAbi {
fn target_os(&self) -> TargetOperatingSystem {
self.target_os
}
fn mangle_function_name(&self, name: &str) -> String {
RiscVAbi::mangle_function_name(self, name)
}
fn call_stub(&self, name: &str) -> Option<String> {
RiscVAbi::call_stub(self, name)
}
}