2025-08-18 09:14:39 +00:00
|
|
|
/*!
|
|
|
|
|
* LLVM Backend Module - Compile MIR to LLVM IR for AOT execution
|
2025-09-11 04:20:28 +09:00
|
|
|
*
|
2025-08-18 09:14:39 +00:00
|
|
|
* This module provides LLVM-based compilation of Nyash MIR to native code.
|
|
|
|
|
* Phase 9.78 PoC implementation focused on minimal "return 42" support.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-11 04:20:28 +09:00
|
|
|
pub mod box_types;
|
2025-08-18 09:14:39 +00:00
|
|
|
pub mod compiler;
|
2025-09-11 04:20:28 +09:00
|
|
|
pub mod context;
|
2025-08-18 09:14:39 +00:00
|
|
|
|
2025-09-11 04:20:28 +09:00
|
|
|
use crate::box_trait::{IntegerBox, NyashBox};
|
2025-08-18 09:14:39 +00:00
|
|
|
use crate::mir::function::MirModule;
|
|
|
|
|
|
|
|
|
|
/// Compile MIR module to object file and execute
|
|
|
|
|
pub fn compile_and_execute(
|
|
|
|
|
mir_module: &MirModule,
|
|
|
|
|
output_path: &str,
|
|
|
|
|
) -> Result<Box<dyn NyashBox>, String> {
|
2025-08-18 19:29:24 +09:00
|
|
|
let mut compiler = compiler::LLVMCompiler::new()?;
|
2025-08-18 09:14:39 +00:00
|
|
|
compiler.compile_and_execute(mir_module, output_path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Compile MIR module to object file only
|
2025-09-11 04:20:28 +09:00
|
|
|
pub fn compile_to_object(mir_module: &MirModule, output_path: &str) -> Result<(), String> {
|
2025-08-18 09:14:39 +00:00
|
|
|
let compiler = compiler::LLVMCompiler::new()?;
|
|
|
|
|
compiler.compile_module(mir_module, output_path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
2025-09-11 04:20:28 +09:00
|
|
|
|
2025-08-18 09:14:39 +00:00
|
|
|
#[test]
|
|
|
|
|
fn test_llvm_module_creation() {
|
|
|
|
|
// Basic test to ensure the module can be loaded
|
|
|
|
|
// Actual compilation tests require full MIR infrastructure
|
|
|
|
|
assert!(true);
|
|
|
|
|
}
|
2025-09-11 04:20:28 +09:00
|
|
|
}
|