From 9d86b46e86690cb0c7f961f5e1e04e281d17ec92 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 22 Mar 2022 15:39:15 +0800 Subject: [PATCH] nac3core: add DEBUG_DUMP_IRRT --- nac3core/build.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nac3core/build.rs b/nac3core/build.rs index b2eda85fb..77ba9fa14 100644 --- a/nac3core/build.rs +++ b/nac3core/build.rs @@ -1,6 +1,7 @@ use regex::Regex; use std::{ env, + fs::File, io::Write, path::Path, process::{Command, Stdio}, @@ -9,6 +10,8 @@ use std::{ fn main() { const FILE: &str = "src/codegen/irrt/irrt.c"; println!("cargo:rerun-if-changed={}", FILE); + let out_dir = env::var("OUT_DIR").unwrap(); + let out_path = Path::new(&out_dir); /* * HACK: Sadly, clang doesn't let us emit generic LLVM bitcode. @@ -50,10 +53,18 @@ fn main() { .unwrap() .replace_all(&filtered_output, ""); + println!("cargo:rerun-if-env-changed=DEBUG_DUMP_IRRT"); + if env::var("DEBUG_DUMP_IRRT").is_ok() { + let mut file = File::create(out_path.join("irrt.ll")).unwrap(); + file.write_all(output.as_bytes()).unwrap(); + let mut file = File::create(out_path.join("irrt-filtered.ll")).unwrap(); + file.write_all(filtered_output.as_bytes()).unwrap(); + } + let mut llvm_as = Command::new("llvm-as") .stdin(Stdio::piped()) .arg("-o") - .arg(Path::new(&env::var("OUT_DIR").unwrap()).join("irrt.bc")) + .arg(out_path.join("irrt.bc")) .spawn() .unwrap(); llvm_as.stdin.as_mut().unwrap().write_all(filtered_output.as_bytes()).unwrap();