2 from openpower
.decoder
.power_enums
import find_wiki_dir
3 from openpower
.decoder
.power_insn
import (Database
, MarkdownDatabase
,
4 FieldsDatabase
, PPCDatabase
,
5 IntegerOpcode
, PatternOpcode
,
6 parse
, Section
, BitSel
,
9 root
= pathlib
.Path(root
)
10 mdwndb
= MarkdownDatabase()
11 fieldsdb
= FieldsDatabase()
13 # create by-sections first. these will be the markdown tables
16 path
= (root
/ "insndb.csv")
17 with
open(path
, "r", encoding
="UTF-8") as stream
:
18 for section
in parse(stream
, Section
.CSV
):
19 sections
[str(section
.path
)] = section
20 insns
[str(section
.path
)] = []
21 for (name
, section
) in sections
.items():
24 # enumerate all instructions and drop them into sections
27 insns
[str(insn
.section
.path
)].append(insn
)
34 return format(v
, "0%db" % num
)
37 def do_table(fname
, insns
, section
, divpoint
):
39 section
= sections
[fname
]
40 start
, end
= section
.bitsel
.start
, section
.bitsel
.end
41 print ("start-end", start
, end
)
44 lowermask
= (1<<half
)-1
45 uppermask
= (1<<(bitlen
-half
))-1
47 # debug-print all opcodes first
51 #fields += [(insn.ppc.opcode.value, insn.ppc.bitsel)]
52 #opcode = FieldsOpcode(fields)
53 opcode
= insn
.ppc
.opcode
54 if not isinstance(opcode
, list):
57 print ("op", insn
.name
, op
)
58 if insn
.name
not in opcode_per_insn
:
59 opcode_per_insn
[insn
.name
] = []
60 opcode_per_insn
[insn
.name
] += opcode
63 for i
in range(1<<bitlen
):
64 # calculate row, column
66 upper
= (i
>>half
) & uppermask
67 print (i
, bin(lower
), bin(upper
))
68 if upper
not in table_entries
:
69 table_entries
[upper
] = {}
70 table_entries
[upper
][lower
] = None
73 print ("search", i
, hex(key
))
76 opcode
= opcode_per_insn
[insn
.name
]
78 #print (" search", i, hex(key), insn.name,
79 # hex(op.value), hex(op.mask))
80 if ((op
.value
& op
.mask
) == (key
& op
.mask
)):
81 print (" match", i
, hex(key
), insn
.name
)
82 assert (table_entries
[upper
][lower
] is None,
83 "entry %d %d should be empty "
84 "contains %s conflicting %s" % \
85 (lower
, upper
, str(table_entries
[upper
][lower
]),
87 table_entries
[upper
][lower
] = insn
.name
88 maxnamelen
= max(maxnamelen
, len(insn
.name
))
92 # now got the table: print it out
96 for j
in range(1<<(half
)):
97 hdr
= binmaxed(half
, j
)
98 line
.append(maxme(maxnamelen
, hdr
))
100 table
.append("|" + "|".join(line
) + "|")
101 line
= ["-"*half
] + ["-"*maxnamelen
] * (1<<(half
)) + ["-"*half
]
102 table
.append("|" + "|".join(line
) + "|")
104 for i
in range(1<<(bitlen
-half
)):
105 hdr
= binmaxed(half
, i
)
107 for j
in range(1<<(half
)):
108 line
.append(maxme(maxnamelen
, table_entries
[i
][j
] or " "))
110 table
.append("|" + "|".join(line
) + "|")
112 print ("\n".join(table
))
114 do_table('minor_30.csv', insns
, sections
, divpoint
=2)