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 2.16 KB
Newer Older
qinsoon's avatar
qinsoon committed
1
2
extern crate hprof;

3
use ast::ir::*;
qinsoon's avatar
qinsoon committed
4
5
use vm::context::VMContext;

6
use std::cell::RefCell;
7
use std::sync::Arc;
8
9

pub mod passes;
10
pub mod backend;
11

qinsoon's avatar
qinsoon committed
12
13
14
15
16
17
18
19
20
21
pub use compiler::passes::CompilerPass;
pub use compiler::passes::PassExecutionResult;
pub use compiler::passes::PASS0_DEF_USE;
pub use compiler::passes::PASS1_TREE_GEN;
pub use compiler::passes::PASS2_CFA;
pub use compiler::passes::PASS3_TRACE_GEN;
pub use compiler::passes::PASS4_INST_SEL;
pub use compiler::passes::PASS5_REG_ALLOC;
pub use compiler::passes::PASS6_CODE_EMIT;

22
pub struct Compiler {
23
24
    policy: RefCell<CompilerPolicy>,
    vm: Arc<VMContext>
25
26
27
}

impl Compiler {
28
29
30
31
32
    pub fn new(policy: CompilerPolicy, vm: Arc<VMContext>) -> Compiler {
        Compiler{
            policy: RefCell::new(policy),
            vm: vm
        }
33
    }
qinsoon's avatar
qinsoon committed
34

35
    pub fn compile(&self, func: &mut MuFunction) {
qinsoon's avatar
qinsoon committed
36
37
        let _p = hprof::enter(func.fn_name);

38
39
        let mut cur_pass = 0;
        let n_passes = self.policy.borrow().passes.len();
qinsoon's avatar
qinsoon committed
40

41
        let ref mut passes = self.policy.borrow_mut().passes;
qinsoon's avatar
qinsoon committed
42

43
        while cur_pass < n_passes {
qinsoon's avatar
qinsoon committed
44
            let _p = hprof::enter(passes[cur_pass].name());
45
            let result = passes[cur_pass].execute(&self.vm, func);
qinsoon's avatar
qinsoon committed
46

47
48
49
50
            match result {
                PassExecutionResult::ProceedToNext => cur_pass += 1,
                PassExecutionResult::GoBackTo(next) => cur_pass = next
            }
qinsoon's avatar
qinsoon committed
51
52

            drop(_p);
53
        }
qinsoon's avatar
qinsoon committed
54
55
56

		drop(_p);
		hprof::profiler().print_timing();
57
58
59
60
61
62
63
64
65
66
    }
}

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

impl CompilerPolicy {
    pub fn default() -> CompilerPolicy {
        let mut passes : Vec<Box<CompilerPass>> = vec![];
qinsoon's avatar
qinsoon committed
67
68
        passes.push(Box::new(passes::DefUse::new()));
        passes.push(Box::new(passes::TreeGen::new()));
69
        passes.push(Box::new(passes::ControlFlowAnalysis::new()));
70
        passes.push(Box::new(passes::TraceGen::new()));
71
        passes.push(Box::new(backend::inst_sel::InstructionSelection::new()));
72
        passes.push(Box::new(backend::reg_alloc::RegisterAllocation::new()));
qinsoon's avatar
qinsoon committed
73

74
75
        CompilerPolicy{passes: passes}
    }
qinsoon's avatar
qinsoon committed
76

qinsoon's avatar
qinsoon committed
77
78
79
    pub fn new(passes: Vec<Box<CompilerPass>>) -> CompilerPolicy {
        CompilerPolicy{passes: passes}
    }
80
}