feat(llvm): wire nyash --emit-mir-json into build_llvm.sh crate path; add NYASH_LLVM_ONLY_OBJ gate; fix ny-llvmc bin name

This commit is contained in:
Selfhosting Dev
2025-09-17 22:11:59 +09:00
parent 8aa01668ff
commit d992fa1d2d
3 changed files with 30 additions and 7 deletions

View File

@ -9,3 +9,6 @@ anyhow = "1.0"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
[[bin]]
name = "ny-llvmc"
path = "src/main.rs"

View File

@ -64,5 +64,16 @@ impl NyashRunner {
println!("🚀 MIR Output for {}:", filename); println!("🚀 MIR Output for {}:", filename);
println!("{}", printer.print_module(&compile_result.module)); println!("{}", printer.print_module(&compile_result.module));
} }
// Emit MIR JSON if requested and exit
if let Some(path) = self.config.emit_mir_json.as_ref() {
let p = std::path::Path::new(path);
if let Err(e) = crate::runner::mir_json_emit::emit_mir_json_for_harness(&compile_result.module, p) {
eprintln!("❌ MIR JSON emit error: {}", e);
std::process::exit(1);
}
println!("MIR JSON written: {}", p.display());
std::process::exit(0);
}
} }
} }

View File

@ -64,12 +64,16 @@ if [[ "${NYASH_LLVM_SKIP_EMIT:-0}" != "1" ]]; then
crate) crate)
# Use crates/nyash-llvm-compiler (ny-llvmc): requires pre-generated MIR JSON path in NYASH_LLVM_MIR_JSON # Use crates/nyash-llvm-compiler (ny-llvmc): requires pre-generated MIR JSON path in NYASH_LLVM_MIR_JSON
if [[ -z "${NYASH_LLVM_MIR_JSON:-}" ]]; then if [[ -z "${NYASH_LLVM_MIR_JSON:-}" ]]; then
echo "[warn] NYASH_LLVM_COMPILER=crate but NYASH_LLVM_MIR_JSON is not set; falling back to harness" >&2 # Autoemit MIR JSON via nyash CLI flag
COMPILER_MODE="harness" mkdir -p tmp
else NYASH_LLVM_MIR_JSON="tmp/nyash_crate_mir.json"
echo " using ny-llvmc (crate) with JSON: $NYASH_LLVM_MIR_JSON" >&2 echo " emitting MIR JSON: $NYASH_LLVM_MIR_JSON" >&2
cargo build --release -p nyash-llvm-compiler >/dev/null ./target/release/nyash --emit-mir-json "$NYASH_LLVM_MIR_JSON" --backend mir "$INPUT" >/dev/null
# Optional schema validation if tool is available fi
echo " using ny-llvmc (crate) with JSON: $NYASH_LLVM_MIR_JSON" >&2
cargo build --release -p nyash-llvm-compiler >/dev/null
# Optional schema validation when explicitly requested
if [[ "${NYASH_LLVM_VALIDATE_JSON:-0}" == "1" ]]; then
if [[ -f tools/validate_mir_json.py ]]; then if [[ -f tools/validate_mir_json.py ]]; then
if ! python3 -m jsonschema --version >/dev/null 2>&1; then if ! python3 -m jsonschema --version >/dev/null 2>&1; then
echo "[warn] jsonschema not available; skipping schema validation" >&2 echo "[warn] jsonschema not available; skipping schema validation" >&2
@ -79,8 +83,8 @@ if [[ "${NYASH_LLVM_SKIP_EMIT:-0}" != "1" ]]; then
echo "error: MIR JSON validation failed" >&2; exit 3; } echo "error: MIR JSON validation failed" >&2; exit 3; }
fi fi
fi fi
./target/release/ny-llvmc --in "$NYASH_LLVM_MIR_JSON" --out "$OBJ"
fi fi
./target/release/ny-llvmc --in "$NYASH_LLVM_MIR_JSON" --out "$OBJ"
;; ;;
esac esac
if [[ "$COMPILER_MODE" == "harness" ]]; then if [[ "$COMPILER_MODE" == "harness" ]]; then
@ -101,6 +105,11 @@ if [[ ! -f "$OBJ" ]]; then
exit 3 exit 3
fi fi
if [[ "${NYASH_LLVM_ONLY_OBJ:-0}" == "1" ]]; then
echo "[3/4] Skipping link: object generated at $OBJ (NYASH_LLVM_ONLY_OBJ=1)"
exit 0
fi
echo "[3/4] Building NyRT static runtime ..." echo "[3/4] Building NyRT static runtime ..."
if [[ "${NYASH_LLVM_SKIP_NYRT_BUILD:-0}" == "1" ]]; then if [[ "${NYASH_LLVM_SKIP_NYRT_BUILD:-0}" == "1" ]]; then
echo " Skipping NyRT build (NYASH_LLVM_SKIP_NYRT_BUILD=1)" echo " Skipping NyRT build (NYASH_LLVM_SKIP_NYRT_BUILD=1)"