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 fn get_print_format(&self) -> &'static str {
39 match self.target_os {
40 TargetOperatingSystem::MacOS => "__mir_fmt_int: .asciz \"%lld\\n\"",
41 _ => ".L_mir_fmt_int: .string \"%lld\\n\"",
42 }
43 }
44
45 pub const ARG_REGISTERS: &'static [&'static str] =
47 &["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7"];
48
49 pub fn call_stub(&self, name: &str) -> Option<String> {
51 common_call_stub(name, self.target_os)
52 }
53}
54
55impl Abi for RiscVAbi {
56 fn target_os(&self) -> TargetOperatingSystem {
57 self.target_os
58 }
59
60 fn mangle_function_name(&self, name: &str) -> String {
61 RiscVAbi::mangle_function_name(self, name)
62 }
63
64 fn call_stub(&self, name: &str) -> Option<String> {
65 RiscVAbi::call_stub(self, name)
66 }
67}