forked from M-Labs/nac3
1
0
Fork 0

nac3core: add DEBUG_DUMP_IRRT

This commit is contained in:
Sebastien Bourdeauducq 2022-03-22 15:39:15 +08:00
parent 263bc82434
commit 9d86b46e86
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,7 @@
use regex::Regex; use regex::Regex;
use std::{ use std::{
env, env,
fs::File,
io::Write, io::Write,
path::Path, path::Path,
process::{Command, Stdio}, process::{Command, Stdio},
@ -9,6 +10,8 @@ use std::{
fn main() { fn main() {
const FILE: &str = "src/codegen/irrt/irrt.c"; const FILE: &str = "src/codegen/irrt/irrt.c";
println!("cargo:rerun-if-changed={}", FILE); 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. * HACK: Sadly, clang doesn't let us emit generic LLVM bitcode.
@ -50,10 +53,18 @@ fn main() {
.unwrap() .unwrap()
.replace_all(&filtered_output, ""); .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") let mut llvm_as = Command::new("llvm-as")
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.arg("-o") .arg("-o")
.arg(Path::new(&env::var("OUT_DIR").unwrap()).join("irrt.bc")) .arg(out_path.join("irrt.bc"))
.spawn() .spawn()
.unwrap(); .unwrap();
llvm_as.stdin.as_mut().unwrap().write_all(filtered_output.as_bytes()).unwrap(); llvm_as.stdin.as_mut().unwrap().write_all(filtered_output.as_bytes()).unwrap();