use crate::error::LaminaError;
use crate::mir::codegen::from_ir;
use crate::parser::parse_module;
use lamina_platform::Target;
pub fn compile_lir_internal(
ir_code: &str,
function_name: &str,
_codegen_units: usize,
) -> Result<crate::runtime::RuntimeResult, LaminaError> {
let host = Target::detect_host();
let target_arch = host.architecture;
let target_os = host.operating_system;
let ir_module = parse_module(ir_code)?;
let mir_module = from_ir(&ir_module, "lir_macro")?;
let lookup_name = function_name.strip_prefix('@').unwrap_or(function_name);
crate::runtime::compile_to_runtime(&mir_module, target_arch, target_os, Some(lookup_name))
}
pub fn extract_function_name(ir_code: &str) -> Option<&str> {
if let Some(start) = ir_code.find("fn @") {
let after_fn = &ir_code[start + 4..];
if let Some(end) = after_fn.find(|c: char| c == '(' || c.is_whitespace()) {
let name = &after_fn[..end];
return Some(name);
}
}
if let Some(start) = ir_code.find("fn ") {
let after_fn = &ir_code[start + 3..];
if let Some(end) = after_fn.find(|c: char| c == '(' || c.is_whitespace()) {
let name = &after_fn[..end];
return Some(name);
}
}
None
}