diff python/ide/disasm.py @ 295:917eab04b8b7

Added disasm
author Windel Bouwman
date Thu, 28 Nov 2013 21:10:32 +0100
parents python/disasm.py@b07d28a5ca56
children dcae6574c974
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/ide/disasm.py	Thu Nov 28 21:10:32 2013 +0100
@@ -0,0 +1,51 @@
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+import binascii
+
+
+class DisAsmModel(QAbstractTableModel):
+    def __init__(self):
+        super().__init__()
+        self.outs = None
+        self.instructions = []
+        self.headers = ['Address', 'Bytes', 'Instruction']
+        self.txts = []
+        self.txts.append(lambda i: '0x{:08x}'.format(i.address))
+        self.txts.append(lambda i: binascii.hexlify(i.encode()).decode('ascii'))
+        self.txts.append(lambda i: str(i))
+
+    def rowCount(self, parent):
+        return len(self.instructions)
+        
+    def columnCount(self, parent):
+        return len(self.headers)
+
+    def data(self, index, role):
+        if not index.isValid():
+            return
+        row, col = index.row(), index.column()
+        if role == Qt.DisplayRole:
+            i = self.instructions[row]
+            return self.txts[col](i)
+
+    def headerData(self, section, orientation, role):
+        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
+            return self.headers[section]
+            
+    def setInstructions(self, ins):
+        self.instructions = ins
+        self.modelReset.emit()
+    
+
+class Disassembly(QTableView):
+    def __init__(self):
+        super().__init__()
+        self.dm = DisAsmModel()
+        self.setModel(self.dm)
+
+    def showPos(self, p):
+        for i in self.dm.instructions:
+            if i.address == p:
+                row = self.dm.instructions.index(i)
+                self.selectRow(row)
+