3 from __future__
import print_function
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:]
13 # Parse the instructions.
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] == '"'
25 insns
.append((code
, string
, converter
, items
, features
))
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.
33 flags
= mnemonic_flags
[mnemonic
] = mnemonic_flags
.get(mnemonic
, set())
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
]
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
))
49 if len(sys
.argv
) == 1:
51 from lit
.Util
import capture
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:
58 raise NotImplementedError
60 analyze_match_table(file)
63 if __name__
== "__main__":