insndb: rename types into core
[openpower-isa.git] / src / openpower / sv / trans / test_pysvp64dis_branch.py
1 from openpower.simulator.program import Program
2 from openpower.insndb.dis import load, dump
3 from openpower.insndb.asm import SVP64Asm
4 from openpower.insndb.core import Database, Style
5 from openpower.decoder.power_enums import find_wiki_dir
6 from openpower.sv import sv_binutils_fptrans
7 import unittest
8 import itertools
9 import sys
10
11 class SVSTATETestCase(unittest.TestCase):
12
13 def _do_tst(self, expected):
14 isa = SVP64Asm(expected)
15 lst = list(isa)
16 with Program(lst, bigendian=False) as program:
17 print ("ops", program._instructions)
18 program.binfile.seek(0)
19 insns = load(program.binfile)
20 #for insn in insns:
21 #print ("insn", insn)
22 insns = list(insns)
23 print ("insns", insns)
24 for i, line in enumerate(dump(insns, style=Style.SHORT)):
25 name = expected[i].split(" ")[0]
26 with self.subTest("%d:%s" % (i, name)):
27 print("instruction", repr(line), repr(expected[i]))
28 self.assertEqual(expected[i], line,
29 "instruction does not match "
30 "'%s' expected '%s'" % (line, expected[i]))
31
32
33 def test_0_bc(self):
34 # hilarious. this should be autogenerated from a sequence
35 # of lists of options. it's a lot of frickin options.
36 lists = [[None, 'all'],
37 [None, 'm=r3', 'sz', 'snz'], # see below on this one...
38 [None, 'vs', 'vsi', 'vsb', 'vsbi'],
39 [None, 'ctr', 'cti'],
40 [None, 'sl'],
41 [None, 'slu'],
42 [None, 'lru'],
43 ]
44 expected = []
45 for options in itertools.product(*lists): # permutations of list-options
46 options = list(filter(lambda x:x, options)) # filter Nones
47 # /sz or /snz must have /m=r3 added but then sorted
48 if 'sz' in options or 'snz' in options:
49 options.append("m=r3")
50 options.sort() # otherwise chaos!
51 if len(options) != 0:
52 options = [''] + options # trick to make a "/" at the front
53 print ("option", options)
54 # ahhhhhahahaha and sv.bcctr and sv.bcl ahahahahaah....
55 option = "sv.bc%s 12,*1,0xc" % "/".join(options)
56 expected.append(option)
57
58 self._do_tst(expected)
59
60 if __name__ == "__main__":
61 unittest.main()
62