3 from __future__
import print_function
5 def analyze_match_table(path
):
6 # Extract the instruction table.
7 data
= open(path
).read()
8 start
= data
.index("static const MatchEntry MatchTable")
9 end
= data
.index("\n};\n", start
)
10 lines
= data
[start
:end
].split("\n")[1:]
12 # Parse the instructions.
15 ln
= ln
.split("{", 1)[1]
16 ln
= ln
.rsplit("}", 1)[0]
17 a
,bc
= ln
.split("{", 1)
18 b
,c
= bc
.split("}", 1)
19 code
, string
, converter
, _
= [s
.strip()
20 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
38 if 'MCK_CCOut' in mnemonic_flags
[m
])
39 condcode_mnemonics
= set(m
for m
in mnemonics
40 if 'MCK_CondCode' in mnemonic_flags
[m
])
41 noncondcode_mnemonics
= mnemonics
- condcode_mnemonics
42 print(' || '.join('Mnemonic == "%s"' % m
43 for m
in ccout_mnemonics
))
44 print(' || '.join('Mnemonic == "%s"' % m
45 for m
in noncondcode_mnemonics
))
49 if len(sys
.argv
) == 1:
51 from lit
.Util
import capture
52 llvm_obj_root
= capture(["llvm-config", "--obj-root"])
53 file = os
.path
.join(llvm_obj_root
,
54 "lib/Target/ARM/ARMGenAsmMatcher.inc")
55 elif len(sys
.argv
) == 2:
58 raise NotImplementedError
60 analyze_match_table(file)
62 if __name__
== '__main__':