To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit e31a5a4b authored by qinsoon's avatar qinsoon
Browse files

gonna revise the design of inst/treenode/op

parent be476b0d
...@@ -22,6 +22,18 @@ pub enum Value { ...@@ -22,6 +22,18 @@ pub enum Value {
Constant(MuConstant) Constant(MuConstant)
} }
#[derive(Debug)]
pub struct TreeNode {
v: TreeNodeKind,
children: Vec<P<TreeNode>>,
}
#[derive(Debug)]
pub enum TreeNodeKind {
Value(Vec<P<Value>>),
Expression(P<Expression>),
}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum MemoryOrder { pub enum MemoryOrder {
NotAtomic, NotAtomic,
...@@ -53,25 +65,20 @@ pub struct CallData { ...@@ -53,25 +65,20 @@ pub struct CallData {
#[derive(Debug)] #[derive(Debug)]
pub struct Block { pub struct Block {
label: MuTag, pub label: MuTag,
content: Option<BlockContent> pub content: Option<BlockContent>
} }
impl Block { impl Block {
pub fn new(label: MuTag) -> Block { pub fn new(label: MuTag) -> Block {
Block{label: label, content: None} Block{label: label, content: None}
} }
pub fn set_content(&mut self, v: BlockContent) {
self.content = Some(v);
}
} }
#[derive(Debug)] #[derive(Debug)]
pub struct BlockContent { pub struct BlockContent {
pub args: Vec<P<Value>>, pub args: Vec<P<Value>>,
pub body: Vec<Instruction>, pub body: Vec<Instruction>,
pub exit: Terminal,
pub keepalives: Option<Vec<P<SSAVar>>> pub keepalives: Option<Vec<P<SSAVar>>>
} }
...@@ -220,6 +227,12 @@ pub enum Expression { ...@@ -220,6 +227,12 @@ pub enum Expression {
#[derive(Debug)] #[derive(Debug)]
pub enum Instruction { pub enum Instruction {
NonTerm(NonTermInstruction),
Term(Terminal)
}
#[derive(Debug)]
pub enum NonTermInstruction {
Assign{ Assign{
left: Vec<P<Value>>, left: Vec<P<Value>>,
right: Expression right: Expression
...@@ -270,7 +283,7 @@ pub enum Terminal { ...@@ -270,7 +283,7 @@ pub enum Terminal {
branches: Vec<(P<Constant>, Destination)> branches: Vec<(P<Constant>, Destination)>
}, },
ExnInstruction{ ExnInstruction{
inner: Instruction, inner: NonTermInstruction,
resume: ResumptionData resume: ResumptionData
} }
} }
......
...@@ -17,9 +17,13 @@ impl CompilerPass for TreeGenerationPass { ...@@ -17,9 +17,13 @@ impl CompilerPass for TreeGenerationPass {
for entry in func.blocks.iter_mut() { for entry in func.blocks.iter_mut() {
let label : MuTag = entry.0; let label : MuTag = entry.0;
let ref block : &mut Block = &mut entry.1; let ref mut block : &mut Block = &mut entry.1;
debug!(" block: {:?}", label); debug!(" block: {:?}", label);
for inst in block.content.take().unwrap().body {
}
} }
} }
} }
\ No newline at end of file
...@@ -50,10 +50,10 @@ pub fn factorial() -> VMContext { ...@@ -50,10 +50,10 @@ pub fn factorial() -> VMContext {
blk_0_n_3.clone(), blk_0_n_3.clone(),
const_def_int64_1.clone() const_def_int64_1.clone()
); );
let blk_0_inst0 = Instruction::Assign{left: vec![blk_0_v48.clone()], right: blk_0_v48_expr}; let blk_0_inst0 = 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) // BRANCH2 %v48 %blk_2(@int_64_1) %blk_1(%n_3)
let blk_0_term = Terminal::Branch2{ let blk_0_term = Instruction::Term(Terminal::Branch2{
cond: blk_0_v48.clone(), cond: blk_0_v48.clone(),
true_dest: Destination { true_dest: Destination {
target: "blk_2", target: "blk_2",
...@@ -63,30 +63,28 @@ pub fn factorial() -> VMContext { ...@@ -63,30 +63,28 @@ pub fn factorial() -> VMContext {
target: "blk_1", target: "blk_1",
args: vec![DestArg::Normal(blk_0_n_3.clone())] args: vec![DestArg::Normal(blk_0_n_3.clone())]
} }
}; });
let blk_0_content = BlockContent { let blk_0_content = BlockContent {
args: vec![blk_0_n_3.clone()], args: vec![blk_0_n_3.clone()],
body: vec![blk_0_inst0], body: vec![blk_0_inst0, blk_0_term],
exit: blk_0_term,
keepalives: None keepalives: None
}; };
blk_0.set_content(blk_0_content); blk_0.content = Some(blk_0_content);
// %blk_2(<@int_64> %v53): // %blk_2(<@int_64> %v53):
let mut blk_2 = Block::new("blk_2"); 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 = P(Value::SSAVar(SSAVar{id: 2, tag: "v53", ty: type_def_int64.clone()}));
// RET %v53 // RET %v53
let blk_2_term = Terminal::Return(vec![blk_2_v53.clone()]); let blk_2_term = Instruction::Term(Terminal::Return(vec![blk_2_v53.clone()]));
let blk_2_content = BlockContent { let blk_2_content = BlockContent {
args: vec![blk_2_v53.clone()], args: vec![blk_2_v53.clone()],
body: vec![], body: vec![blk_2_term],
exit: blk_2_term,
keepalives: None keepalives: None
}; };
blk_2.set_content(blk_2_content); blk_2.content = Some(blk_2_content);
// %blk_1(<@int_64> %n_3): // %blk_1(<@int_64> %n_3):
let mut blk_1 = Block::new("blk_1"); let mut blk_1 = Block::new("blk_1");
...@@ -99,70 +97,52 @@ pub fn factorial() -> VMContext { ...@@ -99,70 +97,52 @@ pub fn factorial() -> VMContext {
blk_1_n_3.clone(), blk_1_n_3.clone(),
const_def_int64_1.clone() const_def_int64_1.clone()
); );
let blk_1_inst0 = Instruction::Assign{left: vec![blk_1_v50.clone()], right: blk_1_v50_expr}; let blk_1_inst0 = Instruction::NonTerm(NonTermInstruction::Assign{left: vec![blk_1_v50.clone()], right: blk_1_v50_expr});
// %v51 = CALL <@fac_sig> @fac (%v50) // %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_v51 = P(Value::SSAVar(SSAVar{id: 5, tag: "v51", ty: type_def_int64.clone()}));
let blk_1_term = Terminal::Call { let blk_1_inst1 = Instruction::NonTerm(NonTermInstruction::Assign{
data: CallData { left: vec![blk_1_v51.clone()],
func: P(SSAVar{id: 6, tag: "fac", ty: fac_func_ref.clone()}), right: Expression::ExprCall {
args: vec![blk_1_v50.clone()], data: CallData {
convention: CallConvention::Mu func: P(SSAVar{id: 6, tag: "fac", ty: fac_func_ref.clone()}),
}, args: vec![blk_1_v50.clone()],
resume: ResumptionData { convention: CallConvention::Mu
normal_dest: Destination { },
target: "blk_1_cont", is_abort: true
args: vec![DestArg::Normal(blk_1_n_3.clone()), DestArg::Freshbound(0)] }
}, });
exn_dest: Destination {
target: "blk_1_cont",
args: vec![DestArg::Normal(blk_1_n_3.clone()), DestArg::Freshbound(0)]
}
}
};
let blk_1_content = BlockContent {
args: vec![blk_1_n_3.clone()],
body: vec![blk_1_inst0],
exit: blk_1_term,
keepalives: None
};
blk_1.set_content(blk_1_content);
// %blk_1_cont(<@int_64> %n_3, <@int_64> %v51):
let mut blk_1_cont = Block::new("blk_1_cont");
let blk_1_cont_n_3 = P(Value::SSAVar(SSAVar{id: 7, tag: "n_3", ty: type_def_int64.clone()}));
let blk_1_cont_v51 = P(Value::SSAVar(SSAVar{id: 8, tag: "v51", ty: type_def_int64.clone()}));
// %v52 = MUL <@int_64> %n_3 %v51 // %v52 = MUL <@int_64> %n_3 %v51
let blk_1_cont_v52 = P(Value::SSAVar(SSAVar{id: 9, tag: "v52", ty: type_def_int64.clone()})); let blk_1_v52 = P(Value::SSAVar(SSAVar{id: 9, tag: "v52", ty: type_def_int64.clone()}));
let blk_1_cont_v52_expr = Expression::BinOp( let blk_1_v52_expr = Expression::BinOp(
BinOp::Mul, BinOp::Mul,
blk_1_cont_n_3.clone(), blk_1_n_3.clone(),
blk_1_cont_v52.clone() blk_1_v51.clone()
); );
let blk_1_cont_inst0 = Instruction::Assign{left: vec![blk_1_cont_v52.clone()], right: blk_1_cont_v52_expr}; let blk_1_inst2 = Instruction::NonTerm(NonTermInstruction::Assign{
left: vec![blk_1_v52.clone()],
right: blk_1_v52_expr
});
let blk_1_cont_term = Terminal::Branch1 ( let blk_1_term = Instruction::Term(Terminal::Branch1 (
Destination { Destination {
target: "blk_2", target: "blk_2",
args: vec![DestArg::Normal(blk_1_cont_v52.clone())] args: vec![DestArg::Normal(blk_1_v52.clone())]
} }
); ));
let blk_1_cont_content = BlockContent { let blk_1_content = BlockContent {
args: vec![blk_1_cont_n_3.clone(), blk_1_cont_v52.clone()], args: vec![blk_1_n_3.clone()],
body: vec![blk_1_cont_inst0], body: vec![blk_1_inst0, blk_1_inst1, blk_1_inst2, blk_1_term],
exit: blk_1_cont_term,
keepalives: None keepalives: None
}; };
blk_1_cont.set_content(blk_1_cont_content); blk_1.content = Some(blk_1_content);
// wrap into a function // wrap into a function
vm.declare_func("fac", fac_sig.clone(), "blk_0", vec![ vm.declare_func("fac", fac_sig.clone(), "blk_0", vec![
("blk_0", blk_0), ("blk_0", blk_0),
("blk_1", blk_1), ("blk_1", blk_1),
("blk_1_cont", blk_1_cont),
("blk_2", blk_2) ("blk_2", blk_2)
] ]
); );
......
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