lamina_codegen/riscv/
abi.rs1use crate::abi::{Abi, common_call_stub, mangle_macos_name};
2use lamina_platform::TargetOperatingSystem;
3
4pub struct RiscVAbi {
6 target_os: TargetOperatingSystem,
7}
8
9impl RiscVAbi {
10 pub fn new(target_os: TargetOperatingSystem) -> Self {
11 Self { target_os }
12 }
13
14 pub fn mangle_function_name(&self, name: &str) -> String {
16 match self.target_os {
17 TargetOperatingSystem::MacOS => mangle_macos_name(name),
18 _ => name.to_string(),
19 }
20 }
21
22 pub fn get_main_global(&self) -> &'static str {
24 ".globl main"
25 }
26
27 pub fn get_data_section(&self) -> &'static str {
29 ".data"
30 }
31
32 pub fn get_text_section(&self) -> &'static str {
34 ".text"
35 }
36
37 pub const ARG_REGISTERS: &'static [&'static str] =
39 &["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7"];
40
41 pub fn call_stub(&self, name: &str) -> Option<String> {
43 common_call_stub(name, self.target_os)
44 }
45}
46
47impl Abi for RiscVAbi {
48 fn target_os(&self) -> TargetOperatingSystem {
49 self.target_os
50 }
51
52 fn mangle_function_name(&self, name: &str) -> String {
53 RiscVAbi::mangle_function_name(self, name)
54 }
55
56 fn call_stub(&self, name: &str) -> Option<String> {
57 RiscVAbi::call_stub(self, name)
58 }
59}