Commit 212638e9 authored by qinsoon's avatar qinsoon

refactored ast

parent e31a5a4b
This diff is collapsed.
pub mod types;
pub mod ir;
pub mod ptr;
\ No newline at end of file
pub mod ptr;
pub mod op;
\ No newline at end of file
#[derive(Copy, Clone, Debug)]
pub enum BinOp {
// Int(n) BinOp Int(n) -> Int(n)
Add,
Sub,
Mul,
Sdiv,
Srem,
Udiv,
And,
Or,
Xor,
// Int(n) BinOp Int(m) -> Int(n)
Shl,
Lshr,
AsHR,
// FP BinOp FP -> FP
Fadd,
FSub,
FMul,
FDiv,
FRem
}
#[derive(Copy, Clone, Debug)]
pub enum CmpOp {
// for Int comparison
EQ,
NE,
SGE,
SGT,
SLE,
SLT,
UGE,
UGT,
ULE,
ULT,
// for FP comparison
FFALSE,
FTRUE,
FOEQ,
FOGT,
FOGE,
FOLT,
FOLE,
FONE,
FORD,
FUEQ,
FUGT,
FUGE,
FULT,
FULE,
FUNE,
FUNO
}
#[derive(Copy, Clone, Debug)]
pub enum AtomicRMWOp {
XCHG,
ADD,
SUB,
AND,
NAND,
OR,
XOR,
MAX,
MIN,
UMAX,
UMIN
}
\ No newline at end of file
extern crate std;
use ast::ptr::*;
use ast::ptr::P;
use ast::ir::*;
use std::collections::HashMap;
use std::sync::RwLock;
......
......@@ -3,6 +3,7 @@ extern crate mu;
use self::mu::ast::types::*;
use self::mu::ast::ir::*;
use self::mu::ast::ptr::*;
use self::mu::ast::op::*;
use self::mu::vm::context::*;
#[test]
......@@ -41,29 +42,30 @@ pub fn factorial() -> VMContext {
// %blk_0(<@int_64> %n_3):
let mut blk_0 = Block::new("blk_0");
let blk_0_n_3 = P(Value::SSAVar(SSAVar{id: 0, tag: "n_3", ty: type_def_int64.clone()}));
let blk_0_n_3 = TreeNode::new_value(Value::new_ssa(SSAVar{id: 0, tag: "n_3", ty: type_def_int64.clone()}));
let const_def_int64_1_local = TreeNode::new_value(const_def_int64_1.clone());
// %v48 = EQ <@int_64> %n_3 @int_64_1
let blk_0_v48 = P(Value::SSAVar(SSAVar{id: 1, tag: "v48", ty: type_def_int64.clone()}));
let blk_0_v48_expr = Expression::CmpOp(
let blk_0_v48 = TreeNode::new_value(Value::new_ssa(SSAVar{id: 1, tag: "v48", ty: type_def_int64.clone()}));
let blk_0_v48_expr = Expression_::CmpOp(
CmpOp::EQ,
blk_0_n_3.clone(),
const_def_int64_1.clone()
const_def_int64_1_local.clone()
);
let blk_0_inst0 = Instruction::NonTerm(NonTermInstruction::Assign{left: vec![blk_0_v48.clone()], right: blk_0_v48_expr});
let blk_0_inst0 = TreeNode::new_inst(Instruction::NonTerm(NonTermInstruction::Assign{left: vec![blk_0_v48.clone()], right: blk_0_v48_expr}));
// BRANCH2 %v48 %blk_2(@int_64_1) %blk_1(%n_3)
let blk_0_term = Instruction::Term(Terminal::Branch2{
let blk_0_term = TreeNode::new_inst(Instruction::Term(Terminal::Branch2{
cond: blk_0_v48.clone(),
true_dest: Destination {
target: "blk_2",
args: vec![DestArg::Normal(const_def_int64_1.clone())]
args: vec![DestArg::Normal(const_def_int64_1_local.clone())]
},
false_dest: Destination {
target: "blk_1",
args: vec![DestArg::Normal(blk_0_n_3.clone())]
}
});
}));
let blk_0_content = BlockContent {
args: vec![blk_0_n_3.clone()],
......@@ -74,10 +76,10 @@ pub fn factorial() -> VMContext {
// %blk_2(<@int_64> %v53):
let mut blk_2 = Block::new("blk_2");
let blk_2_v53 = P(Value::SSAVar(SSAVar{id: 2, tag: "v53", ty: type_def_int64.clone()}));
let blk_2_v53 = TreeNode::new_value(Value::new_ssa(SSAVar{id: 2, tag: "v53", ty: type_def_int64.clone()}));
// RET %v53
let blk_2_term = Instruction::Term(Terminal::Return(vec![blk_2_v53.clone()]));
let blk_2_term = TreeNode::new_inst(Instruction::Term(Terminal::Return(vec![blk_2_v53.clone()])));
let blk_2_content = BlockContent {
args: vec![blk_2_v53.clone()],
......@@ -88,49 +90,49 @@ pub fn factorial() -> VMContext {
// %blk_1(<@int_64> %n_3):
let mut blk_1 = Block::new("blk_1");
let blk_1_n_3 = P(Value::SSAVar(SSAVar{id: 3, tag: "n_3", ty: type_def_int64.clone()}));
let blk_1_n_3 = TreeNode::new_value(Value::new_ssa(SSAVar{id: 3, tag: "n_3", ty: type_def_int64.clone()}));
// %v50 = SUB <@int_64> %n_3 @int_64_1
let blk_1_v50 = P(Value::SSAVar(SSAVar{id: 4, tag: "v50", ty: type_def_int64.clone()}));
let blk_1_v50_expr = Expression::BinOp(
let blk_1_v50 = TreeNode::new_value(Value::new_ssa(SSAVar{id: 4, tag: "v50", ty: type_def_int64.clone()}));
let blk_1_v50_expr = Expression_::BinOp(
BinOp::Sub,
blk_1_n_3.clone(),
const_def_int64_1.clone()
const_def_int64_1_local.clone()
);
let blk_1_inst0 = Instruction::NonTerm(NonTermInstruction::Assign{left: vec![blk_1_v50.clone()], right: blk_1_v50_expr});
let blk_1_inst0 = TreeNode::new_inst(Instruction::NonTerm(NonTermInstruction::Assign{left: vec![blk_1_v50.clone()], right: blk_1_v50_expr}));
// %v51 = CALL <@fac_sig> @fac (%v50)
let blk_1_v51 = P(Value::SSAVar(SSAVar{id: 5, tag: "v51", ty: type_def_int64.clone()}));
let blk_1_inst1 = Instruction::NonTerm(NonTermInstruction::Assign{
let blk_1_v51 = TreeNode::new_value(Value::new_ssa(SSAVar{id: 5, tag: "v51", ty: type_def_int64.clone()}));
let blk_1_inst1 = TreeNode::new_inst(Instruction::NonTerm(NonTermInstruction::Assign{
left: vec![blk_1_v51.clone()],
right: Expression::ExprCall {
right: Expression_::ExprCall {
data: CallData {
func: P(SSAVar{id: 6, tag: "fac", ty: fac_func_ref.clone()}),
func: TreeNode::new_value(Value::new_ssa(SSAVar{id: 6, tag: "fac", ty: fac_func_ref.clone()})),
args: vec![blk_1_v50.clone()],
convention: CallConvention::Mu
},
is_abort: true
}
});
}));
// %v52 = MUL <@int_64> %n_3 %v51
let blk_1_v52 = P(Value::SSAVar(SSAVar{id: 9, tag: "v52", ty: type_def_int64.clone()}));
let blk_1_v52_expr = Expression::BinOp(
let blk_1_v52 = TreeNode::new_value(Value::new_ssa(SSAVar{id: 9, tag: "v52", ty: type_def_int64.clone()}));
let blk_1_v52_expr = Expression_::BinOp(
BinOp::Mul,
blk_1_n_3.clone(),
blk_1_v51.clone()
);
let blk_1_inst2 = Instruction::NonTerm(NonTermInstruction::Assign{
let blk_1_inst2 = TreeNode::new_inst(Instruction::NonTerm(NonTermInstruction::Assign{
left: vec![blk_1_v52.clone()],
right: blk_1_v52_expr
});
}));
let blk_1_term = Instruction::Term(Terminal::Branch1 (
let blk_1_term = TreeNode::new_inst(Instruction::Term(Terminal::Branch1 (
Destination {
target: "blk_2",
args: vec![DestArg::Normal(blk_1_v52.clone())]
}
));
)));
let blk_1_content = BlockContent {
args: vec![blk_1_n_3.clone()],
......
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