Mercurial > lcfOS
comparison python/ide.py @ 282:c137f1fe3e65
Add codeship hook
author | Windel Bouwman |
---|---|
date | Fri, 15 Nov 2013 09:32:37 +0100 |
parents | 4496cae24d7f |
children | 1c7c1e619be8 |
comparison
equal
deleted
inserted
replaced
281:4496cae24d7f | 282:c137f1fe3e65 |
---|---|
14 from logview import LogView as BuildOutput | 14 from logview import LogView as BuildOutput |
15 stutil = __import__('st-util') | 15 stutil = __import__('st-util') |
16 import c3 | 16 import c3 |
17 import zcc | 17 import zcc |
18 import outstream | 18 import outstream |
19 | 19 import traceback |
20 | |
21 | |
22 def handle_exception(tp, v, tb): | |
23 logging.critical(str(v)) | |
24 tb = traceback.format_tb(tb) | |
25 for i in tb: | |
26 logging.critical(i.strip()) | |
27 | |
28 sys.excepthook = handle_exception | |
20 | 29 |
21 class BuildErrors(QTreeView): | 30 class BuildErrors(QTreeView): |
22 sigErrorSelected = pyqtSignal(object) | 31 sigErrorSelected = pyqtSignal(object) |
23 | 32 |
24 def __init__(self, parent=None): | 33 def __init__(self, parent=None): |
54 item = self.model.itemFromIndex(index) | 63 item = self.model.itemFromIndex(index) |
55 err = item.data() | 64 err = item.data() |
56 self.sigErrorSelected.emit(err) | 65 self.sigErrorSelected.emit(err) |
57 | 66 |
58 | 67 |
68 class DisAsmModel(QAbstractTableModel): | |
69 def __init__(self): | |
70 super().__init__() | |
71 self.outs = None | |
72 self.instructions = [] | |
73 self.headers = ['Address', 'Bytes', 'Instruction'] | |
74 self.txts = [] | |
75 self.txts.append(lambda i: '0x{:08x}'.format(i.address)) | |
76 self.txts.append(lambda i: str(i.encode())) | |
77 self.txts.append(lambda i: str(i)) | |
78 | |
79 def rowCount(self, parent): | |
80 return len(self.instructions) | |
81 | |
82 def columnCount(self, parent): | |
83 return len(self.headers) | |
84 | |
85 def data(self, index, role): | |
86 if not index.isValid(): | |
87 return | |
88 row, col = index.row(), index.column() | |
89 if role == Qt.DisplayRole: | |
90 i = self.instructions[row] | |
91 return self.txts[col](i) | |
92 | |
93 def headerData(self, section, orientation, role): | |
94 if orientation == Qt.Horizontal and role == Qt.DisplayRole: | |
95 return self.headers[section] | |
96 | |
97 def setInstructions(self, ins): | |
98 self.instructions = ins | |
99 self.modelReset.emit() | |
100 | |
101 | |
102 class Disassembly(QTableView): | |
103 def __init__(self): | |
104 super().__init__() | |
105 self.dm = DisAsmModel() | |
106 self.setModel(self.dm) | |
107 | |
108 def showPos(self, p): | |
109 for i in self.dm.instructions: | |
110 if i.address == p: | |
111 row = self.dm.instructions.index(i) | |
112 self.selectRow(row) | |
113 | |
59 class AboutDialog(QDialog): | 114 class AboutDialog(QDialog): |
60 def __init__(self, parent=None): | 115 def __init__(self, parent=None): |
61 super(AboutDialog, self).__init__(parent) | 116 super(AboutDialog, self).__init__(parent) |
62 self.setWindowTitle('About') | 117 self.setWindowTitle('About') |
63 l = QVBoxLayout(self) | 118 l = QVBoxLayout(self) |
64 txt = QTextEdit(self) | 119 txt = QTextEdit(self) |
65 txt.setReadOnly(True) | 120 txt.setReadOnly(True) |
66 aboutText = """<h1>lcfOS IDE</h1> | 121 with open(os.path.join('..', 'readme.rst'), 'r') as f: |
67 <p>An all-in-one IDE for OS development.</p> | 122 aboutText = f.read() |
68 <p>https://www.assembla.com/spaces/lcfOS/wiki</p> | |
69 <p>Author: Windel Bouwman</p> | |
70 """ | |
71 txt.append(aboutText) | 123 txt.append(aboutText) |
72 l.addWidget(txt) | 124 l.addWidget(txt) |
73 but = QPushButton('OK') | 125 but = QPushButton('OK') |
74 but.setDefault(True) | 126 but.setDefault(True) |
75 but.clicked.connect(self.close) | 127 but.clicked.connect(self.close) |
114 self.builderrors = addComponent('Build errors', BuildErrors()) | 166 self.builderrors = addComponent('Build errors', BuildErrors()) |
115 self.builderrors.sigErrorSelected.connect(lambda err: self.showLoc(err.loc)) | 167 self.builderrors.sigErrorSelected.connect(lambda err: self.showLoc(err.loc)) |
116 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer()) | 168 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer()) |
117 self.regview = addComponent('Registers', stutil.RegisterView()) | 169 self.regview = addComponent('Registers', stutil.RegisterView()) |
118 self.memview = addComponent('Memory', stutil.MemoryView()) | 170 self.memview = addComponent('Memory', stutil.MemoryView()) |
171 self.disasm = addComponent('Disasm', Disassembly()) | |
119 self.ctrlToolbar = stutil.DebugToolbar() | 172 self.ctrlToolbar = stutil.DebugToolbar() |
120 self.addToolBar(self.ctrlToolbar) | 173 self.addToolBar(self.ctrlToolbar) |
121 self.ctrlToolbar.setObjectName('debugToolbar') | 174 self.ctrlToolbar.setObjectName('debugToolbar') |
122 self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice) | 175 self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice) |
123 self.ctrlToolbar.statusChange.connect(self.memview.refresh) | 176 self.ctrlToolbar.statusChange.connect(self.memview.refresh) |
239 if not ce: | 292 if not ce: |
240 return | 293 return |
241 if loc: | 294 if loc: |
242 ce.setRowCol(loc.row, loc.col) | 295 ce.setRowCol(loc.row, loc.col) |
243 ce.setFocus() | 296 ce.setFocus() |
244 else: | |
245 ce.clearErrors() | |
246 | 297 |
247 def pointCode(self, p): | 298 def pointCode(self, p): |
248 # Lookup pc in debug infos: | 299 # Lookup pc in debug infos: |
249 loc = None | 300 loc = None |
301 print(p) | |
302 self.disasm.showPos(p) | |
250 if hasattr(self, 'debugInfo'): | 303 if hasattr(self, 'debugInfo'): |
251 for di in self.debugInfo: | 304 for di in self.debugInfo: |
252 if di.address > p: | 305 if di.address > p: |
253 loc = di.info | 306 loc = di.info |
254 break | 307 break |
258 ce.ic.arrow = loc | 311 ce.ic.arrow = loc |
259 self.showLoc(loc) | 312 self.showLoc(loc) |
260 | 313 |
261 # Build recepy: | 314 # Build recepy: |
262 def parseFile(self): | 315 def parseFile(self): |
316 self.logger.info('Parsing!') | |
263 ce = self.activeMdiChild() | 317 ce = self.activeMdiChild() |
264 if not ce: | 318 if not ce: |
265 return | 319 return |
266 self.diag.clear() | 320 self.diag.clear() |
267 pkg = self.c3front.parse(ce.Source) | 321 pkg = self.c3front.parse(ce.Source) |
268 | 322 |
269 # Set errors: | 323 # Set errors: |
270 self.builderrors.setErrorList(self.diag.diags) | 324 self.builderrors.setErrorList(self.diag.diags) |
271 ce.setErrors(self.diag.diags) | 325 ce.setErrors(self.diag.diags) |
272 self.astViewer.setAst(pkg) | 326 self.astViewer.setAst(pkg) |
273 c3.AstPrinter().printAst(pkg) | 327 if pkg: |
328 c3.AstPrinter().printAst(pkg) | |
274 self.logger.info('Done!') | 329 self.logger.info('Done!') |
275 | 330 |
276 def buildFile(self): | 331 def buildFile(self): |
277 ce = self.activeMdiChild() | 332 ce = self.activeMdiChild() |
278 if not ce: | 333 if not ce: |
301 ce.setErrors(self.diag.diags) | 356 ce.setErrors(self.diag.diags) |
302 return | 357 return |
303 | 358 |
304 outs.dump() | 359 outs.dump() |
305 code_s = outs.getSection('code') | 360 code_s = outs.getSection('code') |
361 self.disasm.dm.setInstructions(code_s.instructions) | |
306 self.debugInfo = code_s.debugInfos() | 362 self.debugInfo = code_s.debugInfos() |
307 if self.ctrlToolbar.device: | 363 if self.ctrlToolbar.device: |
308 logging.info('Flashing stm32f4 discovery') | 364 logging.info('Flashing stm32f4 discovery') |
309 bts = code_s.to_bytes() | 365 bts = code_s.to_bytes() |
310 self.ctrlToolbar.device.writeFlash(0x08000000, bts) | 366 self.ctrlToolbar.device.writeFlash(0x08000000, bts) |