lib: use opcode masks (#7)
Implements a procedural macro for defining the ISA. Moves validity checks to bitmasks instead of spaghetti code patterns. Solves #1
This commit is contained in:
parent
3971f22b11
commit
d8e951befc
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
.idea/
|
.idea/
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
masks.txt
|
||||||
|
__pycache__
|
|
@ -0,0 +1,38 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def apply_pattern(pattern, mask, bits):
|
||||||
|
start, stop, value = map(int, pattern.split(","))
|
||||||
|
bit_count = stop - start + 1
|
||||||
|
shift = 31 - stop
|
||||||
|
mask |= ((1 << bit_count) - 1) << shift
|
||||||
|
bits |= value << shift
|
||||||
|
return mask, bits
|
||||||
|
|
||||||
|
|
||||||
|
def dump_mask(line):
|
||||||
|
parts = line.split(" ")
|
||||||
|
opcode = parts[0]
|
||||||
|
patterns = parts[1:]
|
||||||
|
assert len(patterns) > 0
|
||||||
|
mask, bits = 0, 0
|
||||||
|
for pattern in patterns:
|
||||||
|
mask, bits = apply_pattern(pattern, mask, bits)
|
||||||
|
print(f' "{opcode}" & {hex(mask)} == {hex(bits)};')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with open("patterns.txt", "r") as patterns, open(
|
||||||
|
"../lib/src/isa.rs", "w"
|
||||||
|
) as isa_file:
|
||||||
|
sys.stdout = isa_file
|
||||||
|
print("use ppc750cl_macros::isa;")
|
||||||
|
print()
|
||||||
|
print("isa! {")
|
||||||
|
for line in patterns.readlines():
|
||||||
|
dump_mask(line)
|
||||||
|
print("}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -0,0 +1,222 @@
|
||||||
|
add 0,5,31 21,30,266
|
||||||
|
addc 0,5,31 21,30,21
|
||||||
|
adde 0,5,31 21,30,138
|
||||||
|
addi 0,5,14
|
||||||
|
addic 0,5,12
|
||||||
|
addic. 0,5,13
|
||||||
|
addis 0,5,15
|
||||||
|
addme 0,5,31 16,20,0 22,30,234
|
||||||
|
addze 0,5,31 16,20,0 22,30,202
|
||||||
|
and 0,5,31 21,30,28
|
||||||
|
andc 0,5,31 21,30,60
|
||||||
|
andi. 0,5,28
|
||||||
|
andis. 0,5,29
|
||||||
|
b 0,5,18
|
||||||
|
bc 0,5,16
|
||||||
|
bcctr 0,5,19 16,20,0 21,31,528
|
||||||
|
bclr 0,5,19 16,20,0 21,30,16
|
||||||
|
cmp 0,5,31 9,9,0 21,31,0
|
||||||
|
cmpi 0,5,11 9,9,0
|
||||||
|
cmpl 0,5,31 9,9,0 21,30,32 31,31,0
|
||||||
|
cmpli 0,5,10 9,9,0
|
||||||
|
cntlzw 0,5,31 16,20,0 21,30,26
|
||||||
|
crand 0,5,19 21,30,257 31,31,0
|
||||||
|
crandc 0,5,19 21,30,129 31,31,0
|
||||||
|
creqv 0,5,19 21,30,289 31,31,0
|
||||||
|
crnand 0,5,19 21,30,225 31,31,0
|
||||||
|
crnor 0,5,19 21,30,33 31,31,0
|
||||||
|
cror 0,5,19 21,30,449 31,31,0
|
||||||
|
crorc 0,5,19 21,30,417 31,31,0
|
||||||
|
crxor 0,5,19 21,30,193 31,31,0
|
||||||
|
dcbf 0,5,31 6,10,0 21,30,86 31,31,0
|
||||||
|
dcbi 0,5,31 6,10,0 21,30,470 31,31,0
|
||||||
|
dcbst 0,5,31 6,10,0 21,30,54 31,31,0
|
||||||
|
dcbt 0,5,31 6,10,0 21,30,278 31,31,0
|
||||||
|
dcbtst 0,5,31 6,10,0 21,30,246 31,31,0
|
||||||
|
dcbz 0,5,31 6,10,0 21,30,1014 31,31,0
|
||||||
|
dcbz_l 0,5,4 6,10,0 21,30,1014 31,31,0
|
||||||
|
divw 0,5,31 22,30,491
|
||||||
|
divwu 0,5,31 22,30,459
|
||||||
|
eciwx 0,5,31 22,30,310 31,31,0
|
||||||
|
ecowx 0,5,31 22,30,438 31,31,0
|
||||||
|
eieio 0,5,31 6,20,0 21,30,854 31,31,0
|
||||||
|
eqv 0,5,31 22,30,284
|
||||||
|
extsb 0,5,31 16,20,0 21,30,954
|
||||||
|
extsh 0,5,31 16,20,0 21,30,922
|
||||||
|
fabs 0,5,63 11,15,0 21,30,922
|
||||||
|
fadd 0,5,63 21,25,0 26,30,21
|
||||||
|
fadds 0,5,59 21,25,0 26,30,21
|
||||||
|
fcmpo 0,5,63 9,10,0 21,30,32 31,31,0
|
||||||
|
fcmpu 0,5,63 9,10,0 21,30,0 31,31,0
|
||||||
|
fctiw 0,5,63 11,15,0 21,30,14
|
||||||
|
fctiwz 0,5,63 11,15,0 21,30,15
|
||||||
|
fdiv 0,5,63 21,25,0 26,30,18
|
||||||
|
fdivs 0,5,59 21,25,0 26,30,18
|
||||||
|
fmadd 0,5,63 26,30,29
|
||||||
|
fmadds 0,5,59 26,30,29
|
||||||
|
fmr 0,5,63 11,15,0 21,30,72
|
||||||
|
fmsub 0,5,63 26,30,28
|
||||||
|
fmsubs 0,5,59 26,30,28
|
||||||
|
fmul 0,5,63 16,20,0 26,30,25
|
||||||
|
fmuls 0,5,59 16,20,0 26,30,25
|
||||||
|
fnabs 0,5,63 11,15,0 21,30,136
|
||||||
|
fneg 0,5,63 11,15,0 21,30,40
|
||||||
|
fnmadd 0,5,63 26,30,31
|
||||||
|
fnmadds 0,5,59 26,30,31
|
||||||
|
fnmsub 0,5,63 26,30,30
|
||||||
|
fnmsubs 0,5,59 26,30,30
|
||||||
|
fres 0,5,59 11,15,0 21,25,0 26,30,24
|
||||||
|
frsp 0,5,63 11,15,0 21,30,12
|
||||||
|
frsqrte 0,5,63 11,15,0 21,25,0 26,30,26
|
||||||
|
fsel 0,5,63 26,30,23
|
||||||
|
fsub 0,5,63 21,25,0 26,30,20
|
||||||
|
fsubs 0,5,59 21,25,0 26,30,20
|
||||||
|
icbi 0,5,31 6,10,0 21,30,982 31,31,0
|
||||||
|
isync 0,5,19 6,20,0 21,30,150 31,31,0
|
||||||
|
lbz 0,5,34
|
||||||
|
lbzu 0,5,35
|
||||||
|
lbzux 0,5,31 21,30,119 31,31,0
|
||||||
|
lbzx 0,5,31 21,30,87 31,31,0
|
||||||
|
lfd 0,5,50
|
||||||
|
lfdu 0,5,51
|
||||||
|
lfdux 0,5,31 21,30,631 31,31,0
|
||||||
|
lfdx 0,5,31 21,30,559 31,31,0
|
||||||
|
lfs 0,5,48
|
||||||
|
lfsu 0,5,49
|
||||||
|
lfsux 0,5,31 21,30,567 31,31,0
|
||||||
|
lfsx 0,5,31 21,30,535 31,31,0
|
||||||
|
lha 0,5,42
|
||||||
|
lhau 0,5,43
|
||||||
|
lhaux 0,5,31 21,30,375 31,31,0
|
||||||
|
lhax 0,5,31 21,30,343 31,31,0
|
||||||
|
lhbrx 0,5,31 21,30,790 31,31,0
|
||||||
|
lhz 0,5,40
|
||||||
|
lhzu 0,5,41
|
||||||
|
lhzux 0,5,31 21,30,311 31,31,0
|
||||||
|
lhzx 0,5,31 21,30,279 31,31,0
|
||||||
|
lmw 0,5,46
|
||||||
|
lswi 0,5,31 21,30,597 31,31,0
|
||||||
|
lswx 0,5,31 21,30,533 31,31,0
|
||||||
|
lwarx 0,5,31 21,30,20 31,31,0
|
||||||
|
lwbrx 0,5,31 21,30,534 31,31,0
|
||||||
|
lwz 0,5,32
|
||||||
|
lwzu 0,5,33
|
||||||
|
lwzux 0,5,31 21,30,55 31,31,0
|
||||||
|
lwzx 0,5,31 21,30,23 31,31,0
|
||||||
|
mcrf 0,5,19 10,11,0 20,31,0
|
||||||
|
mcrfs 0,5,63 10,11,0 16,24,0 25,30,64 31,31,0
|
||||||
|
mcrxr 0,5,31 10,11,0 16,24,0 25,30,512 31,31,0
|
||||||
|
mfcr 0,5,31 11,20,0 21,30,19 31,31,0
|
||||||
|
mffs 0,5,31 11,20,0 21,30,583
|
||||||
|
mfmsr 0,5,31 11,20,0 21,30,83 31,31,0
|
||||||
|
mfspr 0,5,31 21,30,339 31,31,0
|
||||||
|
mfsr 0,5,31 11,11,0 16,20,0 21,30,595 31,31,0
|
||||||
|
mfsrin 0,5,31 11,15,0 21,30,659 31,31,0
|
||||||
|
mftb 0,5,31 21,30,371 31,31,0
|
||||||
|
mtcrf 0,5,31 11,11,0 20,20,0 21,30,144 31,31,0
|
||||||
|
mtfsb0 0,5,63 11,20,0 21,30,70
|
||||||
|
mtfsb1 0,5,63 11,20,0 21,30,38
|
||||||
|
mtfsf 0,5,63 6,6,0 15,15,0 21,30,711
|
||||||
|
mtfsfi 0,5,63 9,15,0 20,20,0 21,30,134
|
||||||
|
mtmsr 0,5,31 11,20,0 21,30,146 31,31,0
|
||||||
|
mtspr 0,5,31 21,30,467 31,31,0
|
||||||
|
mtsr 0,5,31 11,11,0 16,20,0 21,30,210 31,31,0
|
||||||
|
mtsrin 0,5,31 11,15,0 21,30,242 31,31,0
|
||||||
|
mulhw 0,5,31 21,21,0 22,30,75
|
||||||
|
mulhwu 0,5,31 21,21,0 22,30,11
|
||||||
|
mulli 0,5,7
|
||||||
|
mullw 0,5,31 22,30,235
|
||||||
|
nand 0,5,31 21,30,476
|
||||||
|
neg 0,5,31 16,20,0 21,30,104
|
||||||
|
nor 0,5,31 21,30,124
|
||||||
|
or 0,5,31 21,30,444
|
||||||
|
orc 0,5,31 21,30,412
|
||||||
|
ori 0,5,24
|
||||||
|
oris 0,5,25
|
||||||
|
psq_l 0,5,56
|
||||||
|
psq_lu 0,5,57
|
||||||
|
psq_lux 0,5,4 25,30,38 31,31,0
|
||||||
|
psq_lx 0,5,4 25,30,6 31,31,0
|
||||||
|
psq_st 0,5,60
|
||||||
|
psq_stu 0,5,61
|
||||||
|
psq_stux 0,5,4 25,30,39 31,31,0
|
||||||
|
psq_stx 0,5,4 25,30,7 31,31,0
|
||||||
|
ps_abs 0,5,4 11,15,0 21,30,264
|
||||||
|
ps_add 0,5,4 21,25,0 26,30,21
|
||||||
|
ps_cmpo0 0,5,4 9,10,0 21,30,32 31,31,0
|
||||||
|
ps_cmpo1 0,5,4 9,10,0 21,30,96 31,31,0
|
||||||
|
ps_cmpu0 0,5,4 9,10,0 21,30,0 31,31,0
|
||||||
|
ps_cmpu1 0,5,4 9,10,0 21,30,64 31,31,0
|
||||||
|
ps_div 0,5,4 21,25,0 26,30,18
|
||||||
|
ps_madd 0,5,4 26,30,29
|
||||||
|
ps_madds0 0,5,4 26,30,14
|
||||||
|
ps_madds1 0,5,4 26,30,15
|
||||||
|
ps_merge00 0,5,4 21,30,528
|
||||||
|
ps_merge01 0,5,4 21,30,560
|
||||||
|
ps_merge10 0,5,4 21,30,592
|
||||||
|
ps_merge11 0,5,4 21,30,624
|
||||||
|
ps_mr 0,5,4 11,15,0 21,30,72
|
||||||
|
ps_msub 0,5,4 26,30,28
|
||||||
|
ps_mul 0,5,4 16,20,0 26,30,25
|
||||||
|
ps_muls0 0,5,4 16,20,0 26,30,12
|
||||||
|
ps_muls1 0,5,4 16,20,0 26,30,13
|
||||||
|
ps_nabs 0,5,4 11,15,0 21,30,136
|
||||||
|
ps_neg 0,5,4 11,15,0 21,30,40
|
||||||
|
ps_nmadd 0,5,4 26,30,31
|
||||||
|
ps_nmsub 0,5,4 26,30,30
|
||||||
|
ps_res 0,5,4 11,15,0 21,25,0 26,30,24
|
||||||
|
ps_rsqrte 0,5,4 11,15,0 21,25,0 26,30,26
|
||||||
|
ps_sel 0,5,4 26,30,23
|
||||||
|
ps_sub 0,5,4 21,25,0 26,30,20
|
||||||
|
ps_sum0 0,5,4 26,30,10
|
||||||
|
ps_sum1 0,5,4 26,30,11
|
||||||
|
rfi 0,5,19 6,20,0 31,31,0
|
||||||
|
rlwimi 0,5,20
|
||||||
|
rlwinm 0,5,21
|
||||||
|
rlwnm 0,5,23
|
||||||
|
sc 0,5,17 6,29,0 30,30,1 31,31,0
|
||||||
|
slw 0,5,31 21,30,24
|
||||||
|
sraw 0,5,31 21,30,792
|
||||||
|
srawi 0,5,31 21,30,824
|
||||||
|
srw 0,5,31 21,30,536
|
||||||
|
stb 0,5,38
|
||||||
|
stbu 0,5,39
|
||||||
|
stbux 0,5,31 22,30,247 31,31,0
|
||||||
|
stbx 0,5,31 22,30,215 31,31,0
|
||||||
|
stfd 0,5,54
|
||||||
|
stfdu 0,5,55
|
||||||
|
stfdux 0,5,31 21,30,759 31,31,0
|
||||||
|
stfdx 0,5,31 21,30,727 31,31,0
|
||||||
|
stfiwx 0,5,31 21,30,983 31,31,0
|
||||||
|
stfs 0,5,52
|
||||||
|
stfsu 0,5,53
|
||||||
|
stfsux 0,5,31 21,30,695 31,31,0
|
||||||
|
stfsx 0,5,31 21,30,663 31,31,0
|
||||||
|
sth 0,5,44
|
||||||
|
sthbrx 0,5,31 21,30,918 31,31,0
|
||||||
|
sthu 0,5,45
|
||||||
|
sthux 0,5,31 21,30,439 31,31,0
|
||||||
|
sthx 0,5,31 21,30,407 31,31,0
|
||||||
|
stmw 0,5,47
|
||||||
|
stswi 0,5,31 21,30,725 31,31,0
|
||||||
|
stswx 0,5,31 21,30,661 31,31,0
|
||||||
|
stw 0,5,36
|
||||||
|
stwbrx 0,5,31 21,30,662 31,31,0
|
||||||
|
stwcx. 0,5,31 21,30,150 31,31,1
|
||||||
|
stwu 0,5,37
|
||||||
|
stwux 0,5,31 21,30,183 31,31,0
|
||||||
|
stwx 0,5,31 21,30,151 31,31,0
|
||||||
|
subf 0,5,31 22,30,40
|
||||||
|
subfc 0,5,31 22,30,8
|
||||||
|
subfe 0,5,31 22,30,136
|
||||||
|
subfic 0,5,8
|
||||||
|
subfme 0,5,31 16,20,0 22,30,232
|
||||||
|
subfze 0,5,31 16,20,0 22,30,200
|
||||||
|
sync 0,5,31 6,20,0 21,30,598 31,31,0
|
||||||
|
tlbie 0,5,31 6,15,0 21,30,306 31,31,0
|
||||||
|
tlbsync 0,5,31 6,20,0 21,30,566 31,31,0
|
||||||
|
tw 0,5,31 21,30,4 31,31,0
|
||||||
|
twi 0,5,3
|
||||||
|
xor 0,5,31 21,30,316
|
||||||
|
xori 0,5,26
|
||||||
|
xoris 0,5,27
|
|
@ -0,0 +1,226 @@
|
||||||
|
use ppc750cl_macros::isa;
|
||||||
|
|
||||||
|
isa! {
|
||||||
|
"add" & 0xfc0007fe == 0x7c000214;
|
||||||
|
"addc" & 0xfc0007fe == 0x7c00002a;
|
||||||
|
"adde" & 0xfc0007fe == 0x7c000114;
|
||||||
|
"addi" & 0xfc000000 == 0x38000000;
|
||||||
|
"addic" & 0xfc000000 == 0x30000000;
|
||||||
|
"addic." & 0xfc000000 == 0x34000000;
|
||||||
|
"addis" & 0xfc000000 == 0x3c000000;
|
||||||
|
"addme" & 0xfc00fbfe == 0x7c0001d4;
|
||||||
|
"addze" & 0xfc00fbfe == 0x7c000194;
|
||||||
|
"and" & 0xfc0007fe == 0x7c000038;
|
||||||
|
"andc" & 0xfc0007fe == 0x7c000078;
|
||||||
|
"andi." & 0xfc000000 == 0x70000000;
|
||||||
|
"andis." & 0xfc000000 == 0x74000000;
|
||||||
|
"b" & 0xfc000000 == 0x48000000;
|
||||||
|
"bc" & 0xfc000000 == 0x40000000;
|
||||||
|
"bcctr" & 0xfc00ffff == 0x4c000210;
|
||||||
|
"bclr" & 0xfc00fffe == 0x4c000020;
|
||||||
|
"cmp" & 0xfc4007ff == 0x7c000000;
|
||||||
|
"cmpi" & 0xfc400000 == 0x2c000000;
|
||||||
|
"cmpl" & 0xfc4007ff == 0x7c000040;
|
||||||
|
"cmpli" & 0xfc400000 == 0x28000000;
|
||||||
|
"cntlzw" & 0xfc00fffe == 0x7c000034;
|
||||||
|
"crand" & 0xfc0007ff == 0x4c000202;
|
||||||
|
"crandc" & 0xfc0007ff == 0x4c000102;
|
||||||
|
"creqv" & 0xfc0007ff == 0x4c000242;
|
||||||
|
"crnand" & 0xfc0007ff == 0x4c0001c2;
|
||||||
|
"crnor" & 0xfc0007ff == 0x4c000042;
|
||||||
|
"cror" & 0xfc0007ff == 0x4c000382;
|
||||||
|
"crorc" & 0xfc0007ff == 0x4c000342;
|
||||||
|
"crxor" & 0xfc0007ff == 0x4c000182;
|
||||||
|
"dcbf" & 0xffe007ff == 0x7c0000ac;
|
||||||
|
"dcbi" & 0xffe007ff == 0x7c0003ac;
|
||||||
|
"dcbst" & 0xffe007ff == 0x7c00006c;
|
||||||
|
"dcbt" & 0xffe007ff == 0x7c00022c;
|
||||||
|
"dcbtst" & 0xffe007ff == 0x7c0001ec;
|
||||||
|
"dcbz" & 0xffe007ff == 0x7c0007ec;
|
||||||
|
"dcbz_l" & 0xffe007ff == 0x100007ec;
|
||||||
|
"divw" & 0xfc0003fe == 0x7c0003d6;
|
||||||
|
"divwu" & 0xfc0003fe == 0x7c000396;
|
||||||
|
"eciwx" & 0xfc0003ff == 0x7c00026c;
|
||||||
|
"ecowx" & 0xfc0003ff == 0x7c00036c;
|
||||||
|
"eieio" & 0xffffffff == 0x7c0006ac;
|
||||||
|
"eqv" & 0xfc0003fe == 0x7c000238;
|
||||||
|
"extsb" & 0xfc00fffe == 0x7c000774;
|
||||||
|
"extsh" & 0xfc00fffe == 0x7c000734;
|
||||||
|
"fabs" & 0xfc1f07fe == 0xfc000734;
|
||||||
|
"fadd" & 0xfc0007fe == 0xfc00002a;
|
||||||
|
"fadds" & 0xfc0007fe == 0xec00002a;
|
||||||
|
"fcmpo" & 0xfc6007ff == 0xfc000040;
|
||||||
|
"fcmpu" & 0xfc6007ff == 0xfc000000;
|
||||||
|
"fctiw" & 0xfc1f07fe == 0xfc00001c;
|
||||||
|
"fctiwz" & 0xfc1f07fe == 0xfc00001e;
|
||||||
|
"fdiv" & 0xfc0007fe == 0xfc000024;
|
||||||
|
"fdivs" & 0xfc0007fe == 0xec000024;
|
||||||
|
"fmadd" & 0xfc00003e == 0xfc00003a;
|
||||||
|
"fmadds" & 0xfc00003e == 0xec00003a;
|
||||||
|
"fmr" & 0xfc1f07fe == 0xfc000090;
|
||||||
|
"fmsub" & 0xfc00003e == 0xfc000038;
|
||||||
|
"fmsubs" & 0xfc00003e == 0xec000038;
|
||||||
|
"fmul" & 0xfc00f83e == 0xfc000032;
|
||||||
|
"fmuls" & 0xfc00f83e == 0xec000032;
|
||||||
|
"fnabs" & 0xfc1f07fe == 0xfc000110;
|
||||||
|
"fneg" & 0xfc1f07fe == 0xfc000050;
|
||||||
|
"fnmadd" & 0xfc00003e == 0xfc00003e;
|
||||||
|
"fnmadds" & 0xfc00003e == 0xec00003e;
|
||||||
|
"fnmsub" & 0xfc00003e == 0xfc00003c;
|
||||||
|
"fnmsubs" & 0xfc00003e == 0xec00003c;
|
||||||
|
"fres" & 0xfc1f07fe == 0xec000030;
|
||||||
|
"frsp" & 0xfc1f07fe == 0xfc000018;
|
||||||
|
"frsqrte" & 0xfc1f07fe == 0xfc000034;
|
||||||
|
"fsel" & 0xfc00003e == 0xfc00002e;
|
||||||
|
"fsub" & 0xfc0007fe == 0xfc000028;
|
||||||
|
"fsubs" & 0xfc0007fe == 0xec000028;
|
||||||
|
"icbi" & 0xffe007ff == 0x7c0007ac;
|
||||||
|
"isync" & 0xffffffff == 0x4c00012c;
|
||||||
|
"lbz" & 0xfc000000 == 0x88000000;
|
||||||
|
"lbzu" & 0xfc000000 == 0x8c000000;
|
||||||
|
"lbzux" & 0xfc0007ff == 0x7c0000ee;
|
||||||
|
"lbzx" & 0xfc0007ff == 0x7c0000ae;
|
||||||
|
"lfd" & 0xfc000000 == 0xc8000000;
|
||||||
|
"lfdu" & 0xfc000000 == 0xcc000000;
|
||||||
|
"lfdux" & 0xfc0007ff == 0x7c0004ee;
|
||||||
|
"lfdx" & 0xfc0007ff == 0x7c00045e;
|
||||||
|
"lfs" & 0xfc000000 == 0xc0000000;
|
||||||
|
"lfsu" & 0xfc000000 == 0xc4000000;
|
||||||
|
"lfsux" & 0xfc0007ff == 0x7c00046e;
|
||||||
|
"lfsx" & 0xfc0007ff == 0x7c00042e;
|
||||||
|
"lha" & 0xfc000000 == 0xa8000000;
|
||||||
|
"lhau" & 0xfc000000 == 0xac000000;
|
||||||
|
"lhaux" & 0xfc0007ff == 0x7c0002ee;
|
||||||
|
"lhax" & 0xfc0007ff == 0x7c0002ae;
|
||||||
|
"lhbrx" & 0xfc0007ff == 0x7c00062c;
|
||||||
|
"lhz" & 0xfc000000 == 0xa0000000;
|
||||||
|
"lhzu" & 0xfc000000 == 0xa4000000;
|
||||||
|
"lhzux" & 0xfc0007ff == 0x7c00026e;
|
||||||
|
"lhzx" & 0xfc0007ff == 0x7c00022e;
|
||||||
|
"lmw" & 0xfc000000 == 0xb8000000;
|
||||||
|
"lswi" & 0xfc0007ff == 0x7c0004aa;
|
||||||
|
"lswx" & 0xfc0007ff == 0x7c00042a;
|
||||||
|
"lwarx" & 0xfc0007ff == 0x7c000028;
|
||||||
|
"lwbrx" & 0xfc0007ff == 0x7c00042c;
|
||||||
|
"lwz" & 0xfc000000 == 0x80000000;
|
||||||
|
"lwzu" & 0xfc000000 == 0x84000000;
|
||||||
|
"lwzux" & 0xfc0007ff == 0x7c00006e;
|
||||||
|
"lwzx" & 0xfc0007ff == 0x7c00002e;
|
||||||
|
"mcrf" & 0xfc300fff == 0x4c000000;
|
||||||
|
"mcrfs" & 0xfc30ffff == 0xfc000080;
|
||||||
|
"mcrxr" & 0xfc30ffff == 0x7c000400;
|
||||||
|
"mfcr" & 0xfc1fffff == 0x7c000026;
|
||||||
|
"mffs" & 0xfc1ffffe == 0x7c00048e;
|
||||||
|
"mfmsr" & 0xfc1fffff == 0x7c0000a6;
|
||||||
|
"mfspr" & 0xfc0007ff == 0x7c0002a6;
|
||||||
|
"mfsr" & 0xfc10ffff == 0x7c0004a6;
|
||||||
|
"mfsrin" & 0xfc1f07ff == 0x7c000526;
|
||||||
|
"mftb" & 0xfc0007ff == 0x7c0002e6;
|
||||||
|
"mtcrf" & 0xfc100fff == 0x7c000120;
|
||||||
|
"mtfsb0" & 0xfc1ffffe == 0xfc00008c;
|
||||||
|
"mtfsb1" & 0xfc1ffffe == 0xfc00004c;
|
||||||
|
"mtfsf" & 0xfe0107fe == 0xfc00058e;
|
||||||
|
"mtfsfi" & 0xfc7f0ffe == 0xfc00010c;
|
||||||
|
"mtmsr" & 0xfc1fffff == 0x7c000124;
|
||||||
|
"mtspr" & 0xfc0007ff == 0x7c0003a6;
|
||||||
|
"mtsr" & 0xfc10ffff == 0x7c0001a4;
|
||||||
|
"mtsrin" & 0xfc1f07ff == 0x7c0001e4;
|
||||||
|
"mulhw" & 0xfc0007fe == 0x7c000096;
|
||||||
|
"mulhwu" & 0xfc0007fe == 0x7c000016;
|
||||||
|
"mulli" & 0xfc000000 == 0x1c000000;
|
||||||
|
"mullw" & 0xfc0003fe == 0x7c0001d6;
|
||||||
|
"nand" & 0xfc0007fe == 0x7c0003b8;
|
||||||
|
"neg" & 0xfc00fffe == 0x7c0000d0;
|
||||||
|
"nor" & 0xfc0007fe == 0x7c0000f8;
|
||||||
|
"or" & 0xfc0007fe == 0x7c000378;
|
||||||
|
"orc" & 0xfc0007fe == 0x7c000338;
|
||||||
|
"ori" & 0xfc000000 == 0x60000000;
|
||||||
|
"oris" & 0xfc000000 == 0x64000000;
|
||||||
|
"psq_l" & 0xfc000000 == 0xe0000000;
|
||||||
|
"psq_lu" & 0xfc000000 == 0xe4000000;
|
||||||
|
"psq_lux" & 0xfc00007f == 0x1000004c;
|
||||||
|
"psq_lx" & 0xfc00007f == 0x1000000c;
|
||||||
|
"psq_st" & 0xfc000000 == 0xf0000000;
|
||||||
|
"psq_stu" & 0xfc000000 == 0xf4000000;
|
||||||
|
"psq_stux" & 0xfc00007f == 0x1000004e;
|
||||||
|
"psq_stx" & 0xfc00007f == 0x1000000e;
|
||||||
|
"ps_abs" & 0xfc1f07fe == 0x10000210;
|
||||||
|
"ps_add" & 0xfc0007fe == 0x1000002a;
|
||||||
|
"ps_cmpo0" & 0xfc6007ff == 0x10000040;
|
||||||
|
"ps_cmpo1" & 0xfc6007ff == 0x100000c0;
|
||||||
|
"ps_cmpu0" & 0xfc6007ff == 0x10000000;
|
||||||
|
"ps_cmpu1" & 0xfc6007ff == 0x10000080;
|
||||||
|
"ps_div" & 0xfc0007fe == 0x10000024;
|
||||||
|
"ps_madd" & 0xfc00003e == 0x1000003a;
|
||||||
|
"ps_madds0" & 0xfc00003e == 0x1000001c;
|
||||||
|
"ps_madds1" & 0xfc00003e == 0x1000001e;
|
||||||
|
"ps_merge00" & 0xfc0007fe == 0x10000420;
|
||||||
|
"ps_merge01" & 0xfc0007fe == 0x10000460;
|
||||||
|
"ps_merge10" & 0xfc0007fe == 0x100004a0;
|
||||||
|
"ps_merge11" & 0xfc0007fe == 0x100004e0;
|
||||||
|
"ps_mr" & 0xfc1f07fe == 0x10000090;
|
||||||
|
"ps_msub" & 0xfc00003e == 0x10000038;
|
||||||
|
"ps_mul" & 0xfc00f83e == 0x10000032;
|
||||||
|
"ps_muls0" & 0xfc00f83e == 0x10000018;
|
||||||
|
"ps_muls1" & 0xfc00f83e == 0x1000001a;
|
||||||
|
"ps_nabs" & 0xfc1f07fe == 0x10000110;
|
||||||
|
"ps_neg" & 0xfc1f07fe == 0x10000050;
|
||||||
|
"ps_nmadd" & 0xfc00003e == 0x1000003e;
|
||||||
|
"ps_nmsub" & 0xfc00003e == 0x1000003c;
|
||||||
|
"ps_res" & 0xfc1f07fe == 0x10000030;
|
||||||
|
"ps_rsqrte" & 0xfc1f07fe == 0x10000034;
|
||||||
|
"ps_sel" & 0xfc00003e == 0x1000002e;
|
||||||
|
"ps_sub" & 0xfc0007fe == 0x10000028;
|
||||||
|
"ps_sum0" & 0xfc00003e == 0x10000014;
|
||||||
|
"ps_sum1" & 0xfc00003e == 0x10000016;
|
||||||
|
"rfi" & 0xfffff801 == 0x4c000000;
|
||||||
|
"rlwimi" & 0xfc000000 == 0x50000000;
|
||||||
|
"rlwinm" & 0xfc000000 == 0x54000000;
|
||||||
|
"rlwnm" & 0xfc000000 == 0x5c000000;
|
||||||
|
"sc" & 0xffffffff == 0x44000002;
|
||||||
|
"slw" & 0xfc0007fe == 0x7c000030;
|
||||||
|
"sraw" & 0xfc0007fe == 0x7c000630;
|
||||||
|
"srawi" & 0xfc0007fe == 0x7c000670;
|
||||||
|
"srw" & 0xfc0007fe == 0x7c000430;
|
||||||
|
"stb" & 0xfc000000 == 0x98000000;
|
||||||
|
"stbu" & 0xfc000000 == 0x9c000000;
|
||||||
|
"stbux" & 0xfc0003ff == 0x7c0001ee;
|
||||||
|
"stbx" & 0xfc0003ff == 0x7c0001ae;
|
||||||
|
"stfd" & 0xfc000000 == 0xd8000000;
|
||||||
|
"stfdu" & 0xfc000000 == 0xdc000000;
|
||||||
|
"stfdux" & 0xfc0007ff == 0x7c0005ee;
|
||||||
|
"stfdx" & 0xfc0007ff == 0x7c0005ae;
|
||||||
|
"stfiwx" & 0xfc0007ff == 0x7c0007ae;
|
||||||
|
"stfs" & 0xfc000000 == 0xd0000000;
|
||||||
|
"stfsu" & 0xfc000000 == 0xd4000000;
|
||||||
|
"stfsux" & 0xfc0007ff == 0x7c00056e;
|
||||||
|
"stfsx" & 0xfc0007ff == 0x7c00052e;
|
||||||
|
"sth" & 0xfc000000 == 0xb0000000;
|
||||||
|
"sthbrx" & 0xfc0007ff == 0x7c00072c;
|
||||||
|
"sthu" & 0xfc000000 == 0xb4000000;
|
||||||
|
"sthux" & 0xfc0007ff == 0x7c00036e;
|
||||||
|
"sthx" & 0xfc0007ff == 0x7c00032e;
|
||||||
|
"stmw" & 0xfc000000 == 0xbc000000;
|
||||||
|
"stswi" & 0xfc0007ff == 0x7c0005aa;
|
||||||
|
"stswx" & 0xfc0007ff == 0x7c00052a;
|
||||||
|
"stw" & 0xfc000000 == 0x90000000;
|
||||||
|
"stwbrx" & 0xfc0007ff == 0x7c00052c;
|
||||||
|
"stwcx." & 0xfc0007ff == 0x7c00012d;
|
||||||
|
"stwu" & 0xfc000000 == 0x94000000;
|
||||||
|
"stwux" & 0xfc0007ff == 0x7c00016e;
|
||||||
|
"stwx" & 0xfc0007ff == 0x7c00012e;
|
||||||
|
"subf" & 0xfc0003fe == 0x7c000050;
|
||||||
|
"subfc" & 0xfc0003fe == 0x7c000010;
|
||||||
|
"subfe" & 0xfc0003fe == 0x7c000110;
|
||||||
|
"subfic" & 0xfc000000 == 0x20000000;
|
||||||
|
"subfme" & 0xfc00fbfe == 0x7c0001d0;
|
||||||
|
"subfze" & 0xfc00fbfe == 0x7c000190;
|
||||||
|
"sync" & 0xffffffff == 0x7c0004ac;
|
||||||
|
"tlbie" & 0xffff07ff == 0x7c000264;
|
||||||
|
"tlbsync" & 0xffffffff == 0x7c00046c;
|
||||||
|
"tw" & 0xfc0007ff == 0x7c000008;
|
||||||
|
"twi" & 0xfc000000 == 0xc000000;
|
||||||
|
"xor" & 0xfc0007fe == 0x7c000278;
|
||||||
|
"xori" & 0xfc000000 == 0x68000000;
|
||||||
|
"xoris" & 0xfc000000 == 0x6c000000;
|
||||||
|
}
|
1216
lib/src/lib.rs
1216
lib/src/lib.rs
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
||||||
use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree, Literal};
|
use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use syn::parse::{Parse, ParseStream};
|
use syn::parse::{Parse, ParseStream};
|
||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
|
@ -88,14 +88,22 @@ fn opcode_to_variant_name(opcode: &LitStr) -> syn::Result<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_is_valid_fn(tokens: &mut Vec<TokenTree>, opcodes: &Opcodes) {
|
fn gen_is_valid_fn(tokens: &mut Vec<TokenTree>, opcodes: &Opcodes) {
|
||||||
let header: TokenStream = "fn is_valid(&self, code: u32) -> bool".parse().unwrap();
|
let header: TokenStream = "pub fn is_valid(self, code: u32) -> bool".parse().unwrap();
|
||||||
tokens.append(&mut header.into_iter().collect());
|
tokens.append(&mut header.into_iter().collect());
|
||||||
let mut parts = Vec::<TokenTree>::new();
|
let mut parts = Vec::<TokenTree>::new();
|
||||||
let match_header: TokenStream = "match self".parse().unwrap();
|
let match_header: TokenStream = "match self".parse().unwrap();
|
||||||
parts.append(&mut match_header.into_iter().collect());
|
parts.append(&mut match_header.into_iter().collect());
|
||||||
let mut match_parts = Vec::<TokenTree>::new();
|
let mut match_parts = Vec::<TokenTree>::new();
|
||||||
|
let illegal_match: TokenStream = "Opcode::Illegal => false,".parse().unwrap();
|
||||||
|
match_parts.append(&mut illegal_match.into_iter().collect());
|
||||||
for opcode in &opcodes.opcodes {
|
for opcode in &opcodes.opcodes {
|
||||||
match_parts.push(TokenTree::Ident(Ident::new(&opcode.variant_name, Span::call_site())));
|
match_parts.push(TokenTree::Ident(Ident::new("Opcode", Span::call_site())));
|
||||||
|
match_parts.push(TokenTree::Punct(Punct::new(':', Spacing::Joint)));
|
||||||
|
match_parts.push(TokenTree::Punct(Punct::new(':', Spacing::Alone)));
|
||||||
|
match_parts.push(TokenTree::Ident(Ident::new(
|
||||||
|
&opcode.variant_name,
|
||||||
|
Span::call_site(),
|
||||||
|
)));
|
||||||
match_parts.push(TokenTree::Punct(Punct::new('=', Spacing::Joint)));
|
match_parts.push(TokenTree::Punct(Punct::new('=', Spacing::Joint)));
|
||||||
match_parts.push(TokenTree::Punct(Punct::new('>', Spacing::Alone)));
|
match_parts.push(TokenTree::Punct(Punct::new('>', Spacing::Alone)));
|
||||||
match_parts.push(TokenTree::Ident(Ident::new("code", Span::call_site())));
|
match_parts.push(TokenTree::Ident(Ident::new("code", Span::call_site())));
|
||||||
|
@ -106,15 +114,9 @@ fn gen_is_valid_fn(tokens: &mut Vec<TokenTree>, opcodes: &Opcodes) {
|
||||||
match_parts.push(TokenTree::Literal(Literal::u32_suffixed(opcode.bits)));
|
match_parts.push(TokenTree::Literal(Literal::u32_suffixed(opcode.bits)));
|
||||||
match_parts.push(TokenTree::Punct(Punct::new(',', Spacing::Alone)));
|
match_parts.push(TokenTree::Punct(Punct::new(',', Spacing::Alone)));
|
||||||
}
|
}
|
||||||
let match_body = Group::new(
|
let match_body = Group::new(Delimiter::Brace, TokenStream::from_iter(match_parts));
|
||||||
Delimiter::Brace,
|
|
||||||
TokenStream::from_iter(match_parts),
|
|
||||||
);
|
|
||||||
parts.push(TokenTree::Group(match_body));
|
parts.push(TokenTree::Group(match_body));
|
||||||
let body = Group::new(
|
let body = Group::new(Delimiter::Brace, TokenStream::from_iter(parts));
|
||||||
Delimiter::Brace,
|
|
||||||
TokenStream::from_iter(parts),
|
|
||||||
);
|
|
||||||
tokens.push(TokenTree::Group(body));
|
tokens.push(TokenTree::Group(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue