To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

test_misc.rs 3.46 KB
Newer Older
1
extern crate libloading;
2
3
extern crate log;
extern crate mu;
4
5

use self::mu::ast::inst::*;
6
7
use self::mu::ast::ir::*;
use self::mu::ast::types::*;
8
9
use self::mu::linkutils;
use self::mu::utils::LinkedHashMap;
10
use self::mu::vm::*;
11
use std::sync::Arc;
12
13
14

#[test]
fn test_mov_minus_one_to_int8() {
15
16
17
18
    let lib = linkutils::aot::compile_fnc(
        "mov_minus_one_to_int8",
        &mov_minus_one_to_int8
    );
19
20

    unsafe {
21
22
        let mov_minus_one_to_int8: libloading::Symbol<unsafe extern "C" fn() -> (i8)>
            = lib.get(b"mov_minus_one_to_int8").unwrap();
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

        let res = mov_minus_one_to_int8();
        println!("mov_minus_one_to_u8() = {}", res);
        assert!(res == -1);
    }
}

fn mov_minus_one_to_int8() -> VM {
    let vm = VM::new();

    typedef!    ((vm) int8 = mu_int(8));

    constdef!   ((vm) <int8> int8_minus_one = Constant::Int(-1i8 as u64));

    funcsig!    ((vm) mov_minus_one_to_int8_sig = () -> (int8));
    funcdecl!   ((vm) <mov_minus_one_to_int8_sig> mov_minus_one_to_int8);
    funcdef!    ((vm) <mov_minus_one_to_int8_sig> mov_minus_one_to_int8
        VERSION mov_minus_one_to_int8_v1);

    block!      ((vm, mov_minus_one_to_int8_v1) blk_entry);
    consta!     ((vm, mov_minus_one_to_int8_v1) int8_minus_one_local = int8_minus_one);
    ssa!        ((vm, mov_minus_one_to_int8_v1) <int8> ret);
    inst!       ((vm, mov_minus_one_to_int8_v1) blk_entry_mov:
        MOVE int8_minus_one_local -> ret
    );

    inst!       ((vm, mov_minus_one_to_int8_v1) blk_entry_ret:
        RET (ret)
    );

    define_block!((vm, mov_minus_one_to_int8_v1) blk_entry() {
        blk_entry_mov,
        blk_entry_ret
    });

    define_func_ver!((vm) mov_minus_one_to_int8_v1 (entry: blk_entry) {
        blk_entry
    });

    vm
}

#[test]
fn test_branch_minus_one_to_int8() {
67
68
69
70
    let lib = linkutils::aot::compile_fnc(
        "branch_minus_one_to_int8",
        &branch_minus_one_to_int8
    );
71
72

    unsafe {
73
        let branch_minus_one_to_int8: libloading::Symbol<
74
            unsafe extern "C" fn() -> (i8)
75
        > = lib.get(b"branch_minus_one_to_int8").unwrap();
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

        let res = branch_minus_one_to_int8();
        println!("branch_minus_one_to_u8() = {}", res);
        assert!(res == -1);
    }
}

fn branch_minus_one_to_int8() -> VM {
    let vm = VM::new();

    typedef!    ((vm) int8 = mu_int(8));

    constdef!   ((vm) <int8> int8_minus_one = Constant::Int(-1i8 as u64));

    funcsig!    ((vm) branch_minus_one_to_int8_sig = () -> (int8));
    funcdecl!   ((vm) <branch_minus_one_to_int8_sig> branch_minus_one_to_int8);
    funcdef!    ((vm) <branch_minus_one_to_int8_sig> branch_minus_one_to_int8
        VERSION branch_minus_one_to_int8_v1);

    // blk_entry
    block!      ((vm, branch_minus_one_to_int8_v1) blk_entry);
    block!      ((vm, branch_minus_one_to_int8_v1) blk_ret);
    consta!     ((vm, branch_minus_one_to_int8_v1) int8_minus_one_local = int8_minus_one);
    inst!       ((vm, branch_minus_one_to_int8_v1) blk_entry_branch:
        BRANCH blk_ret (int8_minus_one_local)
    );

    define_block!((vm, branch_minus_one_to_int8_v1) blk_entry() {
        blk_entry_branch
    });

    // blk_ret
    ssa!        ((vm, branch_minus_one_to_int8_v1) <int8> res);
    inst!       ((vm, branch_minus_one_to_int8_v1) blk_ret_ret:
        RET (res)
    );

    define_block!((vm, branch_minus_one_to_int8_v1) blk_ret(res) {
        blk_ret_ret
    });

    define_func_ver!((vm) branch_minus_one_to_int8_v1 (entry: blk_entry) {
        blk_entry,
        blk_ret
    });

    vm
}