refactor(llvm): Phase 286 - Modularize llvm.rs into 10 boxes
Following Phase 33 success pattern: - Single responsibility per box - Testability through isolated boxes - Reusability across backends Before: 449 lines monolithic function After: 229 line orchestrator + 10 focused boxes Boxes created: - plugin_init.rs (plugin initialization) - using_resolver.rs (using/prelude handling) - mir_compiler.rs (AST → MIR compilation) - method_id_injector.rs (method_id injection) - joinir_experiment.rs (JoinIR experiment, feature-gated) - pyvm_executor.rs (PyVM harness, dev/test) - object_emitter.rs (LLVM object emit) - harness_executor.rs (LLVM harness execution) - exit_reporter.rs (leak report, Phase 285LLVM-0) - fallback_executor.rs (mock/legacy execution) Test Results: - ✅ cargo build --release - ✅ cargo build --release --features llvm - ✅ 18 VM/LLVM parity tests PASS - ✅ No regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
64
src/runner/modes/llvm/fallback_executor.rs
Normal file
64
src/runner/modes/llvm/fallback_executor.rs
Normal file
@ -0,0 +1,64 @@
|
||||
//! Fallback executor for LLVM mode (mock/legacy)
|
||||
//!
|
||||
//! Handles fallback execution when LLVM backends are not available.
|
||||
|
||||
use nyash_rust::{mir::MirModule, mir::MirInstruction};
|
||||
|
||||
/// Fallback executor Box
|
||||
///
|
||||
/// **Responsibility**: Execute fallback path (feature check + mock)
|
||||
/// **Input**: &MirModule
|
||||
/// **Output**: i32 (exit code)
|
||||
pub struct FallbackExecutorBox;
|
||||
|
||||
impl FallbackExecutorBox {
|
||||
/// Execute fallback path (feature check + mock)
|
||||
///
|
||||
/// Fail-fast: if the user explicitly requested the llvmlite harness
|
||||
/// but this binary was built without the `llvm-harness` feature,
|
||||
/// do not silently fall back to mock.
|
||||
///
|
||||
/// Otherwise, executes mock execution that inspects the MIR
|
||||
/// and returns a deterministic exit code based on Return instructions.
|
||||
pub fn execute(module: &MirModule) -> i32 {
|
||||
// Fail-fast: if the user explicitly requested the llvmlite harness
|
||||
// but this binary was built without the `llvm-harness` feature,
|
||||
// do not silently fall back to mock.
|
||||
if crate::config::env::env_bool("NYASH_LLVM_USE_HARNESS") {
|
||||
crate::console_println!(
|
||||
"❌ LLVM harness requested (NYASH_LLVM_USE_HARNESS=1), but this binary was built without `--features llvm` (llvm-harness)."
|
||||
);
|
||||
crate::console_println!(
|
||||
" Fix: cargo build --release --features llvm"
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
crate::console_println!("🔧 Mock LLVM Backend Execution:");
|
||||
crate::console_println!(" Build with --features llvm for real backend.");
|
||||
|
||||
// NamingBox SSOT: Select entry (arity-aware, Main.main → main fallback)
|
||||
let entry = crate::runner::modes::common_util::entry_selection::select_entry_function(module);
|
||||
|
||||
if let Some(main_func) = module.functions.get(&entry) {
|
||||
for (_bid, block) in &main_func.blocks {
|
||||
for inst in &block.instructions {
|
||||
match inst {
|
||||
MirInstruction::Return { value: Some(_) } => {
|
||||
crate::console_println!("✅ Mock exit code: 42");
|
||||
return 42;
|
||||
}
|
||||
MirInstruction::Return { value: None } => {
|
||||
crate::console_println!("✅ Mock exit code: 0");
|
||||
return 0;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate::console_println!("✅ Mock exit code: 0");
|
||||
0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user