annotate python/ide/disasm.py @ 306:b145f8e6050b

Start on c3 rewrite
author Windel Bouwman
date Mon, 09 Dec 2013 19:00:21 +0100
parents 917eab04b8b7
children dcae6574c974
rev   line source
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
1 from PyQt4.QtCore import *
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
2 from PyQt4.QtGui import *
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 291
diff changeset
3 import binascii
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
4
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
5
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
6 class DisAsmModel(QAbstractTableModel):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
7 def __init__(self):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
8 super().__init__()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
9 self.outs = None
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
10 self.instructions = []
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
11 self.headers = ['Address', 'Bytes', 'Instruction']
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
12 self.txts = []
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
13 self.txts.append(lambda i: '0x{:08x}'.format(i.address))
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 291
diff changeset
14 self.txts.append(lambda i: binascii.hexlify(i.encode()).decode('ascii'))
291
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
15 self.txts.append(lambda i: str(i))
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
16
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
17 def rowCount(self, parent):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
18 return len(self.instructions)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
19
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
20 def columnCount(self, parent):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
21 return len(self.headers)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
22
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
23 def data(self, index, role):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
24 if not index.isValid():
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
25 return
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
26 row, col = index.row(), index.column()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
27 if role == Qt.DisplayRole:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
28 i = self.instructions[row]
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
29 return self.txts[col](i)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
30
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
31 def headerData(self, section, orientation, role):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
32 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
33 return self.headers[section]
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
34
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
35 def setInstructions(self, ins):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
36 self.instructions = ins
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
37 self.modelReset.emit()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
38
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
39
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
40 class Disassembly(QTableView):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
41 def __init__(self):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
42 super().__init__()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
43 self.dm = DisAsmModel()
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
44 self.setModel(self.dm)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
45
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
46 def showPos(self, p):
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
47 for i in self.dm.instructions:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
48 if i.address == p:
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
49 row = self.dm.instructions.index(i)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
50 self.selectRow(row)
b07d28a5ca56 Added some forgotten files
Windel Bouwman
parents:
diff changeset
51