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
.section
.bitsel
)]
52 opcode
= FieldsOpcode(fields
)
53 if not isinstance(opcode
, list):
56 print ("op", insn
.name
, op
)
57 opcode_per_insn
[insn
.name
] = opcode
60 for i
in range(1<<bitlen
):
61 # calculate row, column
63 upper
= (i
>>half
) & uppermask
64 print (i
, bin(lower
), bin(upper
))
65 if upper
not in table_entries
:
66 table_entries
[upper
] = {}
67 table_entries
[upper
][lower
] = None
69 key
= i
<< (31-end
) # MSB0-order shift up by *end*
70 print ("search", i
, hex(key
))
73 opcode
= opcode_per_insn
[insn
.name
]
75 #print (" search", i, hex(key), insn.name,
76 # hex(op.value), hex(op.mask))
77 if ((op
.value
& op
.mask
) == (key
& op
.mask
)):
78 print (" match", i
, hex(key
), insn
.name
)
79 assert (table_entries
[upper
][lower
] is None,
80 "entry %d %d should be empty "
81 "contains %s conflicting %s" % \
82 (lower
, upper
, str(table_entries
[upper
][lower
]),
84 table_entries
[upper
][lower
] = insn
.name
85 maxnamelen
= max(maxnamelen
, len(insn
.name
))
89 # now got the table: print it out
93 for j
in range(1<<(half
)):
94 hdr
= binmaxed(half
, j
)
95 line
.append(maxme(maxnamelen
, hdr
))
97 table
.append("|" + "|".join(line
) + "|")
98 line
= ["-"*half
] + ["-"*maxnamelen
] * (1<<(bitlen
-half
)) + ["-"*half
]
99 table
.append("|" + "|".join(line
) + "|")
101 for i
in range(1<<(bitlen
-half
)):
102 hdr
= binmaxed(half
, i
)
104 for j
in range(1<<(half
)):
105 line
.append(maxme(maxnamelen
, table_entries
[i
][j
] or " "))
107 table
.append("|" + "|".join(line
) + "|")
109 print ("\n".join(table
))
111 do_table('minor_30.csv', insns
, sections
, divpoint
=2)