test_tree_gen.rs 1.87 KB
Newer Older
1
2
3
4
5
6
7
8
extern crate mu;
extern crate log;
extern crate simple_logger;

use test_ir::test_ir::factorial;
use self::mu::compiler::*;
use self::mu::vm::context::VMContext;

qinsoon's avatar
qinsoon committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[test]
fn test_use_count() {
    simple_logger::init_with_level(log::LogLevel::Trace).ok();
    
    let vm_context : VMContext = factorial();
    let compiler = Compiler::new(CompilerPolicy::new(
        vec![Box::new(passes::DefUse::new())]
    ));
    
    let mut factorial_func = {
        vm_context.get_func("fac").unwrap().borrow_mut()
    };
    
    compiler.compile(&vm_context, &mut factorial_func);
    
    assert!(factorial_func.context.get_value(0).unwrap().use_count.get() == 2, "blk_0_n_3 use should be 2");
    assert!(factorial_func.context.get_value(1).unwrap().use_count.get() == 1, "blk_0_v48 use should be 1");
    assert!(factorial_func.context.get_value(2).unwrap().use_count.get() == 1, "blk_2_v53 use should be 1");
    assert!(factorial_func.context.get_value(3).unwrap().use_count.get() == 2, "blk_1_n_3 use should be 2");
    assert!(factorial_func.context.get_value(4).unwrap().use_count.get() == 1, "blk_1_v50 use should be 1");
    assert!(factorial_func.context.get_value(5).unwrap().use_count.get() == 1, "blk_1_v51 use should be 1");
    assert!(factorial_func.context.get_value(6).unwrap().use_count.get() == 1, "blk_1_fac use should be 1");
    assert!(factorial_func.context.get_value(7).unwrap().use_count.get() == 1, "blk_1_v52 use should be 1");
}

34
#[test]
35
fn test_build_tree() {
qinsoon's avatar
qinsoon committed
36
    simple_logger::init_with_level(log::LogLevel::Trace).ok();
37
38
    
    let vm_context : VMContext = factorial();
qinsoon's avatar
qinsoon committed
39
40
41
42
    let compiler = Compiler::new(CompilerPolicy::new(
        vec![Box::new(passes::DefUse::new()),
             Box::new(passes::TreeGen::new())]
    ));
43
44
45
46
47
48
49
    
    let mut factorial_func = {
        vm_context.get_func("fac").unwrap().borrow_mut()
    };
    
    compiler.compile(&vm_context, &mut factorial_func);
}