Commit 081adbdd authored by qinsoon's avatar qinsoon

fix a false assumption about used frame size

parent 5873b545
......@@ -65,14 +65,12 @@ impl Frame {
// frame size is a multiple of 16 bytes
let size = self.cur_offset.abs() as usize;
// frame size is at least 8 byte aligned
assert!(size % 8 == 0);
// align size to a multiple of 16 bytes
let size = (size + 16 - 1) & !(16 - 1);
if size % 16 == 0 {
size
} else {
size + 8
}
debug_assert!(size % 16 == 0);
size
}
pub fn add_argument_by_reg(&mut self, temp: MuID, reg: P<Value>) {
......
......@@ -1265,4 +1265,245 @@ fn create_empty_func_foo6(vm: &VM) {
});
define_func_ver!((vm) foo6_v1 (entry: blk_entry) {blk_entry});
}
#[test]
#[allow(unused_variables)]
fn test_spill_int8() {
VM::start_logging_trace();
let vm = Arc::new(spill_int8());
let compiler = Compiler::new(CompilerPolicy::default(), &vm);
let func_id = vm.id_of("spill_int8");
{
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
backend::emit_context(&vm);
let dylib = aot::link_dylib(vec![Mu("spill_int8")], &testutil::get_dylib_name("spill_int8"), &vm);
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
let spill_int8 : libloading::Symbol<unsafe extern fn() -> u8> = match lib.get(b"spill_int8") {
Ok(symbol) => symbol,
Err(e) => panic!("cannot find symbol spill_int8 in dylib: {:?}", e)
};
let res = spill_int8();
println!("spill_int8() = {}", res);
assert_eq!(res, 136);
}
}
fn spill_int8() -> VM {
let vm = VM::new();
typedef! ((vm) int8 = mu_int(8));
constdef! ((vm) <int8> int8_0 = Constant::Int(0));
constdef! ((vm) <int8> int8_1 = Constant::Int(1));
constdef! ((vm) <int8> int8_2 = Constant::Int(2));
constdef! ((vm) <int8> int8_3 = Constant::Int(3));
constdef! ((vm) <int8> int8_4 = Constant::Int(4));
constdef! ((vm) <int8> int8_5 = Constant::Int(5));
constdef! ((vm) <int8> int8_6 = Constant::Int(6));
constdef! ((vm) <int8> int8_7 = Constant::Int(7));
constdef! ((vm) <int8> int8_8 = Constant::Int(8));
constdef! ((vm) <int8> int8_9 = Constant::Int(9));
constdef! ((vm) <int8> int8_10 = Constant::Int(10));
constdef! ((vm) <int8> int8_11 = Constant::Int(11));
constdef! ((vm) <int8> int8_12 = Constant::Int(12));
constdef! ((vm) <int8> int8_13 = Constant::Int(13));
constdef! ((vm) <int8> int8_14 = Constant::Int(14));
constdef! ((vm) <int8> int8_15 = Constant::Int(15));
constdef! ((vm) <int8> int8_16 = Constant::Int(16));
funcsig! ((vm) sig = () -> (int8));
funcdecl! ((vm) <sig> spill_int8);
funcdef! ((vm) <sig> spill_int8 VERSION spill_int8_v1);
block! ((vm, spill_int8_v1) blk_entry);
consta! ((vm, spill_int8_v1) int8_0_local = int8_0);
consta! ((vm, spill_int8_v1) int8_1_local = int8_1);
consta! ((vm, spill_int8_v1) int8_2_local = int8_2);
consta! ((vm, spill_int8_v1) int8_3_local = int8_3);
consta! ((vm, spill_int8_v1) int8_4_local = int8_4);
consta! ((vm, spill_int8_v1) int8_5_local = int8_5);
consta! ((vm, spill_int8_v1) int8_6_local = int8_6);
consta! ((vm, spill_int8_v1) int8_7_local = int8_7);
consta! ((vm, spill_int8_v1) int8_8_local = int8_8);
consta! ((vm, spill_int8_v1) int8_9_local = int8_9);
consta! ((vm, spill_int8_v1) int8_10_local= int8_10);
consta! ((vm, spill_int8_v1) int8_11_local= int8_11);
consta! ((vm, spill_int8_v1) int8_12_local= int8_12);
consta! ((vm, spill_int8_v1) int8_13_local= int8_13);
consta! ((vm, spill_int8_v1) int8_14_local= int8_14);
consta! ((vm, spill_int8_v1) int8_15_local= int8_15);
consta! ((vm, spill_int8_v1) int8_16_local= int8_16);
block! ((vm, spill_int8_v1) blk_ret);
inst! ((vm, spill_int8_v1) blk_entry_branch:
BRANCH blk_ret (
int8_0_local,
int8_1_local,
int8_2_local,
int8_3_local,
int8_4_local,
int8_5_local,
int8_6_local,
int8_7_local,
int8_8_local,
int8_9_local,
int8_10_local,
int8_11_local,
int8_12_local,
int8_13_local,
int8_14_local,
int8_15_local,
int8_16_local
)
);
define_block!((vm, spill_int8_v1) blk_entry() {
blk_entry_branch
});
ssa! ((vm, spill_int8_v1) <int8> v0);
ssa! ((vm, spill_int8_v1) <int8> v1);
ssa! ((vm, spill_int8_v1) <int8> v2);
ssa! ((vm, spill_int8_v1) <int8> v3);
ssa! ((vm, spill_int8_v1) <int8> v4);
ssa! ((vm, spill_int8_v1) <int8> v5);
ssa! ((vm, spill_int8_v1) <int8> v6);
ssa! ((vm, spill_int8_v1) <int8> v7);
ssa! ((vm, spill_int8_v1) <int8> v8);
ssa! ((vm, spill_int8_v1) <int8> v9);
ssa! ((vm, spill_int8_v1) <int8> v10);
ssa! ((vm, spill_int8_v1) <int8> v11);
ssa! ((vm, spill_int8_v1) <int8> v12);
ssa! ((vm, spill_int8_v1) <int8> v13);
ssa! ((vm, spill_int8_v1) <int8> v14);
ssa! ((vm, spill_int8_v1) <int8> v15);
ssa! ((vm, spill_int8_v1) <int8> v16);
ssa! ((vm, spill_int8_v1) <int8> res1);
inst! ((vm, spill_int8_v1) blk_ret_add1:
res1 = BINOP (BinOp::Add) v0 v1
);
ssa! ((vm, spill_int8_v1) <int8> res2);
inst! ((vm, spill_int8_v1) blk_ret_add2:
res2 = BINOP (BinOp::Add) res1 v2
);
ssa! ((vm, spill_int8_v1) <int8> res3);
inst! ((vm, spill_int8_v1) blk_ret_add3:
res3 = BINOP (BinOp::Add) res2 v3
);
ssa! ((vm, spill_int8_v1) <int8> res4);
inst! ((vm, spill_int8_v1) blk_ret_add4:
res4 = BINOP (BinOp::Add) res3 v4
);
ssa! ((vm, spill_int8_v1) <int8> res5);
inst! ((vm, spill_int8_v1) blk_ret_add5:
res5 = BINOP (BinOp::Add) res4 v5
);
ssa! ((vm, spill_int8_v1) <int8> res6);
inst! ((vm, spill_int8_v1) blk_ret_add6:
res6 = BINOP (BinOp::Add) res5 v6
);
ssa! ((vm, spill_int8_v1) <int8> res7);
inst! ((vm, spill_int8_v1) blk_ret_add7:
res7 = BINOP (BinOp::Add) res6 v7
);
ssa! ((vm, spill_int8_v1) <int8> res8);
inst! ((vm, spill_int8_v1) blk_ret_add8:
res8 = BINOP (BinOp::Add) res7 v8
);
ssa! ((vm, spill_int8_v1) <int8> res9);
inst! ((vm, spill_int8_v1) blk_ret_add9:
res9 = BINOP (BinOp::Add) res8 v9
);
ssa! ((vm, spill_int8_v1) <int8> res10);
inst! ((vm, spill_int8_v1) blk_ret_add10:
res10 = BINOP (BinOp::Add) res9 v10
);
ssa! ((vm, spill_int8_v1) <int8> res11);
inst! ((vm, spill_int8_v1) blk_ret_add11:
res11 = BINOP (BinOp::Add) res10 v11
);
ssa! ((vm, spill_int8_v1) <int8> res12);
inst! ((vm, spill_int8_v1) blk_ret_add12:
res12 = BINOP (BinOp::Add) res11 v12
);
ssa! ((vm, spill_int8_v1) <int8> res13);
inst! ((vm, spill_int8_v1) blk_ret_add13:
res13 = BINOP (BinOp::Add) res12 v13
);
ssa! ((vm, spill_int8_v1) <int8> res14);
inst! ((vm, spill_int8_v1) blk_ret_add14:
res14 = BINOP (BinOp::Add) res13 v14
);
ssa! ((vm, spill_int8_v1) <int8> res15);
inst! ((vm, spill_int8_v1) blk_ret_add15:
res15 = BINOP (BinOp::Add) res14 v15
);
ssa! ((vm, spill_int8_v1) <int8> res16);
inst! ((vm, spill_int8_v1) blk_ret_add16:
res16 = BINOP (BinOp::Add) res15 v16
);
inst! ((vm, spill_int8_v1) blk_ret_ret:
RET (res16)
);
define_block! ((vm, spill_int8_v1) blk_ret(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) {
blk_ret_add1,
blk_ret_add2,
blk_ret_add3,
blk_ret_add4,
blk_ret_add5,
blk_ret_add6,
blk_ret_add7,
blk_ret_add8,
blk_ret_add9,
blk_ret_add10,
blk_ret_add11,
blk_ret_add12,
blk_ret_add13,
blk_ret_add14,
blk_ret_add15,
blk_ret_add16,
blk_ret_ret
});
define_func_ver!((vm) spill_int8_v1 (entry: blk_entry) {
blk_entry,
blk_ret
});
vm
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment