Stage-A selfhost emitter fixes and LLVM opt toggle

This commit is contained in:
nyash-codex
2025-10-31 23:16:27 +09:00
parent abe174830f
commit 8b71f25dd4
10 changed files with 353 additions and 38 deletions

View File

@ -1,3 +1,4 @@
use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
@ -145,10 +146,10 @@ fn main() -> Result<()> {
fn run_harness_dummy(harness: &Path, out: &Path) -> Result<()> {
ensure_python()?;
let status = Command::new("python3")
.arg(harness)
.arg("--out")
.arg(out)
let mut cmd = Command::new("python3");
cmd.arg(harness).arg("--out").arg(out);
propagate_opt_level(&mut cmd);
let status = cmd
.status()
.context("failed to execute python harness (dummy)")?;
if !status.success() {
@ -159,12 +160,14 @@ fn run_harness_dummy(harness: &Path, out: &Path) -> Result<()> {
fn run_harness_in(harness: &Path, input: &Path, out: &Path) -> Result<()> {
ensure_python()?;
let status = Command::new("python3")
.arg(harness)
let mut cmd = Command::new("python3");
cmd.arg(harness)
.arg("--in")
.arg(input)
.arg("--out")
.arg(out)
.arg(out);
propagate_opt_level(&mut cmd);
let status = cmd
.status()
.context("failed to execute python harness")?;
if !status.success() {
@ -180,6 +183,16 @@ fn ensure_python() -> Result<()> {
}
}
fn propagate_opt_level(cmd: &mut Command) {
let level = env::var("HAKO_LLVM_OPT_LEVEL")
.ok()
.or_else(|| env::var("NYASH_LLVM_OPT_LEVEL").ok());
if let Some(level) = level {
cmd.env("HAKO_LLVM_OPT_LEVEL", &level);
cmd.env("NYASH_LLVM_OPT_LEVEL", &level);
}
}
fn link_executable(
obj: &Path,
out_exe: &Path,