aboutsummaryrefslogtreecommitdiffstats
path: root/capstone/suite/synctools/strinforeduce/instrinfo2.py
blob: 6c52bdcd77531fa04ef47964c1e2b798c98027a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
# convert LLVM GenInstrInfo.inc for Capstone disassembler.
# by Nguyen Anh Quynh, 2019

import sys

if len(sys.argv) == 1:
    print("Syntax: %s <GenInstrInfo.inc>" %sys.argv[0])
    sys.exit(1)


count = 0
last_line = None

f = open(sys.argv[1])
lines = f.readlines()
f.close()

# 1st enum is register enum
for line in lines:
    line = line.rstrip()

    # skip all MCPhysReg line
    if 'static const MCPhysReg ' in line:
        continue

    # skip all MCOperandInfo line
    if 'static const MCOperandInfo ' in line:
        continue

    # skip InitX86MCInstrInfo()
    if 'static inline void InitX86MCInstrInfo' in line:
        continue

    if 'II->InitMCInstrInfo' in line:
        last_line = line
        continue

    # skip the next line after II->InitMCInstrInfo
    if last_line:
        last_line = None
        continue
            

    if 'extern const MCInstrDesc ' in line:
        count += 1
        continue

    if count == 1:
        if line == '};':
            # done with first enum
            count += 1
            continue
    else:
        print(line)