]> Witch of Git - jade-rose/blob - toolchain/src/inst.rs
Update spec
[jade-rose] / toolchain / src / inst.rs
1 pub mod decode;
2 pub mod encode;
3 mod format;
4 pub mod parse;
5 #[cfg(test)]
6 pub mod test;
7
8 #[cfg(test)]
9 use proptest_derive::Arbitrary;
10
11 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12 #[cfg_attr(test, derive(Arbitrary))]
13 #[repr(u8)]
14 pub enum Op1 {
15 Zero,
16 Lsl1,
17 Lsr1,
18 Asr1,
19 Incr,
20 Decr,
21 Comp,
22 Negt,
23 }
24
25 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
26 #[cfg_attr(test, derive(Arbitrary))]
27 #[repr(u8)]
28 pub enum OpR {
29 Add,
30 Sub,
31 And,
32 Ior,
33 Xor,
34 Lsl,
35 Lsr,
36 Asr,
37 }
38
39 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
40 #[cfg_attr(test, derive(Arbitrary))]
41 #[repr(u8)]
42 pub enum OpI3 {
43 Rol,
44 Lsl,
45 Lsr,
46 Asr,
47 Clr,
48 Set,
49 Tog,
50 Ext,
51 }
52
53 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
54 #[cfg_attr(test, derive(Arbitrary))]
55 #[repr(u8)]
56 pub enum Data {
57 D1,
58 D2,
59 }
60
61 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
62 #[cfg_attr(test, derive(Arbitrary))]
63 pub enum Special {
64 Data(Data),
65 Code,
66 }
67
68 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
69 #[cfg_attr(test, derive(Arbitrary))]
70 pub struct Reg(U3);
71 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
72 #[cfg_attr(test, derive(Arbitrary))]
73 pub struct U3(#[cfg_attr(test, proptest(strategy = "0..=7u8"))] u8);
74 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
75 #[cfg_attr(test, derive(Arbitrary))]
76 pub struct AddImm(#[cfg_attr(test, proptest(strategy = "-64..=127i8"))] i8);
77
78 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
79 #[cfg_attr(test, derive(Arbitrary))]
80 pub enum AluI {
81 And(u8),
82 Ior(u8),
83 Xor(u8),
84 Add(AddImm),
85 Compact(OpI3, U3),
86 }
87
88 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
89 #[cfg_attr(test, derive(Arbitrary))]
90 pub enum Target {
91 Abs,
92 Off,
93 OffImm(i8),
94 }
95
96 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
97 #[cfg_attr(test, derive(Arbitrary))]
98 #[cfg_attr(test, proptest(no_params))]
99 pub enum Inst {
100 Trap,
101 Jump(Target),
102 Call(Target),
103 Swap(Reg),
104 GetR(Reg),
105 SetR(Reg),
106 Get(Special),
107 Set(Special),
108 Alu1(Op1),
109 IsLt(Reg),
110 AluR(OpR, Reg),
111 LdD(Data, Reg, bool),
112 StD(Data, Reg, bool),
113 AluI(AluI),
114 BEzI(i8),
115 }
116
117 impl Reg {
118 pub fn new(x: u8) -> Option<Reg> {
119 U3::new(x).map(Reg)
120 }
121 }
122
123 impl U3 {
124 pub fn new(x: u8) -> Option<U3> {
125 match x {
126 0..=7 => Some(U3(x)),
127 _ => None,
128 }
129 }
130 }
131
132 impl AddImm {
133 pub fn new(x: i8) -> Option<AddImm> {
134 match x {
135 -64..=127 => Some(AddImm(x)),
136 _ => None,
137 }
138 }
139 }