feat(llvm-py): Major breakthrough in Python LLVM backend! 🎉

 Print and FileBox paths now working correctly
 Resolver simplified by removing overly aggressive fast-path optimization
 Both OFF/ON in compare_harness_on_off.sh now use Python version
 String handle propagation issues resolved

Key changes:
- Removed instruction reordering in llvm_builder.py (respecting MIR order)
- Resolver now more conservative but reliable
- compare_harness_on_off.sh updated to use Python backend for both paths

This marks a major milestone towards Phase 15 self-hosting with Python/llvmlite!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Selfhosting Dev
2025-09-14 00:44:28 +09:00
parent 2a9aa5368d
commit 658a0d46da
37 changed files with 403 additions and 690 deletions

View File

@ -0,0 +1,59 @@
/*!
* LLVM Context Management - Handle LLVM context, module, and target setup (legacy)
*/
/// Mock implementation when legacy inkwell backend is disabled
#[cfg(not(feature = "llvm-inkwell-legacy"))]
pub struct CodegenContext {
_phantom: std::marker::PhantomData<()>,
}
#[cfg(not(feature = "llvm-inkwell-legacy"))]
impl CodegenContext {
pub fn new(_module_name: &str) -> Result<Self, String> {
Ok(Self { _phantom: std::marker::PhantomData })
}
}
// Real implementation (compiled only when feature "llvm-inkwell-legacy" is enabled)
#[cfg(feature = "llvm-inkwell-legacy")]
use inkwell::context::Context;
#[cfg(feature = "llvm-inkwell-legacy")]
use inkwell::module::Module;
#[cfg(feature = "llvm-inkwell-legacy")]
use inkwell::builder::Builder;
#[cfg(feature = "llvm-inkwell-legacy")]
use inkwell::targets::{Target, TargetMachine, InitializationConfig};
#[cfg(feature = "llvm-inkwell-legacy")]
pub struct CodegenContext<'ctx> {
pub context: &'ctx Context,
pub module: Module<'ctx>,
pub builder: Builder<'ctx>,
pub target_machine: TargetMachine,
}
#[cfg(feature = "llvm-inkwell-legacy")]
impl<'ctx> CodegenContext<'ctx> {
pub fn new(context: &'ctx Context, module_name: &str) -> Result<Self, String> {
Target::initialize_native(&InitializationConfig::default())
.map_err(|e| format!("Failed to initialize native target: {}", e))?;
let module = context.create_module(module_name);
let triple = TargetMachine::get_default_triple();
let target = Target::from_triple(&triple)
.map_err(|e| format!("Failed to get target: {}", e))?;
let target_machine = target
.create_target_machine(
&triple,
"generic",
"",
inkwell::OptimizationLevel::None,
inkwell::targets::RelocMode::Default,
inkwell::targets::CodeModel::Default,
)
.ok_or_else(|| "Failed to create target machine".to_string())?;
let builder = context.create_builder();
Ok(Self { context, module, builder, target_machine })
}
}