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:]
10 # Parse the instructions.
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] == '"'
23 insns
.append((code
,string
,converter
,items
,features
))
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.
31 flags
= mnemonic_flags
[mnemonic
] = mnemonic_flags
.get(mnemonic
, set())
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
)
47 if len(sys
.argv
) == 1:
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:
56 raise NotImplementedError
58 analyze_match_table(file)
60 if __name__
== '__main__':