Commit 215df3c1 authored by Kunshan Wang's avatar Kunshan Wang

IRBuilder: Builds most types, consts and NEW

Added supports for all types.

Support Const NULL

Support conversions, the TAILCALL and NEW instructions
parent 0ef55d45
Pipeline #79 failed with stage
in 19 minutes and 42 seconds
......@@ -4,6 +4,7 @@ use inst::*;
use op::*;
use utils::vec_utils;
use utils::Address;
use std::collections::HashMap;
use std::fmt;
......@@ -735,6 +736,8 @@ pub enum Constant {
FuncRef(MuID),
UFuncRef(MuID),
Vector(Vec<Constant>),
//Pointer(Address),
NullRef,
}
impl fmt::Display for Constant {
......@@ -756,6 +759,7 @@ impl fmt::Display for Constant {
}
write!(f, "]")
}
&Constant::NullRef => write!(f, "NullRef"),
}
}
}
......
......@@ -42,7 +42,10 @@ pub enum NodeType {
TypeStruct { id: MuID, fieldtys: Vec<MuTypeNode> },
TypeHybrid { id: MuID, fixedtys: Vec<MuTypeNode>, varty: MuTypeNode },
TypeArray { id: MuID, elemty: MuTypeNode, len: usize },
TypeVector { id: MuID, elemty: MuTypeNode, lem: usize },
TypeVector { id: MuID, elemty: MuTypeNode, len: usize },
TypeVoid { id: MuID },
TypeTagRef64 { id: MuID },
TypeRef { id: MuID, ty: MuTypeNode },
TypeIRef { id: MuID, ty: MuTypeNode },
......
This diff is collapsed.
......@@ -144,6 +144,11 @@ fn test_consts_loading() {
((*b).new_type_int)(b, id1, 32);
((*b).new_const_int)(b, id2, id1, 42);
let id_refi32 = ((*b).gen_sym)(b, csp.get("@refi32"));
let id_nullrefi32 = ((*b).gen_sym)(b, csp.get("@CONST_REFI32_NULL"));
((*b).new_type_ref)(b, id_refi32, id1);
((*b).new_const_null)(b, id_nullrefi32, id_refi32);
((*b).load)(b);
((*ctx).close_context)(ctx);
......@@ -505,6 +510,76 @@ fn test_insts_call() {
}
((*b).load)(b);
((*ctx).close_context)(ctx);
info!("Finished.");
}
}
#[test]
#[allow(unused_variables)]
fn test_insts_new() {
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_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);
let mut ptys = vec![];
let mut rtys = vec![];
((*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_funcver = ((*b).gen_sym)(b, csp.get("@func.v1"));
let id_entry = ((*b).gen_sym)(b, csp.get("@func.v1.entry"));
let mut bbs = vec![
id_entry,
];
((*b).new_func_ver)(b, id_funcver, id_func, bbs.as_mut_ptr(), bbs.len());
{
let mut args = vec![];
let mut argtys = vec![];
let id_new = ((*b).gen_sym)(b, csp.get("@func.v1.entry.new"));
let id_ret = ((*b).gen_sym)(b, csp.get("@func.v1.entry.ret"));
let mut insts = vec![id_new, id_ret];
((*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_x = ((*b).gen_sym)(b, csp.get("@func.v1.entry.x"));
((*b).new_new)(b, id_new, id_x, id_i32, 0);
{
let mut args = vec![];
((*b).new_ret)(b, id_ret, args.as_mut_ptr(), args.len());
}
}
((*b).load)(b);
((*ctx).close_context)(ctx);
......
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