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

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

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
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;
20
21
pub use compiler::passes::PASS6_PEEPHOLE;
pub use compiler::passes::PASS7_CODE_EMIT;
qinsoon's avatar
qinsoon committed
22

23
pub struct Compiler {
24
    policy: RefCell<CompilerPolicy>,
qinsoon's avatar
qinsoon committed
25
    vm: Arc<VM>
26
27
28
}

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

36
    pub fn compile(&self, func: &mut MuFunctionVersion) {
qinsoon's avatar
qinsoon committed
37
38
        // FIXME: should use function name here (however hprof::enter only accept &'static str)
        let _p = hprof::enter("Function Compilation");
qinsoon's avatar
qinsoon committed
39

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

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

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

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

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

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

pub struct CompilerPolicy {
63
    pub passes: Vec<Box<CompilerPass>>
64
65
66
67
68
}

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

78
79
        CompilerPolicy{passes: passes}
    }
qinsoon's avatar
qinsoon committed
80

qinsoon's avatar
qinsoon committed
81
82
83
    pub fn new(passes: Vec<Box<CompilerPass>>) -> CompilerPolicy {
        CompilerPolicy{passes: passes}
    }
qinsoon's avatar
qinsoon committed
84
}