Update IR's helper functions

This commit is contained in:
Jeehoon Kang
2020-04-11 12:20:53 +09:00
parent 6edb4665c0
commit 72ec63ea82
19 changed files with 505 additions and 125 deletions

View File

@@ -3,6 +3,7 @@ use std::fs::{self, File};
use std::path::Path;
use std::process::{Command, Stdio};
use tempfile::tempdir;
use wait_timeout::ChildExt;
use crate::*;
@@ -45,18 +46,28 @@ pub fn test_irgen(unit: &TranslationUnit, path: &Path) {
}
// Execute compiled executable
let status = Command::new(fs::canonicalize(bin_path.clone()).unwrap())
.status()
.expect("failed to execute the compiled executable")
.code()
.expect("failed to return an exit code");
let mut child = Command::new(fs::canonicalize(bin_path.clone()).unwrap())
.spawn()
.expect("failed to execute the compiled executable");
// Remove compiled executable
Command::new("rm")
.arg(bin_path)
.status()
.expect("failed to remove compiled executable");
let status = some_or!(
child
.wait_timeout_ms(500)
.expect("failed to obtain exit status from child process"),
{
println!("timeout occurs");
child.kill().unwrap();
child.wait().unwrap();
return;
}
);
let status = some_or!(status.code(), return);
let ir = match Irgen::default().translate(unit) {
Ok(ir) => ir,
Err(irgen_error) => panic!("{}", irgen_error),
@@ -73,5 +84,6 @@ pub fn test_irgen(unit: &TranslationUnit, path: &Path) {
panic!("non-integer value occurs")
};
println!("kecc: {:?}\ngcc: {:?}", result, status);
assert_eq!(result, ir::Value::int(status as u128, 32, true));
}