]>
Witch of Git - jade-rose/blob - toolchain/src/inst/test.rs
1 use super::{decode
::Decode
, encode
::Encode
, parse
, Inst
};
2 use proptest
::prelude
::*;
7 fn roundtrip(inst
: Inst
) {
9 let mut cursor
= Cursor
::new(&mut buf
[..]);
10 inst
.encode(&mut cursor
).expect("to encode");
11 cursor
.set_position(0);
12 let decoded
= Inst
::decode(&mut cursor
).expect("to decode");
13 prop_assert_eq
!(inst
, decoded
);
17 fn format_roundtrip(inst
: Inst
) {
18 let formatted
= format
!("{}", inst
);
19 prop_assert_eq
!(parse
::parse_inst(&formatted
).unwrap
(), inst
, "formatted as {:?}", formatted
);
23 fn display(buf
: &[u8]) -> String
{
25 1 => format
!("{:04b}_{:04b}", buf
[0] >> 4, buf
[0] & 0xf),
27 "{:04b}_{:04b} {:04b}_{:04b}",
33 n
=> unreachable
!("Shouldn't be instructions of length {}", n
),
40 parse
::parse_inst($txt
).is
_none
(),
41 "expect to not parse {:?}",
45 ($txt
:expr
=> $res
:expr
) => {
47 let mut cursor
= Cursor
::new(&mut buf
[..]);
48 let parsed
= parse
::parse_inst($txt
).expect(&format
!("to parse {:?}", $txt
));
51 .expect(&format
!("to encode {:?}", parsed
));
52 let pos
= cursor
.position() as usize;
53 assert_eq
!($res
, &display(&buf
[..pos
]), "While parsing {:?}", $txt
);
57 macro_rules
! test_parse
{
58 ($
($txt
:expr
=> $res
:tt
),* $
(,)?
) => {
68 "STOP" => "0000_0000",
69 "stop" => "0000_0000",
76 "NOPE" => "0000_0001",
83 "PRNT" => "0000_0010",
90 "CABA" => "0000_0110",
91 "COFA" => "0000_0111",
98 "zero" => "0000_1000",
99 "lsl1" => "0000_1001",
100 "lsr1" => "0000_1010",
101 "asr1" => "0000_1011",
102 "incr" => "0000_1100",
103 "decr" => "0000_1101",
104 "comp" => "0000_1110",
105 "negt" => "0000_1111",
110 fn get_set_special() {
112 "GET1" => "0001_0000",
113 "GET2" => "0001_0001",
114 "GETC" => "0001_0010",
116 "SET1" => "0001_1000",
117 "SET2" => "0001_1001",
118 "SETC" => "0001_1010",
125 "getr r3" => "0010_0011",
126 "GETR r7" => "0010_0111",
130 "SETR r0" => "0010_1000",
131 "SETR r7" => "0010_1111",
138 "swap r0" => "0011_0000",
139 "SWAP r1" => "0011_0001",
140 "Swap\tr2" => "0011_0010",
141 "SWAP\t\tr3" => "0011_0011",
142 "SWAP r4" => "0011_0100",
143 "SWAP r5" => "0011_0101",
144 "SWAP r6" => "0011_0110",
145 "SWAP r7" => "0011_0111",
157 "islt r0" => "0011_1000",
158 "islt r7" => "0011_1111",
167 "addr r0" => "0100_0000",
168 "addr r4" => "0100_0100",
169 "subr r1" => "0100_1001",
170 "subr r5" => "0100_1101",
171 "andr r2" => "0101_0010",
172 "andr r6" => "0101_0110",
173 "iorr r3" => "0101_1011",
174 "iorr r7" => "0101_1111",
175 "xorr r0" => "0110_0000",
176 "xorr r4" => "0110_0100",
177 "lslr r1" => "0110_1001",
178 "lslr r5" => "0110_1101",
179 "lsrr r2" => "0111_0010",
180 "lsrr r6" => "0111_0110",
181 "asrr r3" => "0111_1011",
182 "asrr r7" => "0111_1111",
189 "ld1u r0" => "1000_0000",
190 "ld1u r3!" => "1001_0011",
191 "ld2u r2!" => "1011_0010",
192 "ld2u r4" => "1010_0100",
194 "st1u r1" => "1000_1001",
195 "st1u r7!" => "1001_1111",
196 "st2u r7!" => "1011_1111",
197 "st2u r7" => "1010_1111",
204 "andi 00" => "1111_0000 0000_0000",
205 "andi 0000" => "1111_0000 0000_0000",
206 "andi 10" => "1111_0000 0000_1010",
207 "andi 255" => "1111_0000 1111_1111",
212 "andi 0d00" => "1111_0000 0000_0000",
213 "andi 0D0000" => "1111_0000 0000_0000",
214 "andi 0d10" => "1111_0000 0000_1010",
215 "andi 0D255" => "1111_0000 1111_1111",
220 "andi 0x00" => "1111_0000 0000_0000",
221 "andi 0XFF" => "1111_0000 1111_1111",
222 "andi 0xAA" => "1111_0000 1010_1010",
223 "andi 0o177" => "1111_0000 0111_1111",
224 "andi 0O177" => "1111_0000 0111_1111",
225 "andi 0b11010000" => "1111_0000 1101_0000",
227 "iori 00" => "1111_0001 0000_0000",
228 "iori 32" => "1111_0001 0010_0000",
229 "iori 01" => "1111_0001 0000_0001",
232 "xori 00" => "1111_0010 0000_0000",
233 "xori 07" => "1111_0010 0000_0111",
234 "xori 255" => "1111_0010 1111_1111",
237 "addi 0" => "1111_0011 0000_0000",
238 "addi 1" => "1111_0011 0000_0001",
239 "addi 127" => "1111_0011 0111_1111",
242 "addi -1" => "1111_0011 1111_1111",
243 "addi -10" => "1111_0011 1111_0110",
244 "addi -64" => "1111_0011 1100_0000",
248 "addi 0x7F" => "1111_0011 0111_1111",
256 "roli 0" => "1111_0011 1000_0000",
257 "roli 7" => "1111_0011 1000_0111",
261 "lsli 0" => "1111_0011 1000_1000",
262 "lsli 7" => "1111_0011 1000_1111",
263 "lsri 0" => "1111_0011 1001_0000",
264 "lsri 7" => "1111_0011 1001_0111",
265 "asri 0" => "1111_0011 1001_1000",
266 "asri 7" => "1111_0011 1001_1111",
268 "clri 0" => "1111_0011 1010_0000",
269 "clri 7" => "1111_0011 1010_0111",
270 "insi 0" => "1111_0011 1010_1000",
271 "insi 7" => "1111_0011 1010_1111",
272 "togi 0" => "1111_0011 1011_0000",
273 "togi 7" => "1111_0011 1011_0111",
274 "exti 0" => "1111_0011 1011_1000",
275 "exti 7" => "1111_0011 1011_1111",
282 "bezi 0" => "1111_0100 0000_0000",
283 "bezi 1" => "1111_0100 0000_0001",
284 "bezi -1" => "1111_0100 1111_1111",
285 "bezi -128" => "1111_0100 1000_0000",
286 "bezi 127" => "1111_0100 0111_1111",
290 "jofi 0" => "1111_0101 0000_0000",
291 "jofi 1" => "1111_0101 0000_0001",
292 "jofi -1" => "1111_0101 1111_1111",
294 "cabi 0" => "1111_0110 0000_0000",
295 "cabi 1" => "1111_0110 0000_0001",
298 "cofi 0" => "1111_0111 0000_0000",
299 "cofi 1" => "1111_0111 0000_0001",
300 "cofi -1" => "1111_0111 1111_1111",
307 "geti 0" => "1111_1110 0000_0000",
308 "geti 1" => "1111_1110 0000_0001",
309 "geti 0xFF" => "1111_1110 1111_1111",
311 "geti -1" => "1111_1110 1111_1111",
312 "geti -128" => "1111_1110 1000_0000",