~nabijaczleweli/yaxpeax-superh

ref: 6ae35f2bf775252e254141be09d1d9c72893c811 yaxpeax-superh/tests/bare/mod.rs -rw-r--r-- 1.8 KiB
6ae35f2bнаб Some more displays a month ago
                                                                                
1
2
3
4
5
6
7
8
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
extern crate yaxpeax_superh;

use yaxpeax_superh::{SuperHFloatRegister, SuperHInstruction, SuperHRegister, Displacement8};


#[test]
fn round_trip() {
    for i in 0..=0xFFFF {
        for &fpscr_sz in &[true, false] {
            if let Some(ins) = SuperHInstruction::parse(i, fpscr_sz) {
                let rt: u16 = ins.into();
                assert_eq!(rt, i as u16, "{:#06X} !+ {:#06X} for {:?}", rt, i as u16, ins);
            }
        }
    }
}

#[test]
fn display() {
    assert_eq!(format!("{}", SuperHInstruction::MovImm(0x69, SuperHRegister::R4)), "MOV #105,R4"); // Agrees with objdump
    assert_eq!(format!("{}", SuperHInstruction::Bf(Displacement8(0xFD))), "BF 253");
    assert_eq!(format!("{}", SuperHInstruction::FMovAtIndexedRegisterS(SuperHRegister::R2, SuperHFloatRegister::Fr3)), "FMOV.S @(R0,R2),FR3");
}


mod generated_f64 {
    use yaxpeax_superh::{SuperHInstruction, SuperHRegister, SuperHRegisterBank, SuperHFloatRegister, SuperHVectorFloatRegister, SuperHDoubleRegister,
                         SuperHExtendedDoubleRegister, Displacement4, Displacement8, Displacement12};
    include!("instruction_map-with-overrides.rs");
}

mod generated_no_f64 {
    use yaxpeax_superh::{SuperHInstruction, SuperHRegister, SuperHRegisterBank, SuperHFloatRegister, SuperHVectorFloatRegister, SuperHDoubleRegister,
                         Displacement4, Displacement8, Displacement12};
    include!("instruction_map-unoverriden.rs");
}

#[test]
fn decode_f64() {
    for (i, &ins) in generated_f64::MAPPING.iter().enumerate() {
        assert_eq!(SuperHInstruction::parse(i as u16, true), ins);
    }
}

#[test]
fn decode_no_f64() {
    for (i, &ins) in generated_no_f64::MAPPING.iter().enumerate() {
        assert_eq!(SuperHInstruction::parse(i as u16, false), ins);
    }
}