lamina_codegen/wasm/
abi.rs1use crate::abi::Abi;
7use lamina_platform::TargetOperatingSystem;
8
9pub struct WasmABI {
11 target_os: TargetOperatingSystem,
12}
13
14impl WasmABI {
15 pub fn new(target_os: TargetOperatingSystem) -> Self {
17 Self { target_os }
18 }
19
20 pub fn mangle_function_name(&self, name: &str) -> String {
24 name.to_string()
25 }
26
27 pub fn get_print_import(&self) -> &'static str {
29 "(import \"console\" \"log\" (func $log (param i64)))"
30 }
31
32 pub fn get_wasm_type(&self, ty: &lamina_mir::MirType) -> &'static str {
34 match ty {
35 lamina_mir::MirType::Scalar(lamina_mir::ScalarType::I64) => "i64",
36 _ => "i64",
37 }
38 }
39
40 pub fn generate_global_decl(&self, index: usize) -> String {
42 format!(" (global $vreg{} (mut i64) (i64.const 0))", index)
43 }
44
45 pub fn generate_local_decl(&self, index: usize) -> String {
47 format!(" (local $l{} i64)", index)
48 }
49}
50
51impl Abi for WasmABI {
52 fn target_os(&self) -> TargetOperatingSystem {
53 self.target_os
54 }
55
56 fn mangle_function_name(&self, name: &str) -> String {
57 WasmABI::mangle_function_name(self, name)
58 }
59}