test_global.rs 1.2 KB
Newer Older
qinsoon's avatar
qinsoon committed
1 2 3 4 5 6
extern crate mu;
extern crate log;
extern crate simple_logger;

use test_ir::test_ir::global_access;
use self::mu::compiler::*;
7
use self::mu::ast::ir::*;
qinsoon's avatar
qinsoon committed
8 9 10 11 12 13 14

use std::sync::Arc;

#[test]
fn test_global_access() {
    simple_logger::init_with_level(log::LogLevel::Trace).ok();
    
qinsoon's avatar
qinsoon committed
15
    let vm = Arc::new(global_access());
qinsoon's avatar
qinsoon committed
16 17 18 19 20 21 22 23 24 25
    
    let compiler = Compiler::new(CompilerPolicy::new(vec![
        Box::new(passes::DefUse::new()),
        Box::new(passes::TreeGen::new()),
        Box::new(passes::ControlFlowAnalysis::new()),
        Box::new(passes::TraceGen::new()),
        Box::new(backend::inst_sel::InstructionSelection::new()),
        Box::new(backend::reg_alloc::RegisterAllocation::new()),
        Box::new(backend::peephole_opt::PeepholeOptimization::new()),
        Box::new(backend::code_emission::CodeEmission::new())
qinsoon's avatar
qinsoon committed
26
    ]), vm.clone());
qinsoon's avatar
qinsoon committed
27
    
28
    let func_id = vm.id_of("global_access");
qinsoon's avatar
qinsoon committed
29
    let funcs = vm.funcs().read().unwrap();
30
    let func = funcs.get(&func_id).unwrap().read().unwrap();
qinsoon's avatar
qinsoon committed
31
    let func_vers = vm.func_vers().read().unwrap();
32
    let mut func_ver = func_vers.get(&(func.id(), func.cur_ver.unwrap())).unwrap().write().unwrap();
qinsoon's avatar
qinsoon committed
33
    
34
    compiler.compile(&mut func_ver);
qinsoon's avatar
qinsoon committed
35
    backend::emit_context(&vm);
qinsoon's avatar
qinsoon committed
36
}