WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit dcfeb8fc authored by Kunshan Wang's avatar Kunshan Wang
Browse files

IRBuilder: WIP: IR nodes and implementing API...

parent c7865d15
......@@ -26,6 +26,7 @@ use super::super::vm::VM;
use super::api_c::*;
use super::api_bridge::*;
//use super::deps::*; // maybe it is better to import * here.
use super::irnodes::*;
use ast::bundle::*;
use ast::ir::*;
......@@ -97,7 +98,18 @@ pub struct MuIRBuilder<'v> {
/// A trantient bundle, i.e. the bundle being built, but not yet loaded into the MuVM.
#[derive(Default)]
pub struct TrantientBundle {
types: Vec<P<MuType>>,
types: Vec<Box<NodeType>>,
sigs: Vec<Box<NodeFuncSig>>,
consts: Vec<Box<NodeConst>>,
globals: Vec<Box<NodeGlobalCell>>,
funcs: Vec<Box<NodeFunc>>,
expfuncs: Vec<Box<NodeExpFunc>>,
funcvers: Vec<Box<NodeFuncVer>>,
bbs: Vec<Box<NodeBB>>,
insts: Vec<Box<NodeInst>>,
dest_clauses: Vec<Box<NodeDestClause>>,
exc_clauses: Vec<Box<NodeExcClause>>,
ka_clauses: Vec<Box<NodeKeepaliveClause>>,
}
/**
......@@ -621,16 +633,19 @@ impl<'v> MuIRBuilder<'v> {
}
pub fn new_type_int(&mut self, id: MuID, len: c_int) {
let maybe_name = self.consume_name_of(id);
let pty = P(MuType {
hdr: MuEntityHeader {
id: id,
name: RwLock::new(maybe_name),
},
v: MuType_::Int(len as usize),
});
self.bundle.types.push(Box::new(NodeType::TypeInt { id: id, len: len }));
self.bundle.types.push(pty);
// let maybe_name = self.consume_name_of(id);
// let pty = P(MuType {
// hdr: MuEntityHeader {
// id: id,
// name: RwLock::new(maybe_name),
// },
// v: MuType_::Int(len as usize),
// });
//
// self.bundle.types.push(pty);
}
pub fn new_type_float(&mut self, id: MuID) {
......@@ -642,7 +657,8 @@ impl<'v> MuIRBuilder<'v> {
}
pub fn new_type_uptr(&mut self, id: MuID, ty: MuID) {
panic!("Not implemented")
self.bundle.types.push(Box::new(NodeType::TypeUPtr{ id: id,
ty: ty }));
}
pub fn new_type_ufuncptr(&mut self, id: MuID, sig: MuID) {
......@@ -650,7 +666,8 @@ impl<'v> MuIRBuilder<'v> {
}
pub fn new_type_struct(&mut self, id: MuID, fieldtys: Vec<MuID>) {
panic!("Not implemented")
self.bundle.types.push(Box::new(NodeType::TypeStruct { id: id,
fieldtys: fieldtys }));
}
pub fn new_type_hybrid(&mut self, id: MuID, fixedtys: Vec<MuID>, varty: MuID) {
......@@ -706,11 +723,13 @@ impl<'v> MuIRBuilder<'v> {
}
pub fn new_funcsig(&mut self, id: MuID, paramtys: Vec<MuID>, rettys: Vec<MuID>) {
panic!("Not implemented")
self.bundle.sigs.push(Box::new(NodeFuncSig { id: id,
paramtys: paramtys, rettys: rettys }));
}
pub fn new_const_int(&mut self, id: MuID, ty: MuID, value: u64) {
panic!("Not implemented")
self.bundle.consts.push(Box::new(NodeConst::ConstInt { id: id,
ty: ty, value: value }));
}
pub fn new_const_int_ex(&mut self, id: MuID, ty: MuID, values: &[u64]) {
......@@ -738,11 +757,13 @@ impl<'v> MuIRBuilder<'v> {
}
pub fn new_global_cell(&mut self, id: MuID, ty: MuID) {
panic!("Not implemented")
self.bundle.globals.push(Box::new(NodeGlobalCell { id: id,
ty: ty }));
}
pub fn new_func(&mut self, id: MuID, sig: MuID) {
panic!("Not implemented")
self.bundle.funcs.push(Box::new(NodeFunc { id: id,
sig: sig }));
}
pub fn new_exp_func(&mut self, id: MuID, func: MuID, callconv: CMuCallConv, cookie: MuID) {
......@@ -750,11 +771,14 @@ impl<'v> MuIRBuilder<'v> {
}
pub fn new_func_ver(&mut self, id: MuID, func: MuID, bbs: Vec<MuID>) {
panic!("Not implemented")
self.bundle.funcvers.push(Box::new(NodeFuncVer { id: id,
func: func, bbs: bbs }));
}
pub fn new_bb(&mut self, id: MuID, nor_param_ids: Vec<MuID>, nor_param_types: Vec<MuID>, exc_param_id: Option<MuID>, insts: Vec<MuID>) {
panic!("Not implemented")
self.bundle.bbs.push(Box::new(NodeBB { id: id,
norParamIDs: nor_param_ids, norParamTys: nor_param_types,
excParamID: exc_param_id, insts: insts }));
}
pub fn new_dest_clause(&mut self, id: MuID, dest: MuID, vars: Vec<MuID>) {
......@@ -786,7 +810,10 @@ impl<'v> MuIRBuilder<'v> {
}
pub fn new_binop(&mut self, id: MuID, result_id: MuID, optr: CMuBinOptr, ty: MuID, opnd1: MuID, opnd2: MuID, exc_clause: Option<MuID>) {
panic!("Not implemented")
self.bundle.insts.push(Box::new(NodeInst::NodeBinOp {
id: id, resultID: result_id, statusResultIDs: vec![],
optr: optr, flags: 0, ty: ty, opnd1: opnd1, opnd2: opnd2,
excClause: exc_clause}))
}
pub fn new_binop_with_status(&mut self, id: MuID, result_id: MuID, status_result_ids: Vec<MuID>, optr: CMuBinOptr, status_flags: CMuBinOpStatus, ty: MuID, opnd1: MuID, opnd2: MuID, exc_clause: Option<MuID>) {
......
#![allow(non_snake_case)]
#![allow(dead_code)]
use super::deps::*;
//pub type MuID = usize;
pub type MuTypeNode = MuID;
pub type MuFuncSigNode = MuID;
pub type MuVarNode = MuID;
pub type MuGlobalVarNode = MuID;
pub type MuLocalVarNode = MuID;
pub type MuConstNode = MuID;
pub type MuConstIntNode = MuID;
pub type MuFuncNode = MuID;
pub type MuFuncVerNode = MuID;
pub type MuBBNode = MuID;
pub type MuInstNode = MuID;
pub type MuDestClause = MuID;
pub type MuExcClause = MuID;
pub type MuKeepaliveClause = MuID;
pub type MuCurStackClause = MuID;
pub type MuNewStackClause = MuID;
pub type MuWPID = MuID;
pub type Flag = u32;
pub type MuBinOptr = Flag;
pub type MuBinOpStatus = Flag;
pub type MuCmpOptr = Flag;
pub type MuConvOptr = Flag;
pub type MuMemoryOrder = Flag;
pub type MuAtomicRMWOptr = Flag;
pub type MuCommInst = Flag;
#[derive(Debug)]
enum TypeNode {
TypeInt { len: usize },
TypeFloat,
TypeDouble,
TypeUPtr { ty: MuID },
TypeUFuncPtr { sig: MuID },
TypeStruct { fieldtys: Vec<MuID> },
TypeHybrid { fixedtys: Vec<MuID>, varty: MuID },
TypeArray { elemty: MuID, len: usize },
TypeVector { elemty: MuID, lem: usize },
TypeRef { ty: MuID },
TypeIRef { ty: MuID },
TypeWeakRef { ty: MuID },
TypeFuncRef { sig: MuID },
TypeThreadRef,
TypeStackRef,
TypeFrameCursorRef,
pub enum NodeType {
TypeInt { id: MuID, len: i32 },
TypeFloat { id: MuID },
TypeDouble { id: MuID },
TypeUPtr { id: MuID, ty: MuTypeNode },
TypeUFuncPtr { id: MuID, sig: MuFuncSigNode },
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 },
TypeRef { id: MuID, ty: MuTypeNode },
TypeIRef { id: MuID, ty: MuTypeNode },
TypeWeakRef { id: MuID, ty: MuTypeNode },
TypeFuncRef { id: MuID, sig: MuFuncSigNode },
TypeThreadRef { id: MuID },
TypeStackRef { id: MuID },
TypeFrameCursorRef { id: MuID },
TypeIRBuilderRef { id: MuID },
}
struct FuncSigNode { paramtys: Vec<MuID>, rettys: Vec<MuID> };
#[derive(Debug)]
pub struct NodeFuncSig { pub id: MuID, pub paramtys: Vec<MuTypeNode>, pub rettys: Vec<MuTypeNode> }
enum ConstNode {
ConstInt { ty: MuID, value: usize },
ConstFloat { ty: MuID, value: f32 },
ConstDouble { ty: MuID, value: f64 },
ConstNull { ty: MuID },
ConstSeq { ty: MuID, elems: Vec<MuID> },
ConstExtern { ty: MuID, symbol: String },
#[derive(Debug)]
pub enum NodeConst {
ConstInt { id: MuID, ty: MuTypeNode, value: u64 },
ConstFloat { id: MuID, ty: MuTypeNode, value: f32 },
ConstDouble { id: MuID, ty: MuTypeNode, value: f64 },
ConstNull { id: MuID, ty: MuTypeNode },
ConstSeq { id: MuID, ty: MuTypeNode, elems: Vec<MuGlobalVarNode> },
ConstExtern { id: MuID, ty: MuTypeNode, symbol: String },
}
struct GlobalCellNode { ty: MuID };
#[derive(Debug)]
pub struct NodeGlobalCell { pub id: MuID, pub ty: MuTypeNode }
#[derive(Debug)]
pub struct NodeFunc { pub id: MuID, pub sig: MuFuncSigNode }
#[derive(Debug)]
pub struct NodeExpFunc { pub id: MuID, pub func: MuFuncNode, pub callconv: usize, pub cookie: MuConstIntNode }
#[derive(Debug)]
pub struct NodeFuncVer { pub id: MuID, pub func: MuFuncNode, pub bbs: Vec<MuBBNode> }
#[derive(Debug)]
pub struct NodeBB { pub id: MuID, pub norParamIDs: Vec<MuID>, pub norParamTys: Vec<MuTypeNode>, pub excParamID: Option<MuID>, pub insts: Vec<MuInstNode> }
#[derive(Debug)]
pub struct NodeDestClause { pub id: MuID, pub dest: MuBBNode, pub vars: Vec<MuVarNode> }
#[derive(Debug)]
pub struct NodeExcClause { pub id: MuID, pub nor: MuDestClause, pub exc: MuDestClause }
#[derive(Debug)]
pub struct NodeKeepaliveClause { pub id: MuID, pub vars: Vec<MuLocalVarNode> }
struct FuncNode { sig: MuID },
#[derive(Debug)]
pub struct NodeCscRetWith { pub id: MuID, pub rettys: Vec<MuVarNode> }
#[derive(Debug)]
pub struct NodeCscKillOld { pub id: MuID }
#[derive(Debug)]
pub struct NodeNscPassValues { pub id: MuID, pub tys: Vec<MuTypeNode>, pub vars: Vec<MuVarNode> }
#[derive(Debug)]
pub struct NodeNscThrowExc { pub id: MuID, pub exc: MuVarNode }
#[derive(Debug)]
pub enum NodeInst {
NodeBinOp { id: MuID, resultID: MuID, statusResultIDs: Vec<MuID>, optr: MuBinOptr, flags: MuBinOpStatus, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode, excClause: Option<MuExcClause> },
NodeCmp { id: MuID, resultID: MuID, optr: MuCmpOptr, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode },
NodeConv { id: MuID, resultID: MuID, optr: MuConvOptr, fromTy: MuTypeNode, toTy: MuTypeNode, opnd: MuVarNode },
NodeSelect { id: MuID, resultID: MuID, condTy: MuTypeNode, opndTy: MuTypeNode, cond: MuVarNode, ifTrue: MuVarNode, ifFalse: MuVarNode },
NodeBranch { id: MuID, dest: MuDestClause },
NodeBranch2 { id: MuID, cond: MuVarNode, ifTrue: MuDestClause, ifFalse: MuDestClause },
NodeSwitch { id: MuID, opndTy: MuTypeNode, opnd: MuVarNode, defaultDest: MuDestClause, cases: Vec<MuConstNode>, dests: Vec<MuDestClause> },
NodeCall { id: MuID, resultIDs: Vec<MuID>, sig: MuFuncSigNode, callee: MuVarNode, args: Vec<MuVarNode>, excClause: Option<MuExcClause>, keepaliveClause: Option<MuKeepaliveClause> },
NodeTailCall { id: MuID, sig: MuFuncSigNode, callee: MuVarNode, args: Vec<MuVarNode> },
NodeRet { id: MuID, rvs: Vec<MuVarNode> },
NodeThrow { id: MuID, exc: MuVarNode },
NodeExtractValue { id: MuID, resultID: MuID, strty: MuTypeNode, index: i32, opnd: MuVarNode },
NodeInsertValue { id: MuID, resultID: MuID, strty: MuTypeNode, index: i32, opnd: MuVarNode, newval: MuVarNode },
NodeExtractElement { id: MuID, resultID: MuID, seqty: MuTypeNode, indty: MuTypeNode, opnd: MuVarNode, index: MuVarNode },
NodeInsertElement { id: MuID, resultID: MuID, seqty: MuTypeNode, indty: MuTypeNode, opnd: MuVarNode, index: MuVarNode, newval: MuVarNode },
NodeShuffleVector { id: MuID, resultID: MuID, vecty: MuTypeNode, maskty: MuTypeNode, vec1: MuVarNode, vec2: MuVarNode, mask: MuVarNode },
NodeNew { id: MuID, resultID: MuID, allocty: MuTypeNode, excClause: Option<MuExcClause> },
NodeNewHybrid { id: MuID, resultID: MuID, allocty: MuTypeNode, lenty: MuTypeNode, length: MuVarNode, excClause: Option<MuExcClause> },
NodeAlloca { id: MuID, resultID: MuID, allocty: MuTypeNode, excClause: Option<MuExcClause> },
NodeAllocaHybrid { id: MuID, resultID: MuID, allocty: MuTypeNode, lenty: MuTypeNode, length: MuVarNode, excClause: Option<MuExcClause> },
NodeGetIRef { id: MuID, resultID: MuID, refty: MuTypeNode, opnd: MuVarNode },
NodeGetFieldIRef { id: MuID, resultID: MuID, isPtr: bool, refty: MuTypeNode, index: i32, opnd: MuVarNode },
NodeGetElemIRef { id: MuID, resultID: MuID, isPtr: bool, refty: MuTypeNode, indty: MuTypeNode, opnd: MuVarNode, index: MuVarNode },
NodeShiftIRef { id: MuID, resultID: MuID, isPtr: bool, refty: MuTypeNode, offty: MuTypeNode, opnd: MuVarNode, offset: MuVarNode },
NodeGetVarPartIRef { id: MuID, resultID: MuID, isPtr: bool, refty: MuTypeNode, opnd: MuVarNode },
NodeLoad { id: MuID, resultID: MuID, isPtr: bool, ord: MuMemoryOrder, refty: MuTypeNode, loc: MuVarNode, excClause: Option<MuExcClause> },
NodeStore { id: MuID, isPtr: bool, ord: MuMemoryOrder, refty: MuTypeNode, loc: MuVarNode, newval: MuVarNode, excClause: Option<MuExcClause> },
NodeCmpXchg { id: MuID, valueResultID: MuID, succResultID: MuID, isPtr: bool, isWeak: bool, ordSucc: MuMemoryOrder, ordFail: MuMemoryOrder, refty: MuTypeNode, loc: MuVarNode, expected: MuVarNode, desired: MuVarNode, excClause: Option<MuExcClause> },
NodeAtomicRMW { id: MuID, resultID: MuID, isPtr: bool, ord: MuMemoryOrder, optr: MuAtomicRMWOptr, refTy: MuTypeNode, loc: MuVarNode, opnd: MuVarNode, excClause: Option<MuExcClause> },
NodeFence { id: MuID, ord: MuMemoryOrder, },
NodeTrap { id: MuID, resultIDs: Vec<MuID>, rettys: Vec<MuTypeNode>, excClause: Option<MuExcClause>, keepaliveClause: Option<MuKeepaliveClause> },
NodeWatchPoint { id: MuID, wpid: MuWPID, resultIDs: Vec<MuID>, rettys: Vec<MuTypeNode>, dis: MuDestClause, ena: MuDestClause, exc: Option<MuDestClause>, keepaliveClause: Option<MuKeepaliveClause> },
NodeWPBranch { id: MuID, wpid: MuWPID, dis: MuDestClause, ena: MuDestClause },
NodeCCall { id: MuID, resultIDs: Vec<MuID>, callconv: Flag, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Vec<MuVarNode>, excClause: Option<MuExcClause>, keepaliveClause: Option<MuKeepaliveClause> },
NodeNewThread { id: MuID, resultID: MuID, stack: MuVarNode, threadlocal: Option<MuVarNode>, newStackClause: MuNewStackClause, excClause: Option<MuExcClause> },
NodeSwapStack { id: MuID, resultIDs: Vec<MuID>, swappee: MuVarNode, curStackClause: MuCurStackClause, newStackClause: MuNewStackClause, excClause: Option<MuExcClause>, keepaliveClause: Option<MuKeepaliveClause> },
NodeCommInst { id: MuID, resultIDs: Vec<MuID>, opcode: MuCommInst, flags: Vec<Flag>, tys: Vec<MuTypeNode>, sigs: Vec<MuFuncSigNode>, args: Vec<MuVarNode>, excClause: Option<MuExcClause>, keepaliveClause: Option<MuKeepaliveClause> },
}
pub mod api_c; // This is pub because `api_c` can be used directly. It is just an interface.
mod api_bridge; // This is mostly auto-generatd code, and should not be used externally.
mod api_impl; // Mostly private.
mod irnodes;
pub use self::api_impl::mu_fastimpl_new;
......
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