Debian Codegraph @

suite/synctools/strinforeduce/instrinfo2.py

raw symbols SCIP
1 #!/usr/bin/python
2 # convert LLVM GenInstrInfo.inc for Capstone disassembler.
3 # by Nguyen Anh Quynh, 2019
4
5 import sys
6
7 if len(sys.argv) == 1:
8 print("Syntax: %s <GenInstrInfo.inc>" %sys.argv[0])
9 sys.exit(1)
10
11
12 count = 0
13 last_line = None
14
15 f = open(sys.argv[1])
16 lines = f.readlines()
17 f.close()
18
19 # 1st enum is register enum
20 for line in lines:
21 line = line.rstrip()
22
23 # skip all MCPhysReg line
24 if 'static const MCPhysReg ' in line:
25 continue
26
27 # skip all MCOperandInfo line
28 if 'static const MCOperandInfo ' in line:
29 continue
30
31 # skip InitX86MCInstrInfo()
32 if 'static inline void InitX86MCInstrInfo' in line:
33 continue
34
35 if 'II->InitMCInstrInfo' in line:
36 last_line = line
37 continue
38
39 # skip the next line after II->InitMCInstrInfo
40 if last_line:
41 last_line = None
42 continue
43
44
45 if 'extern const MCInstrDesc ' in line:
46 count += 1
47 continue
48
49 if count == 1:
50 if line == '};':
51 # done with first enum
52 count += 1
53 continue
54 else:
55 print(line)