| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
from __future__ import print_function |
| 4 |
|
| 5 |
|
| 6 |
def analyze_match_table(path): |
| 7 |
# Extract the instruction table. |
| 8 |
data = open(path).read() |
| 9 |
start = data.index("static const MatchEntry MatchTable") |
| 10 |
end = data.index("\n};\n", start) |
| 11 |
lines = data[start:end].split("\n")[1:] |
| 12 |
|
| 13 |
# Parse the instructions. |
| 14 |
insns = [] |
| 15 |
for ln in lines: |
| 16 |
ln = ln.split("{", 1)[1] |
| 17 |
ln = ln.rsplit("}", 1)[0] |
| 18 |
a, bc = ln.split("{", 1) |
| 19 |
b, c = bc.split("}", 1) |
| 20 |
code, string, converter, _ = [s.strip() for s in a.split(",")] |
| 21 |
items = [s.strip() for s in b.split(",")] |
| 22 |
_, features = [s.strip() for s in c.split(",")] |
| 23 |
assert string[0] == string[-1] == '"' |
| 24 |
string = string[1:-1] |
| 25 |
insns.append((code, string, converter, items, features)) |
| 26 |
|
| 27 |
# For every mnemonic, compute whether or not it can have a carry setting |
| 28 |
# operand and whether or not it can have a predication code. |
| 29 |
mnemonic_flags = {} |
| 30 |
for insn in insns: |
| 31 |
mnemonic = insn[1] |
| 32 |
items = insn[3] |
| 33 |
flags = mnemonic_flags[mnemonic] = mnemonic_flags.get(mnemonic, set()) |
| 34 |
flags.update(items) |
| 35 |
|
| 36 |
mnemonics = set(mnemonic_flags) |
| 37 |
ccout_mnemonics = set(m for m in mnemonics if "MCK_CCOut" in mnemonic_flags[m]) |
| 38 |
condcode_mnemonics = set( |
| 39 |
m for m in mnemonics if "MCK_CondCode" in mnemonic_flags[m] |
| 40 |
) |
| 41 |
noncondcode_mnemonics = mnemonics - condcode_mnemonics |
| 42 |
print(" || ".join('Mnemonic == "%s"' % m for m in ccout_mnemonics)) |
| 43 |
print(" || ".join('Mnemonic == "%s"' % m for m in noncondcode_mnemonics)) |
| 44 |
|
| 45 |
|
| 46 |
def main(): |
| 47 |
import sys |
| 48 |
|
| 49 |
if len(sys.argv) == 1: |
| 50 |
import os |
| 51 |
from lit.Util import capture |
| 52 |
|
| 53 |
llvm_obj_root = capture(["llvm-config", "--obj-root"]) |
| 54 |
file = os.path.join(llvm_obj_root, "lib/Target/ARM/ARMGenAsmMatcher.inc") |
| 55 |
elif len(sys.argv) == 2: |
| 56 |
file = sys.argv[1] |
| 57 |
else: |
| 58 |
raise NotImplementedError |
| 59 |
|
| 60 |
analyze_match_table(file) |
| 61 |
|
| 62 |
|
| 63 |
if __name__ == "__main__": |
| 64 |
main() |