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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use operation::*;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Opcode {
Arm(u32),
Thumb(u16),
}
macro_rules! simple_from {
($src:ty => $dst:ty as $variant:path) => {
impl From<$src> for $dst {
fn from(orig: $src) -> Self {
$variant(orig)
}
}
};
}
simple_from!(u16 => Opcode as Opcode::Thumb);
simple_from!(u32 => Opcode as Opcode::Arm);
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Instruction {
Arm(Condition, Operation),
Thumb(Operation),
}
impl From<Opcode> for Instruction {
fn from(opcode: Opcode) -> Self {
use arm;
use thumb;
match opcode {
Opcode::Arm(w) => {
let condition = arm::condition(w);
let operation = arm::decode(w);
Instruction::Arm(condition, operation)
}
Opcode::Thumb(s) => {
let operation = thumb::decode(s);
Instruction::Thumb(operation)
}
}
}
}