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.53 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
pub use compiler::passes::CompilerPass;
pub use compiler::passes::PassExecutionResult;
14
15
16
17
18
19
20
21
22
pub use compiler::passes::PASS_IR_CHECK;
pub use compiler::passes::PASS_DEF_USE;
pub use compiler::passes::PASS_TREE_GEN;
pub use compiler::passes::PASS_CFA;
pub use compiler::passes::PASS_TRACE_GEN;
pub use compiler::passes::PASS_INST_SEL;
pub use compiler::passes::PASS_REG_ALLOC;
pub use compiler::passes::PASS_PEEPHOLE;
pub use compiler::passes::PASS_CODE_EMIT;
qinsoon's avatar
qinsoon committed
23

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

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

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

43
44
        let mut cur_pass = 0;
        let n_passes = self.policy.borrow().passes.len();
qinsoon's avatar
qinsoon committed
45

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

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

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

            drop(_p);
58
        }
qinsoon's avatar
qinsoon committed
59

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

pub struct CompilerPolicy {
66
    pub passes: Vec<Box<CompilerPass>>
67
68
69
70
71
}

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

81
82
        CompilerPolicy{passes: passes}
    }
qinsoon's avatar
qinsoon committed
83

qinsoon's avatar
qinsoon committed
84
85
86
    pub fn new(passes: Vec<Box<CompilerPass>>) -> CompilerPolicy {
        CompilerPolicy{passes: passes}
    }
qinsoon's avatar
qinsoon committed
87
}