]>
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 display(buf
: &[u8]) -> String
{
19 1 => format
!("{:04b}_{:04b}", buf
[0] >> 4, buf
[0] & 0xf),
21 "{:04b}_{:04b} {:04b}_{:04b}",
27 n
=> unreachable
!("Shouldn't be instructions of length {}", n
),
34 parse
::parse_inst($txt
).is
_none
(),
35 "expect to not parse {:?}",
39 ($txt
:expr
=> $res
:expr
) => {
41 let mut cursor
= Cursor
::new(&mut buf
[..]);
42 let parsed
= parse
::parse_inst($txt
).expect(&format
!("to parse {:?}", $txt
));
45 .expect(&format
!("to encode {:?}", parsed
));
46 let pos
= cursor
.position() as usize;
47 assert_eq
!($res
, &display(&buf
[..pos
]), "While parsing {:?}", $txt
);
51 macro_rules
! test_parse
{
52 ($
($txt
:expr
=> $res
:tt
),* $
(,)?
) => {
62 "TRAP" => "0000_0000",
63 "trap" => "0000_0000",
70 "JABS" => "0000_0100",
71 "CABS" => "0000_0101",
72 "JOFF" => "0000_0110",
73 "COFF" => "0000_0111",
80 "swap r0" => "0000_1000",
81 "SWAP r1" => "0000_1001",
82 "Swap\tr2" => "0000_1010",
83 "SWAP\t\tr3" => "0000_1011",
84 "SWAP r4" => "0000_1100",
85 "SWAP r5" => "0000_1101",
86 "SWAP r6" => "0000_1110",
87 "SWAP r7" => "0000_1111",
99 "getr r3" => "0001_0011",
100 "GETR r7" => "0001_0111",
103 "SETR r0" => "0001_1000",
104 "SETR r7" => "0001_1111",
109 fn get_set_special() {
111 "GET1" => "0010_0000",
112 "GET2" => "0010_0001",
113 "GETC" => "0010_0010",
115 "SET1" => "0010_1000",
116 "SET2" => "0010_1001",
117 "SETC" => "0010_1010",
124 "zero" => "0011_0000",
125 "lsl1" => "0011_0001",
126 "lsr1" => "0011_0010",
127 "asr1" => "0011_0011",
128 "incr" => "0011_0100",
129 "decr" => "0011_0101",
130 "comp" => "0011_0110",
131 "negt" => "0011_0111",
138 "islt r0" => "0011_1000",
139 "islt r7" => "0011_1111",
148 "addr r0" => "0100_0000",
149 "addr r4" => "0100_0100",
150 "subr r1" => "0100_1001",
151 "subr r5" => "0100_1101",
152 "andr r2" => "0101_0010",
153 "andr r6" => "0101_0110",
154 "iorr r3" => "0101_1011",
155 "iorr r7" => "0101_1111",
156 "xorr r0" => "0110_0000",
157 "xorr r4" => "0110_0100",
158 "lslr r1" => "0110_1001",
159 "lslr r5" => "0110_1101",
160 "lsrr r2" => "0111_0010",
161 "lsrr r6" => "0111_0110",
162 "asrr r3" => "0111_1011",
163 "asrr r7" => "0111_1111",
170 "ld1u r0" => "1000_0000",
171 "ld1u r3!" => "1001_0011",
172 "ld2u r2!" => "1011_0010",
173 "ld2u r4" => "1010_0100",
175 "st1u r1" => "1000_1001",
176 "st1u r7!" => "1001_1111",
177 "st2u r7!" => "1011_1111",
178 "st2u r7" => "1010_1111",
185 "andi #00" => "1111_0000 0000_0000",
186 "andi #0000" => "1111_0000 0000_0000",
187 "andi #10" => "1111_0000 0000_1010",
188 "andi #255" => "1111_0000 1111_1111",
193 "andi #d00" => "1111_0000 0000_0000",
194 "andi #D0000" => "1111_0000 0000_0000",
195 "andi #d10" => "1111_0000 0000_1010",
196 "andi #D255" => "1111_0000 1111_1111",
201 "andi #x00" => "1111_0000 0000_0000",
202 "andi #XFF" => "1111_0000 1111_1111",
203 "andi #xAA" => "1111_0000 1010_1010",
204 "andi #o177" => "1111_0000 0111_1111",
205 "andi #O177" => "1111_0000 0111_1111",
206 "andi #b11010000" => "1111_0000 1101_0000",
208 "iori #00" => "1111_0001 0000_0000",
209 "iori #32" => "1111_0001 0010_0000",
210 "iori #01" => "1111_0001 0000_0001",
213 "xori #00" => "1111_0010 0000_0000",
214 "xori #07" => "1111_0010 0000_0111",
215 "xori #255" => "1111_0010 1111_1111",
218 "addi #0" => "1111_0011 0000_0000",
219 "addi #1" => "1111_0011 0000_0001",
220 "addi #127" => "1111_0011 0111_1111",
223 "addi #-1" => "1111_0011 1111_1111",
224 "addi #-10" => "1111_0011 1111_0110",
225 "addi #-64" => "1111_0011 1100_0000",
229 "addi #x7F" => "1111_0011 0111_1111",
237 "roli #0" => "1111_0011 1000_0000",
238 "roli #7" => "1111_0011 1000_0111",
242 "lsli #0" => "1111_0011 1000_1000",
243 "lsli #7" => "1111_0011 1000_1111",
244 "lsri #0" => "1111_0011 1001_0000",
245 "lsri #7" => "1111_0011 1001_0111",
246 "asri #0" => "1111_0011 1001_1000",
247 "asri #7" => "1111_0011 1001_1111",
249 "clri #0" => "1111_0011 1010_0000",
250 "clri #7" => "1111_0011 1010_0111",
251 "seti #0" => "1111_0011 1010_1000",
252 "seti #7" => "1111_0011 1010_1111",
253 "togi #0" => "1111_0011 1011_0000",
254 "togi #7" => "1111_0011 1011_0111",
255 "exti #0" => "1111_0011 1011_1000",
256 "exti #7" => "1111_0011 1011_1111",
263 "bezi #0" => "1111_0100 0000_0000",
264 "bezi #1" => "1111_0100 0000_0001",
265 "bezi #-1" => "1111_0100 1111_1111",
266 "bezi #-128" => "1111_0100 1000_0000",
267 "bezi #127" => "1111_0100 0111_1111",
271 "jofi #0" => "1111_0110 0000_0000",
272 "jofi #1" => "1111_0110 0000_0001",
273 "jofi #-1" => "1111_0110 1111_1111",
275 "cofi #0" => "1111_0111 0000_0000",
276 "cofi #1" => "1111_0111 0000_0001",
277 "cofi #-1" => "1111_0111 1111_1111",