seqc/codegen/
platform.rs

1//! Platform detection and FFI type helpers.
2
3use crate::ffi::{FfiArg, FfiReturn, FfiType};
4
5/// Get the target triple for the current platform
6pub fn get_target_triple() -> &'static str {
7    #[cfg(all(target_os = "macos", target_arch = "aarch64"))]
8    {
9        "arm64-apple-macosx14.0.0"
10    }
11
12    #[cfg(all(target_os = "macos", target_arch = "x86_64"))]
13    {
14        "x86_64-apple-darwin"
15    }
16
17    #[cfg(all(target_os = "linux", target_arch = "x86_64"))]
18    {
19        "x86_64-unknown-linux-gnu"
20    }
21
22    #[cfg(all(target_os = "linux", target_arch = "aarch64"))]
23    {
24        "aarch64-unknown-linux-gnu"
25    }
26
27    #[cfg(not(any(
28        all(target_os = "macos", target_arch = "aarch64"),
29        all(target_os = "macos", target_arch = "x86_64"),
30        all(target_os = "linux", target_arch = "x86_64"),
31        all(target_os = "linux", target_arch = "aarch64")
32    )))]
33    {
34        "unknown"
35    }
36}
37
38/// Get the LLVM IR return type for an FFI function
39pub fn ffi_return_type(return_spec: &Option<FfiReturn>) -> &'static str {
40    match return_spec {
41        Some(spec) => match spec.return_type {
42            FfiType::Int => "i64",
43            FfiType::String => "ptr",
44            FfiType::Ptr => "ptr",
45            FfiType::Void => "void",
46        },
47        None => "void",
48    }
49}
50
51/// Get the LLVM IR argument types for an FFI function
52pub fn ffi_c_args(args: &[FfiArg]) -> String {
53    if args.is_empty() {
54        return String::new();
55    }
56
57    args.iter()
58        .map(|arg| match arg.arg_type {
59            FfiType::Int => "i64",
60            FfiType::String => "ptr",
61            FfiType::Ptr => "ptr",
62            FfiType::Void => "void",
63        })
64        .collect::<Vec<_>>()
65        .join(", ")
66}