GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 470eac11 authored by qinsoon's avatar qinsoon

[wip] refactored TreeNode

parent 8f9266c0
......@@ -10,21 +10,25 @@ use std::sync::RwLock;
#[derive(Debug)]
pub struct Instruction {
pub hdr: MuEntityHeader,
pub value : Option<Vec<P<Value>>>,
pub ops : RwLock<Vec<P<TreeNode>>>,
pub v: Instruction_
}
impl_mu_entity!(Instruction);
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
impl Encodable for Instruction {
fn encode<S: Encoder> (&self, s: &mut S) -> Result<(), S::Error> {
s.emit_struct("Instruction", 3, |s| {
try!(s.emit_struct_field("value", 0, |s| self.value.encode(s)));
s.emit_struct("Instruction", 4, |s| {
try!(s.emit_struct_field("hdr", 0, |s| self.hdr.encode(s)));
try!(s.emit_struct_field("value", 1, |s| self.value.encode(s)));
let ops = &self.ops.read().unwrap();
try!(s.emit_struct_field("ops", 1, |s| ops.encode(s)));
try!(s.emit_struct_field("ops", 2, |s| ops.encode(s)));
try!(s.emit_struct_field("v", 2, |s| self.v.encode(s)));
try!(s.emit_struct_field("v", 3, |s| self.v.encode(s)));
Ok(())
})
......@@ -33,14 +37,16 @@ impl Encodable for Instruction {
impl Decodable for Instruction {
fn decode<D: Decoder>(d: &mut D) -> Result<Instruction, D::Error> {
d.read_struct("Instruction", 3, |d| {
let value = try!(d.read_struct_field("value", 0, |d| Decodable::decode(d)));
d.read_struct("Instruction", 4, |d| {
let hdr = try!(d.read_struct_field("hdr", 0, |d| Decodable::decode(d)));
let value = try!(d.read_struct_field("value", 1, |d| Decodable::decode(d)));
let ops = try!(d.read_struct_field("ops", 1, |d| Decodable::decode(d)));
let ops = try!(d.read_struct_field("ops", 2, |d| Decodable::decode(d)));
let v = try!(d.read_struct_field("v", 2, |d| Decodable::decode(d)));
let v = try!(d.read_struct_field("v", 3, |d| Decodable::decode(d)));
Ok(Instruction{
hdr: hdr,
value: value,
ops: RwLock::new(ops),
v: v
......@@ -52,6 +58,7 @@ impl Decodable for Instruction {
impl Clone for Instruction {
fn clone(&self) -> Self {
Instruction {
hdr: self.hdr.clone(),
value: self.value.clone(),
ops: RwLock::new(self.ops.read().unwrap().clone()),
v: self.v.clone()
......
......@@ -158,31 +158,27 @@ impl MuFunctionVersion {
self.context.values.insert(id, SSAVarEntry::new(val.clone()));
P(TreeNode {
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_ssa(&val.ty),
v: TreeNode_::Value(val)
})
}
pub fn new_constant(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> {
pub fn new_constant(&mut self, v: P<Value>) -> P<TreeNode> {
P(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v)
})
}
pub fn new_global(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> {
pub fn new_global(&mut self, v: P<Value>) -> P<TreeNode> {
P(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v)
})
}
pub fn new_inst(&mut self, id: MuID, v: Instruction) -> Box<TreeNode> {
pub fn new_inst(&mut self, v: Instruction) -> Box<TreeNode> {
Box::new(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v),
})
......@@ -257,7 +253,6 @@ impl FunctionContext {
self.values.insert(id, SSAVarEntry::new(val.clone()));
P(TreeNode {
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_ssa(&val.ty),
v: TreeNode_::Value(val)
})
......@@ -459,16 +454,14 @@ impl BlockContent {
#[derive(Debug, RustcEncodable, RustcDecodable, Clone)]
/// always use with P<TreeNode>
pub struct TreeNode {
pub hdr: MuEntityHeader,
pub op: OpCode,
pub v: TreeNode_,
}
impl TreeNode {
// this is a hack to allow creating TreeNode without using a &mut MuFunctionVersion
pub fn new_inst(id: MuID, v: Instruction) -> P<TreeNode> {
pub fn new_inst(v: Instruction) -> P<TreeNode> {
P(TreeNode{
hdr: MuEntityHeader::unnamed(id),
op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v),
})
......@@ -895,11 +888,40 @@ pub trait MuEntity {
impl_mu_entity!(MuFunction);
impl_mu_entity!(MuFunctionVersion);
impl_mu_entity!(Block);
impl_mu_entity!(TreeNode);
impl_mu_entity!(MuType);
impl_mu_entity!(Value);
impl_mu_entity!(MuFuncSig);
impl MuEntity for TreeNode {
fn id(&self) -> MuID {
match self.v {
TreeNode_::Instruction(ref inst) => inst.id(),
TreeNode_::Value(ref pv) => pv.id()
}
}
fn name(&self) -> Option<MuName> {
match self.v {
TreeNode_::Instruction(ref inst) => inst.name(),
TreeNode_::Value(ref pv) => pv.name()
}
}
fn set_name(&self, name: MuName) {
match self.v {
TreeNode_::Instruction(ref inst) => inst.set_name(name),
TreeNode_::Value(ref pv) => pv.set_name(name)
}
}
fn as_entity(&self) -> &MuEntity {
match self.v {
TreeNode_::Instruction(ref inst) => inst.as_entity(),
TreeNode_::Value(ref pv) => pv.as_entity()
}
}
}
pub fn op_vector_str(vec: &Vec<OpIndex>, ops: &Vec<P<TreeNode>>) -> String {
let mut ret = String::new();
for i in 0..vec.len() {
......
......@@ -52,7 +52,7 @@ pub type P<T> = Arc<T>;
#[allow(non_snake_case)]
/// Construct a `P<T>` from a `T` value.
pub fn P<T: MuEntity>(value: T) -> P<T> {
pub fn P<T>(value: T) -> P<T> {
// P {ptr: Arc::new(value)}
Arc::new(value)
}
......
......@@ -60,7 +60,7 @@ impl CompilerPass for TreeGen {
let expr = entry_value.take_expr();
trace!("{} replaced by {}", ops[index], expr);
ops[index] = TreeNode::new_inst(vm.next_id(), expr);
ops[index] = TreeNode::new_inst(expr);
}
} else {
trace!("{} cant be replaced", ops[index]);
......
......@@ -79,7 +79,8 @@ pub fn alloc_new() -> VM {
// %a = NEW <@int64_t>
let blk_0_a = func_ver.new_ssa(vm.next_id(), type_def_ref_int64.clone());
vm.set_name(blk_0_a.as_entity(), "blk_0_a".to_string());
let blk_0_inst0 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_0_inst0 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_a.clone_value()]),
ops: RwLock::new(vec![]),
v: Instruction_::New(type_def_int64.clone())
......@@ -88,15 +89,17 @@ pub fn alloc_new() -> VM {
// %a_iref = GETIREF <@int_64> @a
let blk_0_a_iref = func_ver.new_ssa(vm.next_id(), type_def_iref_int64.clone());
vm.set_name(blk_0_a.as_entity(), "blk_0_a_iref".to_string());
let blk_0_inst1 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_0_inst1 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_a_iref.clone_value()]),
ops: RwLock::new(vec![blk_0_a.clone()]),
v: Instruction_::GetIRef(0)
});
// STORE <@int_64> @a_iref @int_64_1
let blk_0_const_int64_1 = func_ver.new_constant(vm.next_id(), const_def_int64_1.clone());
let blk_0_inst2 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_0_const_int64_1 = func_ver.new_constant(const_def_int64_1.clone());
let blk_0_inst2 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_0_a_iref.clone(), blk_0_const_int64_1.clone()]),
v: Instruction_::Store{
......@@ -120,7 +123,8 @@ pub fn alloc_new() -> VM {
// }
// });
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction {
let blk_0_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit
......
......@@ -104,8 +104,9 @@ fn create_catch_exception_func (vm: &VM) {
let blk_normal_cont_id = vm.next_id();
let blk_exn_cont_id = vm.next_id();
let blk_0_throw = func_ver.new_constant(vm.next_id(), const_funcref_throw_exception.clone());
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction {
let blk_0_throw = func_ver.new_constant(const_funcref_throw_exception.clone());
let blk_0_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_0_throw]),
v: Instruction_::Call {
......@@ -138,7 +139,8 @@ fn create_catch_exception_func (vm: &VM) {
// %blk_normal_cont():
let mut blk_normal_cont = Block::new(blk_normal_cont_id);
vm.set_name(blk_normal_cont.as_entity(), Mu("blk_normal_cont"));
let blk_normal_cont_thread_exit = func_ver.new_inst(vm.next_id(), Instruction {
let blk_normal_cont_thread_exit = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit
......@@ -156,7 +158,8 @@ fn create_catch_exception_func (vm: &VM) {
let type_ref_int64 = vm.get_type(vm.id_of("ref_int64"));
let blk_exn_cont_exception_arg = func_ver.new_ssa(vm.next_id(), type_ref_int64.clone());
vm.set_name(blk_exn_cont_exception_arg.as_entity(), Mu("blk_0_exception_arg"));
let blk_exn_cont_thread_exit = func_ver.new_inst(vm.next_id(), Instruction {
let blk_exn_cont_thread_exit = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit
......@@ -206,25 +209,28 @@ fn create_throw_exception_func (vm: &VM) {
// %exception_obj = NEW <@int64>
let blk_0_exception_obj = func_ver.new_ssa(vm.next_id(), type_ref_int64.clone());
vm.set_name(blk_0_exception_obj.as_entity(), Mu("blk_0_exception_obj"));
let blk_0_inst0 = func_ver.new_inst(vm.next_id(), Instruction {
value: Some(vec![blk_0_exception_obj.clone_value()]),
ops: RwLock::new(vec![]),
v: Instruction_::New(type_ref_int64.clone())
let blk_0_inst0 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_exception_obj.clone_value()]),
ops: RwLock::new(vec![]),
v: Instruction_::New(type_ref_int64.clone())
});
// %exception_obj_iref = GETIREF <@int64> %exception_obj
let blk_0_exception_obj_iref = func_ver.new_ssa(vm.next_id(), type_iref_int64.clone());
vm.set_name(blk_0_exception_obj_iref.as_entity(), Mu("blk_0_exception_obj_iref"));
let blk_0_inst1 = func_ver.new_inst(vm.next_id(), Instruction {
value: Some(vec![blk_0_exception_obj_iref.clone_value()]),
ops: RwLock::new(vec![blk_0_exception_obj.clone()]),
v: Instruction_::GetIRef(0)
let blk_0_inst1 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_exception_obj_iref.clone_value()]),
ops: RwLock::new(vec![blk_0_exception_obj.clone()]),
v: Instruction_::GetIRef(0)
});
// STORE <@int64> %exception_obj_iref @int64_1
let const_int64_1 = vm.get_const(vm.id_of("int64_1"));
let blk_0_const_int64_1 = func_ver.new_constant(vm.next_id(), const_int64_1);
let blk_0_inst2 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_0_const_int64_1 = func_ver.new_constant(const_int64_1);
let blk_0_inst2 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_0_exception_obj_iref.clone(), blk_0_const_int64_1.clone()]),
v: Instruction_::Store {
......@@ -235,7 +241,8 @@ fn create_throw_exception_func (vm: &VM) {
}
});
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction {
let blk_0_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_0_exception_obj.clone()]),
v: Instruction_::Throw(0)
......
......@@ -123,7 +123,7 @@ fn create_spill1() -> VM {
vm.set_name(blk_entry.as_entity(), Mu("entry"));
// callee
let blk_entry_spill1_funcref = func_ver.new_constant(vm.next_id(), const_func_spill1.clone());
let blk_entry_spill1_funcref = func_ver.new_constant(const_func_spill1.clone());
// args
let blk_entry_t1 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_t1.as_entity(), Mu("blk_entry_t1"));
......@@ -148,7 +148,8 @@ fn create_spill1() -> VM {
// %x = CALL spill1(%t1, %t2, ... t10)
let blk_entry_x = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
let blk_entry_call = func_ver.new_inst(vm.next_id(), Instruction{
let blk_entry_call = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_x.clone_value()]),
ops: RwLock::new(vec![
blk_entry_spill1_funcref,
......@@ -176,7 +177,8 @@ fn create_spill1() -> VM {
// %res0 = ADD %t1 %t2
let blk_entry_res0 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res0.as_entity(), Mu("blk_entry_res0"));
let blk_entry_add0 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_entry_add0 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res0.clone_value()]),
ops: RwLock::new(vec![blk_entry_t1.clone(), blk_entry_t2.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1)
......@@ -185,7 +187,8 @@ fn create_spill1() -> VM {
// %res1 = ADD %res0 %t3
let blk_entry_res1 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res1.as_entity(), Mu("blk_entry_res1"));
let blk_entry_add1 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_entry_add1 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res1.clone_value()]),
ops: RwLock::new(vec![blk_entry_res0.clone(), blk_entry_t3.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1)
......@@ -194,7 +197,8 @@ fn create_spill1() -> VM {
// %res2 = ADD %res1 %t4
let blk_entry_res2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res2.as_entity(), Mu("blk_entry_res2"));
let blk_entry_add2 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_entry_add2 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res2.clone_value()]),
ops: RwLock::new(vec![blk_entry_res1.clone(), blk_entry_t4.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1)
......@@ -203,14 +207,16 @@ fn create_spill1() -> VM {
// %res3 = ADD %res2 %t5
let blk_entry_res3 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_res3.as_entity(), Mu("blk_entry_res3"));
let blk_entry_add3 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_entry_add3 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_entry_res3.clone_value()]),
ops: RwLock::new(vec![blk_entry_res2.clone(), blk_entry_t5.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1)
});
// RET %res3
let blk_entry_ret = func_ver.new_inst(vm.next_id(), Instruction{
let blk_entry_ret = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_entry_res3.clone()]),
v: Instruction_::Return(vec![0])
......
......@@ -55,7 +55,8 @@ fn primordial_main() -> VM {
let mut blk_entry = Block::new(vm.next_id());
vm.set_name(blk_entry.as_entity(), "entry".to_string());
let thread_exit = func_ver.new_inst(vm.next_id(), Instruction {
let thread_exit = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![]),
v: Instruction_::ThreadExit
......
......@@ -51,13 +51,14 @@ pub fn sum() -> VM {
let blk_entry_n = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_entry_n.as_entity(), "blk_entry_n".to_string());
let const_def_int64_0_local = func_ver.new_constant(vm.next_id(), const_def_int64_0.clone()); // FIXME: why we need a local version?
let const_def_int64_1_local = func_ver.new_constant(vm.next_id(), const_def_int64_1.clone());
let const_def_int64_0_local = func_ver.new_constant(const_def_int64_0.clone()); // FIXME: why we need a local version?
let const_def_int64_1_local = func_ver.new_constant(const_def_int64_1.clone());
// BRANCH %head
let mut blk_head = Block::new(vm.next_id());
vm.set_name(blk_head.as_entity(), "head".to_string());
let blk_entry_term = func_ver.new_inst(vm.next_id(), Instruction {
let blk_entry_term = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_entry_n.clone(), const_def_int64_0_local.clone(), const_def_int64_0_local.clone()]),
v: Instruction_::Branch1(Destination{
......@@ -86,7 +87,8 @@ pub fn sum() -> VM {
// %s2 = ADD %s %i
let blk_head_s2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_head_s2.as_entity(), "blk_head_s2".to_string());
let blk_head_inst0 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_head_inst0 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_head_s2.clone_value()]),
ops: RwLock::new(vec![blk_head_s.clone(), blk_head_i.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1)
......@@ -95,7 +97,8 @@ pub fn sum() -> VM {
// %i2 = ADD %i 1
let blk_head_i2 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_head_i2.as_entity(), "blk_head_i2".to_string());
let blk_head_inst1 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_head_inst1 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_head_i2.clone_value()]),
ops: RwLock::new(vec![blk_head_i.clone(), const_def_int64_1_local.clone()]),
v: Instruction_::BinOp(BinOp::Add, 0, 1)
......@@ -104,7 +107,8 @@ pub fn sum() -> VM {
// %cond = UGT %i %n
let blk_head_cond = func_ver.new_ssa(vm.next_id(), type_def_int1.clone());
vm.set_name(blk_head_cond.as_entity(), "blk_head_cond".to_string());
let blk_head_inst2 = func_ver.new_inst(vm.next_id(), Instruction {
let blk_head_inst2 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_head_cond.clone_value()]),
ops: RwLock::new(vec![blk_head_i.clone(), blk_head_n.clone()]),
v: Instruction_::CmpOp(CmpOp::UGT, 0, 1)
......@@ -113,7 +117,8 @@ pub fn sum() -> VM {
// BRANCH2 %cond %ret(%s2) %head(%n %s2 %i2)
let mut blk_ret = Block::new(vm.next_id());
vm.set_name(blk_ret.as_entity(), "ret".to_string());
let blk_head_term = func_ver.new_inst(vm.next_id(), Instruction{
let blk_head_term = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_head_cond.clone(), blk_head_n.clone(), blk_head_s2.clone(), blk_head_i2.clone()]),
v: Instruction_::Branch2 {
......@@ -143,7 +148,8 @@ pub fn sum() -> VM {
vm.set_name(blk_ret_s.as_entity(), "blk_ret_s".to_string());
// RET %s
let blk_ret_term = func_ver.new_inst(vm.next_id(), Instruction{
let blk_ret_term = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_ret_s.clone()]),
v: Instruction_::Return(vec![0])
......@@ -231,15 +237,16 @@ pub fn factorial() -> VM {
vm.set_name(blk_0.as_entity(), "blk_0".to_string());
let blk_0_n_3 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_0_n_3.as_entity(), "blk_0_n_3".to_string());
let const_def_int64_1_local = func_ver.new_constant(vm.next_id(), const_def_int64_1.clone());
let const_def_int64_1_local = func_ver.new_constant(const_def_int64_1.clone());
// %v48 = EQ <@int_64> %n_3 @int_64_1
let blk_0_v48 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_0_v48.as_entity(), "blk_0_v48".to_string());
let blk_0_inst0 = func_ver.new_inst(vm.next_id(), Instruction {
value: Some(vec![blk_0_v48.clone_value()]),
ops: RwLock::new(vec![blk_0_n_3.clone(), const_def_int64_1_local.clone()]),
v: Instruction_::CmpOp(CmpOp::EQ, 0, 1)
let blk_0_inst0 = func_ver.new_inst(Instruction {
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_v48.clone_value()]),
ops: RwLock::new(vec![blk_0_n_3.clone(), const_def_int64_1_local.clone()]),
v: Instruction_::CmpOp(CmpOp::EQ, 0, 1)
});
// BRANCH2 %v48 %blk_2(@int_64_1) %blk_1(%n_3)
......@@ -247,7 +254,8 @@ pub fn factorial() -> VM {
vm.set_name(blk_1.as_entity(), "blk_1".to_string());
let mut blk_2 = Block::new(vm.next_id());
vm.set_name(blk_2.as_entity(), "blk_2".to_string());
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction{
let blk_0_term = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_0_v48.clone(), const_def_int64_1_local.clone(), blk_0_n_3.clone()]),
v: Instruction_::Branch2 {
......@@ -277,7 +285,8 @@ pub fn factorial() -> VM {
vm.set_name(blk_2_v53.as_entity(), "blk_2_v53".to_string());
// RET %v53
let blk_2_term = func_ver.new_inst(vm.next_id(), Instruction{
let blk_2_term = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_2_v53.clone()]),
v: Instruction_::Return(vec![0])
......@@ -298,7 +307,8 @@ pub fn factorial() -> VM {
// %v50 = SUB <@int_64> %n_3 @int_64_1
let blk_1_v50 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_1_v50.as_entity(), "blk_1_v50".to_string());
let blk_1_inst0 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_1_inst0 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_1_v50.clone_value()]),
ops: RwLock::new(vec![blk_1_n_3.clone(), const_def_int64_1_local.clone()]),
v: Instruction_::BinOp(BinOp::Sub, 0, 1)
......@@ -307,8 +317,9 @@ pub fn factorial() -> VM {
// %v51 = CALL <@fac_sig> @fac (%v50)
let blk_1_v51 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_1_v51.as_entity(), "blk_1_v51".to_string());
let blk_1_fac = func_ver.new_constant(vm.next_id(), const_func_fac.clone());
let blk_1_inst1 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_1_fac = func_ver.new_constant(const_func_fac.clone());
let blk_1_inst1 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_1_v51.clone_value()]),
ops: RwLock::new(vec![blk_1_fac, blk_1_v50.clone()]),
v: Instruction_::ExprCall {
......@@ -324,14 +335,16 @@ pub fn factorial() -> VM {
// %v52 = MUL <@int_64> %n_3 %v51
let blk_1_v52 = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_1_v52.as_entity(), "blk_1_v52".to_string());
let blk_1_inst2 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_1_inst2 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_1_v52.clone_value()]),
ops: RwLock::new(vec![blk_1_n_3.clone(), blk_1_v51.clone()]),
v: Instruction_::BinOp(BinOp::Mul, 0, 1)
});
// BRANCH blk_2 (%blk_1_v52)
let blk_1_term = func_ver.new_inst(vm.next_id(), Instruction{
let blk_1_term = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_1_v52.clone()]),
v: Instruction_::Branch1(Destination {
......@@ -411,9 +424,10 @@ pub fn global_access() -> VM {
vm.set_name(blk_0.as_entity(), "blk_0".to_string());
// STORE <@int_64> @a @int_64_1
let blk_0_a = func_ver.new_global(vm.next_id(), global_a.clone());
let blk_0_const_int64_1 = func_ver.new_constant(vm.next_id(), const_def_int64_1.clone());
let blk_0_inst0 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_0_a = func_ver.new_global(global_a.clone());
let blk_0_const_int64_1 = func_ver.new_constant(const_def_int64_1.clone());
let blk_0_inst0 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_0_a.clone(), blk_0_const_int64_1.clone()]),
v: Instruction_::Store{
......@@ -427,7 +441,8 @@ pub fn global_access() -> VM {
// %x = LOAD <@int_64> @a
let blk_0_x = func_ver.new_ssa(vm.next_id(), type_def_int64.clone());
vm.set_name(blk_0_x.as_entity(), "blk_0_x".to_string());
let blk_0_inst1 = func_ver.new_inst(vm.next_id(), Instruction{
let blk_0_inst1 = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: Some(vec![blk_0_x.clone_value()]),
ops: RwLock::new(vec![blk_0_a.clone()]),
v: Instruction_::Load{
......@@ -437,7 +452,8 @@ pub fn global_access() -> VM {
}
});
let blk_0_term = func_ver.new_inst(vm.next_id(), Instruction{
let blk_0_term = func_ver.new_inst(Instruction{
hdr: MuEntityHeader::unnamed(vm.next_id()),
value: None,
ops: RwLock::new(vec![blk_0_x.clone()]),
v: Instruction_::Return(vec![0])
......
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