]> Witch of Git - jade-rose/blob - toolchain/src/inst.rs
Add the wait state to the state machine
[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 pub use self::{decode::Decode, encode::Encode};
9
10 #[cfg(test)]
11 use proptest_derive::Arbitrary;
12
13 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
14 #[cfg_attr(test, derive(Arbitrary))]
15 #[repr(u8)]
16 pub enum Op1 {
17 Zero,
18 Lsl1,
19 Lsr1,
20 Asr1,
21 Incr,
22 Decr,
23 Comp,
24 Negt,
25 }
26
27 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
28 #[cfg_attr(test, derive(Arbitrary))]
29 #[repr(u8)]
30 pub enum OpR {
31 Add,
32 Sub,
33 And,
34 Ior,
35 Xor,
36 Lsl,
37 Lsr,
38 Asr,
39 }
40
41 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
42 #[cfg_attr(test, derive(Arbitrary))]
43 #[repr(u8)]
44 pub enum OpI3 {
45 Rol,
46 Lsl,
47 Lsr,
48 Asr,
49 Clr,
50 Ins,
51 Tog,
52 Ext,
53 }
54
55 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
56 #[cfg_attr(test, derive(Arbitrary))]
57 #[repr(u8)]
58 pub enum Data {
59 D1,
60 D2,
61 }
62
63 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
64 #[cfg_attr(test, derive(Arbitrary))]
65 pub enum Special {
66 Data(Data),
67 Code,
68 }
69
70 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
71 #[cfg_attr(test, derive(Arbitrary))]
72 pub struct Reg(U3);
73 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
74 #[cfg_attr(test, derive(Arbitrary))]
75 pub struct U3(#[cfg_attr(test, proptest(strategy = "0..=7u8"))] u8);
76 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
77 #[cfg_attr(test, derive(Arbitrary))]
78 pub struct AddImm(#[cfg_attr(test, proptest(strategy = "-64..=127i8"))] i8);
79
80 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
81 #[cfg_attr(test, derive(Arbitrary))]
82 pub enum AluI {
83 And(u8),
84 Ior(u8),
85 Xor(u8),
86 Add(AddImm),
87 Compact(OpI3, U3),
88 }
89
90 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
91 #[cfg_attr(test, derive(Arbitrary))]
92 #[repr(u8)]
93 pub enum LdSt {
94 Ld,
95 St,
96 }
97
98 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
99 #[cfg_attr(test, derive(Arbitrary))]
100 #[cfg_attr(test, proptest(no_params))]
101 pub enum Inst {
102 Stop,
103 Nope,
104 Prnt,
105 CAbA,
106 COfA,
107 Alu1(Op1),
108 Get(Special),
109 Set(Special),
110 GetR(Reg),
111 SetR(Reg),
112 Swap(Reg),
113 IsLt(Reg),
114 AluR(OpR, Reg),
115 Mem(LdSt, Data, Reg, bool),
116 AluI(AluI),
117 BEzI(i8),
118 JOfI(i8),
119 CAbI(u8),
120 COfI(i8),
121 GetI(u8),
122 }
123
124 impl Inst {
125 pub fn parse(s: &str) -> Option<Self> {
126 parse::parse_inst(s)
127 }
128 }
129
130 impl Reg {
131 pub fn new(x: u8) -> Option<Reg> {
132 U3::new(x).map(Reg)
133 }
134 }
135
136 impl U3 {
137 pub fn new(x: u8) -> Option<U3> {
138 match x {
139 0..=7 => Some(U3(x)),
140 _ => None,
141 }
142 }
143 }
144
145 impl AddImm {
146 pub fn new(x: i8) -> Option<AddImm> {
147 match x {
148 -64..=127 => Some(AddImm(x)),
149 _ => None,
150 }
151 }
152 }