Improve --irrun option to print byte size value

This commit is contained in:
Chunmyong Park
2020-06-10 02:45:57 +00:00
parent 5101b294b6
commit 9ca05ba893
2 changed files with 13 additions and 7 deletions

View File

@@ -116,7 +116,13 @@ fn compile_ir(
if matches.is_present("irrun") {
let result = ir::interp(input, Vec::new()).unwrap();
println!("[result] {:?}", result);
let (value, width, is_signed) = result.get_int().expect("non-integer value occurs");
assert_eq!(width, 32);
assert!(is_signed);
// When obtain status from `gcc` executable process, status value is truncated to byte size.
// So, we also truncate result value to byte size before printing it.
println!("[result] {:?}", value as u8);
return;
}

View File

@@ -115,8 +115,8 @@ pub fn test_irgen(path: &Path) {
// For this reason, we make `fuzzer` generate the C source code which returns value
// typecasted to `unsigned char`. However, during `creduce` reduce the code, typecasting
// may be deleted. So, we truncate result value to byte size one more time here.
println!("gcc: {}, kecc: {}", status as i8, value as i8);
assert_eq!(status as i8, value as i8);
println!("gcc: {}, kecc: {}", status as u8, value as u8);
assert_eq!(status as u8, value as u8);
}
pub fn test_irparse(path: &Path) {
@@ -297,8 +297,8 @@ pub fn test_asmgen(path: &Path) {
let qemu_status = some_or_exit!(status.code(), SKIP_TEST);
println!("kecc interp: {}, qemu: {}", value as i8, qemu_status as i8);
assert_eq!(value as i8, qemu_status as i8);
println!("kecc interp: {}, qemu: {}", value as u8, qemu_status as u8);
assert_eq!(value as u8, qemu_status as u8);
}
// TODO: test all the way down to assembly
@@ -397,6 +397,6 @@ pub fn test_end_to_end(path: &Path) {
// For this reason, we make `fuzzer` generate the C source code which returns value
// typecasted to `unsigned char`. However, during `creduce` reduce the code, typecasting
// may be deleted. So, we truncate result value to byte size one more time here.
println!("gcc: {}, kecc: {}", status as i8, value as i8);
assert_eq!(status as i8, value as i8);
println!("gcc: {}, kecc: {}", status as u8, value as u8);
assert_eq!(status as u8, value as u8);
}