test_instsel.rs 1.52 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1
// Copyright 2017 The Australian National University
qinsoon's avatar
qinsoon committed
2
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
3 4 5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
qinsoon's avatar
qinsoon committed
6
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
7
//     http://www.apache.org/licenses/LICENSE-2.0
qinsoon's avatar
qinsoon committed
8
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
9 10 11 12 13 14
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15 16 17
extern crate mu;

use self::mu::compiler::*;
qinsoon's avatar
qinsoon committed
18
use self::mu::vm::VM;
19
use test_ir::test_ir::factorial;
20

21 22
use std::sync::Arc;

23 24
#[test]
fn test_instsel_fac() {
qinsoon's avatar
qinsoon committed
25
    VM::start_logging_trace();
qinsoon's avatar
qinsoon committed
26

qinsoon's avatar
qinsoon committed
27
    let vm = Arc::new(factorial());
qinsoon's avatar
qinsoon committed
28 29 30

    let compiler = Compiler::new(
        CompilerPolicy::new(vec![
31 32 33 34
            Box::new(passes::DefUse::new()),
            Box::new(passes::TreeGen::new()),
            Box::new(passes::ControlFlowAnalysis::new()),
            Box::new(passes::TraceGen::new()),
qinsoon's avatar
qinsoon committed
35 36
            Box::new(backend::inst_sel::InstructionSelection::new()),
        ]),
37
        &vm,
qinsoon's avatar
qinsoon committed
38 39
    );

qinsoon's avatar
qinsoon committed
40
    let func_id = vm.id_of("fac");
qinsoon's avatar
qinsoon committed
41
    let funcs = vm.funcs().read().unwrap();
42
    let func = funcs.get(&func_id).unwrap().read().unwrap();
qinsoon's avatar
qinsoon committed
43
    let func_vers = vm.func_vers().read().unwrap();
qinsoon's avatar
qinsoon committed
44 45 46 47 48 49
    let mut func_ver = func_vers
        .get(&func.cur_ver.unwrap())
        .unwrap()
        .write()
        .unwrap();

qinsoon's avatar
qinsoon committed
50
    compiler.compile(&mut func_ver);
51
}