Debian Codegraph @

suite/synctools/mapping_reg.py

raw symbols SCIP
1 #!/usr/bin/python
2 # print out all registers from LLVM GenRegisterInfo.inc for Capstone disassembler.
3 # NOTE: the list then must be filtered, manually.
4 # by Nguyen Anh Quynh, 2019
5
6 import sys
7
8 if len(sys.argv) == 1:
9 print("Syntax: %s <GenRegisterInfo.inc> <architecture>" %sys.argv[0])
10 sys.exit(1)
11
12 f = open(sys.argv[1])
13 lines = f.readlines()
14 f.close()
15
16 arch = sys.argv[2].upper()
17
18 enum_count = 0
19
20 print("""/* Capstone Disassembly Engine, http://www.capstone-engine.org */
21 /* This is auto-gen data for Capstone disassembly engine (www.capstone-engine.org) */
22 /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */
23 """)
24
25 # 1st enum is register enum
26 for line in lines:
27 line = line.rstrip()
28
29 if len(line.strip()) == 0:
30 continue
31
32 if line.strip() == 'enum {':
33 enum_count += 1
34 continue
35
36 if enum_count == 1:
37 if line == '};':
38 # done with first enum
39 break
40 else:
41 # enum items
42 if 'NoRegister' in line or 'TARGET_REGS' in line:
43 continue
44 reg = line.strip().split('=')[0].strip()
45 if reg.startswith('H') or reg.endswith('PH') or reg.endswith('IH') or reg.endswith('WH'):
46 print("{ %s_%s, 0 }," %(arch, reg))
47 elif 'K' in reg or 'BND' in reg:
48 print("{ %s_%s, 0 }," %(arch, reg))
49 elif reg in ('DF', 'SSP', 'R8BH', 'R9BH', 'R10BH', 'R11BH', 'R12BH', 'R13BH', 'R14BH', 'R15BH'):
50 print("{ %s_%s, 0 }," %(arch, reg))
51 else:
52 print("{ %s_%s, %s_REG_%s }," %(arch, reg, arch, reg))
53