Commit 6b0b9650 authored by Kunshan Wang's avatar Kunshan Wang

IRBuilder: WIP: Attempt to build CALL

Still panics. need to debug
parent 98f275bf
Pipeline #37 failed with stage
in 8 minutes and 4 seconds
This diff is collapsed.
......@@ -177,13 +177,16 @@ fn test_function_loading() {
((*b).new_type_int)(b, id_i64, 64);
let mut ptys = vec![id_i32];
let mut rtys = vec![id_i64];
let mut rtys = vec![id_i32];
((*b).new_funcsig)(b, id_sig,
ptys.as_mut_ptr(), ptys.len(),
rtys.as_mut_ptr(), rtys.len());
((*b).new_func)(b, id_func, id_sig);
let id_const1 = ((*b).gen_sym)(b, csp.get("@const_i32_1"));
((*b).new_const_int)(b, id_const1, id_i32, 1);
let id_const99 = ((*b).gen_sym)(b, csp.get("@const_i32_99"));
((*b).new_const_int)(b, id_const99, id_i32, 99);
......@@ -191,9 +194,16 @@ fn test_function_loading() {
let id_entry = ((*b).gen_sym)(b, csp.get("@func.v1.entry"));
let id_bb1 = ((*b).gen_sym)(b, csp.get("@func.v1.bb1"));
let id_bb2 = ((*b).gen_sym)(b, csp.get("@func.v1.bb2"));
let id_bb3 = ((*b).gen_sym)(b, csp.get("@func.v1.bb3"));
let id_bb4 = ((*b).gen_sym)(b, csp.get("@func.v1.bb4"));
let id_bb5 = ((*b).gen_sym)(b, csp.get("@func.v1.bb5"));
let id_bbxxx = ((*b).gen_sym)(b, csp.get("@func.v1.bbxxx"));
let mut bbs = vec![id_entry, id_bb1, id_bbxxx];
let mut bbs = vec![
id_entry, id_bb1, id_bb2, id_bb3, id_bb4,
id_bb5, id_bbxxx,
];
((*b).new_func_ver)(b, id_funcver, id_func, bbs.as_mut_ptr(), bbs.len());
{
......@@ -239,15 +249,119 @@ fn test_function_loading() {
((*b).new_ret)(b, id_ret, rvs.as_mut_ptr(), rvs.len())
}
{
let id_x = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.x"));
let id_add = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.add"));
let id_eq = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.eq"));
let id_br2 = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.br2"));
let mut args = vec![id_x];
let mut argtys = vec![id_i32];
let mut insts = vec![id_add, id_eq, id_br2];
((*b).new_bb)(b, id_bb2,
args.as_mut_ptr(), argtys.as_mut_ptr(), args.len(),
0,
insts.as_mut_ptr(), insts.len());
let id_y = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.y"));
((*b).new_binop)(b, id_add, id_y, CMU_BINOP_ADD, id_i32, id_x, id_const1, 0);
let id_e = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.x"));
((*b).new_cmp)(b, id_eq, id_e, CMU_CMP_EQ, id_i32, id_x, id_const99);
let id_dest_t = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.dest_t"));
let id_dest_f = ((*b).gen_sym)(b, csp.get("@func.v1.bb2.dest_f"));
{
let mut dest_args = vec![id_x];
((*b).new_dest_clause)(b, id_dest_t, id_bb3, dest_args.as_mut_ptr(), dest_args.len());
}
{
let mut dest_args = vec![id_y, id_y, id_x];
((*b).new_dest_clause)(b, id_dest_f, id_bb4, dest_args.as_mut_ptr(), dest_args.len());
}
((*b).new_branch2)(b, id_br2, id_e, id_dest_t, id_dest_f);
}
{
let id_x = ((*b).gen_sym)(b, csp.get("@func.v1.bb3.x"));
let id_ret = ((*b).gen_sym)(b, csp.get("@func.v1.bb3.ret"));
let mut args = vec![id_x];
let mut argtys = vec![id_i32];
let mut insts = vec![id_ret];
((*b).new_bb)(b, id_bb3,
args.as_mut_ptr(), argtys.as_mut_ptr(), args.len(),
0,
insts.as_mut_ptr(), insts.len());
let mut rvs = vec![id_const99];
((*b).new_ret)(b, id_ret, rvs.as_mut_ptr(), rvs.len())
}
{
let id_x = ((*b).gen_sym)(b, csp.get("@func.v1.bb4.x"));
let id_y = ((*b).gen_sym)(b, csp.get("@func.v1.bb4.y"));
let id_z = ((*b).gen_sym)(b, csp.get("@func.v1.bb4.z"));
let id_ret = ((*b).gen_sym)(b, csp.get("@func.v1.bb4.ret"));
let mut args = vec![id_x, id_y, id_z];
let mut argtys = vec![id_i32, id_i32, id_i32];
let mut insts = vec![id_ret];
((*b).new_bb)(b, id_bb4,
args.as_mut_ptr(), argtys.as_mut_ptr(), args.len(),
0,
insts.as_mut_ptr(), insts.len());
let mut rvs = vec![id_const99];
((*b).new_ret)(b, id_ret, rvs.as_mut_ptr(), rvs.len())
}
{
let id_exc = ((*b).gen_sym)(b, csp.get("@func.v1.bbxxx.exc"));
let id_ret = ((*b).gen_sym)(b, csp.get("@func.v1.bbxxx.ret"));
let mut args = vec![];
let mut argtys = vec![];
let mut insts = vec![];
let mut insts = vec![id_ret];
((*b).new_bb)(b, id_bbxxx,
args.as_mut_ptr(), argtys.as_mut_ptr(), args.len(),
id_exc,
insts.as_mut_ptr(), insts.len());
let mut rvs = vec![id_const99];
((*b).new_ret)(b, id_ret, rvs.as_mut_ptr(), rvs.len())
}
{
let id_x = ((*b).gen_sym)(b, csp.get("@func.v1.bb5.x"));
let id_add = ((*b).gen_sym)(b, csp.get("@func.v1.bb5.add"));
let id_switch = ((*b).gen_sym)(b, csp.get("@func.v1.bb5.switch"));
let mut args = vec![id_x];
let mut argtys = vec![id_i32];
let mut insts = vec![id_add, id_switch];
((*b).new_bb)(b, id_bb5,
args.as_mut_ptr(), argtys.as_mut_ptr(), args.len(),
0,
insts.as_mut_ptr(), insts.len());
let id_y = ((*b).gen_sym)(b, csp.get("@func.v1.bb5.y"));
((*b).new_binop)(b, id_add, id_y, CMU_BINOP_ADD, id_i32, id_x, id_const1, 0);
let id_dest_def = ((*b).gen_sym)(b, csp.get("@func.v1.bb5.dest_def"));
let id_dest_99 = ((*b).gen_sym)(b, csp.get("@func.v1.bb5.dest_99"));
{
let mut dest_args = vec![id_x];
((*b).new_dest_clause)(b, id_dest_def, id_bb3, dest_args.as_mut_ptr(), dest_args.len());
}
{
let mut dest_args = vec![id_y, id_y, id_x];
((*b).new_dest_clause)(b, id_dest_99, id_bb4, dest_args.as_mut_ptr(), dest_args.len());
}
let mut cases = vec![id_const99];
let mut dests = vec![id_dest_99];
((*b).new_switch)(b, id_switch, id_i32, id_y, id_dest_def,
cases.as_mut_ptr(), dests.as_mut_ptr(), cases.len())
}
((*b).load)(b);
......@@ -257,4 +371,81 @@ fn test_function_loading() {
}
}
#[test]
#[allow(unused_variables)]
fn test_insts_call() {
let mut csp: CStringPool = Default::default();
unsafe {
simple_logger::init_with_level(log::LogLevel::Trace).ok();
info!("Starting micro VM...");
let mvm = mu_fastimpl_new();
let ctx = ((*mvm).new_context)(mvm);
let b = ((*ctx).new_ir_builder)(ctx);
let id_i32 = ((*b).gen_sym)(b, csp.get("@i32"));
let id_i64 = ((*b).gen_sym)(b, csp.get("@i64"));
let id_sig = ((*b).gen_sym)(b, csp.get("@sig"));
let id_func = ((*b).gen_sym)(b, csp.get("@func"));
((*b).new_type_int)(b, id_i32, 32);
((*b).new_type_int)(b, id_i64, 64);
let mut ptys = vec![id_i32];
let mut rtys = vec![id_i32];
((*b).new_funcsig)(b, id_sig,
ptys.as_mut_ptr(), ptys.len(),
rtys.as_mut_ptr(), rtys.len());
((*b).new_func)(b, id_func, id_sig);
let id_const1 = ((*b).gen_sym)(b, csp.get("@const_i32_1"));
((*b).new_const_int)(b, id_const1, id_i32, 1);
let id_const99 = ((*b).gen_sym)(b, csp.get("@const_i32_99"));
((*b).new_const_int)(b, id_const99, id_i32, 99);
let id_funcver = ((*b).gen_sym)(b, csp.get("@func.v1"));
let id_entry = ((*b).gen_sym)(b, csp.get("@func.v1.entry"));
let id_bb1 = ((*b).gen_sym)(b, csp.get("@func.v1.bb1"));
let id_bb2 = ((*b).gen_sym)(b, csp.get("@func.v1.bb2"));
let mut bbs = vec![
id_entry, id_bb1, id_bb2,
];
((*b).new_func_ver)(b, id_funcver, id_func, bbs.as_mut_ptr(), bbs.len());
{
let id_x = ((*b).gen_sym)(b, csp.get("@func.v1.entry.x"));
let mut args = vec![id_x];
let mut argtys = vec![id_i32];
let id_call1 = ((*b).gen_sym)(b, csp.get("@func.v1.entry.call1"));
let id_call2 = ((*b).gen_sym)(b, csp.get("@func.v1.entry.call2"));
let mut insts = vec![id_call1];//, id_call2];
((*b).new_bb)(b, id_entry,
args.as_mut_ptr(), argtys.as_mut_ptr(), args.len(),
0,
insts.as_mut_ptr(), insts.len());
let id_y = ((*b).gen_sym)(b, csp.get("@func.v1.entry.y"));
let mut args = vec![id_x];
let mut rvs = vec![id_y];
((*b).new_call)(b, id_call1,
rvs.as_mut_ptr(), rvs.len(),
id_sig, id_func, args.as_mut_ptr(), args.len(), 0, 0);
}
((*b).load)(b);
((*ctx).close_context)(ctx);
info!("Finished.");
}
}
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