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.11 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;
qinsoon's avatar
qinsoon committed
11
12
pub mod frame;
pub mod machine_code;
13

qinsoon's avatar
qinsoon committed
14
15
pub use compiler::passes::CompilerPass;

16
pub struct Compiler {
17
    policy: RefCell<CompilerPolicy>,
qinsoon's avatar
qinsoon committed
18
    vm: Arc<VM>
19
20
21
}

impl Compiler {
qinsoon's avatar
qinsoon committed
22
    pub fn new(policy: CompilerPolicy, vm: Arc<VM>) -> Compiler {
23
24
25
26
        Compiler{
            policy: RefCell::new(policy),
            vm: vm
        }
27
    }
qinsoon's avatar
qinsoon committed
28

29
    pub fn compile(&self, func: &mut MuFunctionVersion) {
30
31
        trace!("{:?}", func);
        
qinsoon's avatar
qinsoon committed
32
33
        // FIXME: should use function name here (however hprof::enter only accept &'static str)
        let _p = hprof::enter("Function Compilation");
qinsoon's avatar
qinsoon committed
34

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

37
38
        for pass in passes.iter_mut() {
            let _p = hprof::enter(pass.name());
qinsoon's avatar
qinsoon committed
39

40
            pass.execute(&self.vm, func);
qinsoon's avatar
qinsoon committed
41
42

            drop(_p);
43
        }
qinsoon's avatar
qinsoon committed
44

45
46
        drop(_p);
        hprof::profiler().print_timing();
47
    }
qinsoon's avatar
qinsoon committed
48
49
50
51

    pub fn get_policy(&self) -> &RefCell<CompilerPolicy> {
        &self.policy
    }
52
53
54
}

pub struct CompilerPolicy {
55
    pub passes: Vec<Box<CompilerPass>>
56
57
58
}

impl CompilerPolicy {
59
60
61
62
63
64
65
    pub fn new(passes: Vec<Box<CompilerPass>>) -> CompilerPolicy {
        CompilerPolicy{passes: passes}
    }
}

impl Default for CompilerPolicy {
    fn default() -> Self {
66
        let mut passes : Vec<Box<CompilerPass>> = vec![];
67
        // ir level passes
qinsoon's avatar
qinsoon committed
68
69
        passes.push(Box::new(passes::DefUse::new()));
        passes.push(Box::new(passes::TreeGen::new()));
70
        passes.push(Box::new(passes::GenMovPhi::new()));
71
        passes.push(Box::new(passes::ControlFlowAnalysis::new()));
72
        passes.push(Box::new(passes::TraceGen::new()));
73

74
75
76
        // compilation
        passes.push(Box::new(backend::inst_sel::InstructionSelection::new()));
        passes.push(Box::new(backend::reg_alloc::RegisterAllocation::new()));
77
78

        // machine code level passes
79
80
        passes.push(Box::new(backend::peephole_opt::PeepholeOptimization::new()));
        passes.push(Box::new(backend::code_emission::CodeEmission::new()));
qinsoon's avatar
qinsoon committed
81

82
83
        CompilerPolicy{passes: passes}
    }
84
}