-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadOpcodeTable.py
50 lines (40 loc) · 1.16 KB
/
loadOpcodeTable.py
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
'''
Module to open and create Opcode Table
'''
import os
import re
def loadOpcodeTable(opcodes, fn = 'OpcodeTbl', genOpcodeLst = False):
'''
Read Opcodes Table
'''
with open(fn + '.txt', 'rt') as finp:
opcodeTbl = finp.readlines()
print('len(OpcodeTbl) = %d' % (len(opcodeTbl)))
'''
Create Opcodes Dictionary
'''
maxWidth = 0
for opcode in opcodeTbl:
op = opcode.split()
key = op[0]
if key in opcodes:
print('Error - duplicate key found: %s' % (key))
else:
opcodes[key] = [int(op[1]), int(op[2]), op[3]]
if len(key) > maxWidth:
maxWidth = len(key)
'''
Print Opcode Table Listing
'''
if genOpcodeLst:
with open(fn + '.lst', 'wt') as fout:
print('-'*80, file=fout)
print('\tOpcode Table', file=fout)
print('-'*80, file=fout)
print(file=fout)
for key in opcodes:
print('%-*s' % (maxWidth, key),':',opcodes[key], file=fout)
print(file=fout)
print('-'*80, file=fout)
print(file=fout)
return opcodes