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