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

mod.rs 1.84 KB
Newer Older
1
use ast::ir::*;
qinsoon's avatar
qinsoon committed
2
use ast::ptr::*;
qinsoon's avatar
qinsoon committed
3
4
use vm::context::VMContext;

5
6
7
8
9
10
11
12
13
14
15
16
17
use std::cell::RefCell;

pub mod passes;

pub struct Compiler {
    policy: RefCell<CompilerPolicy>
}

impl Compiler {
    pub fn new(policy: CompilerPolicy) -> Compiler {
        Compiler{policy: RefCell::new(policy)}
    }
    
qinsoon's avatar
qinsoon committed
18
    pub fn compile(&self, vm: &VMContext, func: &mut MuFunction) {
19
        for pass in self.policy.borrow_mut().passes.iter_mut() {
qinsoon's avatar
qinsoon committed
20
            pass.execute(vm, func);
21
22
23
24
25
26
27
28
29
30
31
        }
    }
}

pub struct CompilerPolicy {
    passes: Vec<Box<CompilerPass>>
}

impl CompilerPolicy {
    pub fn default() -> CompilerPolicy {
        let mut passes : Vec<Box<CompilerPass>> = vec![];
32
        passes.push(Box::new(passes::def_use::DefUsePass::new("DefUse")));
qinsoon's avatar
qinsoon committed
33
        passes.push(Box::new(passes::tree_gen::TreeGenerationPass::new("Tree Generation")));
34
35
36
37
38
39
        
        CompilerPolicy{passes: passes}
    }
}

pub trait CompilerPass {
qinsoon's avatar
qinsoon committed
40
41
42
43
44
45
46
47
48
49
50
51
52
    fn name(&self) -> &'static str;
    
    fn execute(&mut self, vm_context: &VMContext, func: &mut MuFunction) {
        debug!("---CompilerPass {} for {}---", self.name(), func.fn_name);
        
        self.visit_function(vm_context, func);
        
        for entry in func.blocks.iter_mut() {
            let label : MuTag = entry.0;
            let ref mut block : &mut Block = &mut entry.1;
            
            debug!("block: {}", label);
            
53
54
55
56
            for inst in block.content.as_mut().unwrap().body.iter_mut() {
                debug!("{:?}", inst);
                
                self.visit_inst(vm_context, inst);
qinsoon's avatar
qinsoon committed
57
58
59
60
61
62
63
64
            }
            
            debug!("---finish---");
        }
    }
    
    fn visit_function(&mut self, vm_context: &VMContext, func: &mut MuFunction) {}
    fn visit_block(&mut self, vm_context: &VMContext, block: &mut Block) {}
65
    fn visit_inst(&mut self, vm_context: &VMContext, node: &mut TreeNode) {}
66
}