annotate python/ide/ide.py @ 375:19eacf4f7270

Started on memory manager
author Windel Bouwman
date Sun, 23 Mar 2014 15:44:06 +0100
parents 11c5a8a70c02
children
rev   line source
99
windel
parents: 98
diff changeset
1 #!/usr/bin/python
windel
parents: 98
diff changeset
2
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
3 import sys
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
4 import os
255
7416c923a02a Added more logging
Windel Bouwman
parents: 254
diff changeset
5 import logging
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 282
diff changeset
6 import traceback
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
7 import io
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
8
343
11c5a8a70c02 Fix ide
Windel Bouwman
parents: 333
diff changeset
9 from qtwrapper import QtGui, QtCore, QtWidgets, pyqtSignal, get_icon
11c5a8a70c02 Fix ide
Windel Bouwman
parents: 333
diff changeset
10 from qtwrapper import abspath, Qt
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
11
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
12 # Compiler imports:
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
13 p = os.path.join(os.path.dirname(__file__), '..')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
14 sys.path.insert(0, p)
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
15 sys.path.insert(0, os.path.join(p, 'utils'))
343
11c5a8a70c02 Fix ide
Windel Bouwman
parents: 333
diff changeset
16
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 102
diff changeset
17 import ppci
100
fe145e42259d Fixes after movage
windel
parents: 99
diff changeset
18 from astviewer import AstViewer
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
19 from codeedit import CodeEdit
281
4496cae24d7f Improved logview
Windel Bouwman
parents: 279
diff changeset
20 from logview import LogView as BuildOutput
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
21 from disasm import Disassembly
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
22 stutil = __import__('st-util')
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
23 import zcc
343
11c5a8a70c02 Fix ide
Windel Bouwman
parents: 333
diff changeset
24 from ppci.outstream import BinaryOutputStream
11c5a8a70c02 Fix ide
Windel Bouwman
parents: 333
diff changeset
25 from ppci.target.target_list import thumb_target
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
26
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
27
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
28 def handle_exception(tp, v, tb):
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
29 logging.critical(str(v))
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
30 tb = traceback.format_tb(tb)
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
31 for i in tb:
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
32 logging.critical(i.strip())
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
33
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
34 # sys.excepthook = handle_exception
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
35
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
36 class BuildErrors(QtWidgets.QTreeView):
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
37 sigErrorSelected = pyqtSignal(object)
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
38
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
39 def __init__(self, parent=None):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
40 super(BuildErrors, self).__init__(parent)
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
41 model = QtGui.QStandardItemModel()
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
42 self.setModel(model)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
43 self.clicked.connect(self.itemSelected)
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
44 self.errorIcon = get_icon('error.png')
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
45 self.model = QtGui.QStandardItemModel()
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
46 self.model.setHorizontalHeaderLabels(['Message', 'Row', 'Column'])
281
4496cae24d7f Improved logview
Windel Bouwman
parents: 279
diff changeset
47 self.header().setStretchLastSection(True)
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
48 self.setModel(self.model)
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
49
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
50 def setErrorList(self, errorlist):
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
51 c = self.model.rowCount()
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
52 self.model.removeRows(0, c)
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
53 for e in errorlist:
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
54 item = QtGui.QStandardItem(self.errorIcon, str(e.msg))
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
55 item.setData(e)
277
046017431c6a Started register allocator
Windel Bouwman
parents: 259
diff changeset
56 row = str(e.loc.row) if e.loc else ''
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
57 irow = QtGui.QStandardItem(row)
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
58 irow.setData(e)
277
046017431c6a Started register allocator
Windel Bouwman
parents: 259
diff changeset
59 col = str(e.loc.col) if e.loc else ''
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
60 icol = QtGui.QStandardItem(col)
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
61 icol.setData(e)
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
62 self.model.appendRow([item, irow, icol])
281
4496cae24d7f Improved logview
Windel Bouwman
parents: 279
diff changeset
63 for i in range(3):
4496cae24d7f Improved logview
Windel Bouwman
parents: 279
diff changeset
64 self.resizeColumnToContents(i)
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
65
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
66 def itemSelected(self, index):
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
67 if not index.isValid():
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
68 return
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
69 item = self.model.itemFromIndex(index)
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
70 err = item.data()
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
71 self.sigErrorSelected.emit(err)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
72
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
73
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
74
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
75 class AboutDialog(QtWidgets.QDialog):
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
76 def __init__(self, parent=None):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
77 super(AboutDialog, self).__init__(parent)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
78 self.setWindowTitle('About')
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
79 l = QtWidgets.QVBoxLayout(self)
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
80 txt = QtWidgets.QTextEdit(self)
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
81 txt.setReadOnly(True)
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
82 with open(abspath(os.path.join('..', '..', 'readme.rst')), 'r') as f:
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
83 aboutText = f.read()
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
84 txt.append(aboutText)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
85 l.addWidget(txt)
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
86 but = QtWidgets.QPushButton('OK')
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
87 but.setDefault(True)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
88 but.clicked.connect(self.close)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
89 l.addWidget(but)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
90
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
91
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
92 class Ide(QtWidgets.QMainWindow):
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
93 def __init__(self, parent=None):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
94 super(Ide, self).__init__(parent)
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
95 self.to_open_files = []
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
96 self.logger = logging.getLogger('ide')
255
7416c923a02a Added more logging
Windel Bouwman
parents: 254
diff changeset
97
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
98 self.setWindowTitle('LCFOS IDE')
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
99 icon = QtGui.QIcon(get_icon('logo.png'))
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
100 self.setWindowIcon(icon)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
101
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
102 # Create menus:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
103 mb = self.menuBar()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
104 self.fileMenu = mb.addMenu('File')
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
105 self.viewMenu = mb.addMenu('View')
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
106 self.helpMenu = mb.addMenu('Help')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
107
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
108 # Create mdi area:
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
109 self.mdiArea = QtWidgets.QMdiArea()
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
110 self.mdiArea.setViewMode(QtWidgets.QMdiArea.TabbedView)
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
111 self.mdiArea.setTabsClosable(True)
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
112 self.mdiArea.setTabsMovable(True)
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
113 self.setCentralWidget(self.mdiArea)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
114
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
115 # Create components:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
116 def addComponent(name, widget):
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
117 dw = QtWidgets.QDockWidget(name)
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
118 dw.setWidget(widget)
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
119 dw.setObjectName(name)
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
120 self.addDockWidget(Qt.RightDockWidgetArea, dw)
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
121 self.viewMenu.addAction(dw.toggleViewAction())
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
122 return widget
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
123
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
124 self.buildOutput = addComponent('Build output', BuildOutput())
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
125 self.astViewer = addComponent('AST viewer', AstViewer())
255
7416c923a02a Added more logging
Windel Bouwman
parents: 254
diff changeset
126 self.astViewer.sigNodeSelected.connect(lambda node: self.showLoc(node.loc))
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
127 self.builderrors = addComponent('Build errors', BuildErrors())
255
7416c923a02a Added more logging
Windel Bouwman
parents: 254
diff changeset
128 self.builderrors.sigErrorSelected.connect(lambda err: self.showLoc(err.loc))
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
129 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer())
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
130 self.regview = addComponent('Registers', stutil.RegisterView())
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
131 self.memview = addComponent('Memory', stutil.MemoryView())
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
132 self.disasm = addComponent('Disasm', Disassembly())
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
133 self.ctrlToolbar = stutil.DebugToolbar()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
134 self.addToolBar(self.ctrlToolbar)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
135 self.ctrlToolbar.setObjectName('debugToolbar')
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
136 self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
137 self.ctrlToolbar.statusChange.connect(self.memview.refresh)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
138 self.devxplr.deviceSelected.connect(self.memview.setDevice)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
139 self.devxplr.deviceSelected.connect(self.ctrlToolbar.setDevice)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
140 self.ctrlToolbar.statusChange.connect(self.regview.refresh)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
141 self.ctrlToolbar.codePosition.connect(self.pointCode)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
142
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
143 # About dialog:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
144 self.aboutDialog = AboutDialog()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
145 self.aboutDialog.setWindowIcon(icon)
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
146
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
147 # Create actions:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
148 def addMenuEntry(name, menu, callback, shortcut=None):
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
149 a = QtWidgets.QAction(name, self)
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
150 menu.addAction(a)
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
151 a.triggered.connect(callback)
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
152 if shortcut:
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
153 a.setShortcut(QtGui.QKeySequence(shortcut))
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
154
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
155 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QtGui.QKeySequence.New)
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
156 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QtGui.QKeySequence.Open)
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
157 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QtGui.QKeySequence.Save)
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
158 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut="F7")
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
159 addMenuEntry("Build and flash", self.fileMenu, self.buildFileAndFlash, shortcut="F8")
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
160
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
161 self.helpAction = QtWidgets.QAction('Help', self)
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
162 self.helpAction.setShortcut(QtGui.QKeySequence('F1'))
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
163 self.helpMenu.addAction(self.helpAction)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
164 addMenuEntry('About', self.helpMenu, self.aboutDialog.open)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
165
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
166 addMenuEntry('Cascade windows', self.viewMenu, self.mdiArea.cascadeSubWindows)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
167 addMenuEntry('Tile windows', self.viewMenu, self.mdiArea.tileSubWindows)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
168 sb = self.statusBar()
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
169
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
170 # Load settings:
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
171 self.settings = QtCore.QSettings('windelsoft', 'lcfoside')
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
172 self.loadSettings()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
173 self.diag = ppci.DiagnosticsManager()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
174
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
175 # File handling:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
176 def newFile(self):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
177 self.newCodeEdit()
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
178
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
179 def openFile(self):
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
180 filename = QtWidgets.QFileDialog.getOpenFileName(self, "Open C3 file...", "*.c3",
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
181 "C3 source files (*.c3)")
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
182 if filename:
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
183 self.loadFile(filename[0])
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
184
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
185 def saveFile(self):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
186 ac = self.activeMdiChild()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
187 if ac:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
188 ac.save()
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
189
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
190 def loadFile(self, filename):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
191 ce = self.newCodeEdit()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
192 try:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
193 with open(filename) as f:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
194 ce.Source = f.read()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
195 ce.FileName = filename
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
196 except Exception as e:
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
197 print('exception opening file:', e)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
198
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
199 # MDI:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
200 def newCodeEdit(self):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
201 ce = CodeEdit()
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
202 ce.textChanged.connect(self.parseFile)
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
203 w = self.mdiArea.addSubWindow(ce)
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
204 self.mdiArea.setActiveSubWindow(w)
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
205 ce.showMaximized()
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
206 return ce
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
207
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
208 def activeMdiChild(self):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
209 aw = self.mdiArea.activeSubWindow()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
210 if aw:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
211 return aw.widget()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
212
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
213 def findMdiChild(self, filename):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
214 for wid in self.allChildren():
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
215 if wid.filename == filename:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
216 return wid
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
217
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
218 def allChildren(self):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
219 return [w.widget() for w in self.mdiArea.subWindowList()]
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
220
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
221 # Settings:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
222 def loadSettings(self):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
223 if self.settings.contains('mainwindowstate'):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
224 self.restoreState(self.settings.value('mainwindowstate'))
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
225 if self.settings.contains('mainwindowgeometry'):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
226 self.restoreGeometry(self.settings.value('mainwindowgeometry'))
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
227 if self.settings.contains('lastfiles'):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
228 lfs = self.settings.value('lastfiles')
277
046017431c6a Started register allocator
Windel Bouwman
parents: 259
diff changeset
229 if lfs:
046017431c6a Started register allocator
Windel Bouwman
parents: 259
diff changeset
230 self.to_open_files.extend(lfs)
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
231
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
232 def showEvent(self, ev):
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
233 super().showEvent(ev)
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
234 while self.to_open_files:
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
235 fn = self.to_open_files.pop(0)
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
236 self.loadFile(fn)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
237
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
238 def closeEvent(self, ev):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
239 self.settings.setValue('mainwindowstate', self.saveState())
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
240 self.settings.setValue('mainwindowgeometry', self.saveGeometry())
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
241 ac = self.activeMdiChild()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
242 lfs = [ce.FileName for ce in self.allChildren() if ce.FileName]
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
243 self.settings.setValue('lastfiles', lfs)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
244 ev.accept()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
245
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
246 # Error handling:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
247 def nodeSelected(self, node):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
248 self.showLoc(node.loc)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
249
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
250 def showLoc(self, loc):
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
251 ce = self.activeMdiChild()
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
252 if not ce:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
253 return
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
254 if loc:
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
255 ce.setRowCol(loc.row, loc.col)
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
256 ce.setFocus()
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
257
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
258 def pointCode(self, p):
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
259 # Lookup pc in debug infos:
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
260 loc = None
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
261 print(p)
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
262 self.disasm.showPos(p)
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
263 if hasattr(self, 'debugInfo'):
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
264 for di in self.debugInfo:
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
265 if di.address > p:
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
266 loc = di.info
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
267 break
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
268 if loc:
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
269 ce = self.activeMdiChild()
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
270 if ce:
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
271 ce.ic.arrow = loc
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
272 self.showLoc(loc)
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
273
248
b10d46e5c8dd ide refactor
Windel Bouwman
parents: 247
diff changeset
274 # Build recepy:
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
275 def parseFile(self):
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
276 self.logger.info('Parsing!')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
277
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
278 def doBuild(self):
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
279 ce = self.activeMdiChild()
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
280 if not ce:
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
281 return
279
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents: 277
diff changeset
282 fn = ce.FileName
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
283 self.diag.clear()
343
11c5a8a70c02 Fix ide
Windel Bouwman
parents: 333
diff changeset
284 outs = BinaryOutputStream()
289
bd2593de3ff8 Semifix burn2
Windel Bouwman
parents: 288
diff changeset
285 imps = [open(ce.FileName, 'r') for ce in self.allChildren() if ce.FileName and ce.FileName != fn]
343
11c5a8a70c02 Fix ide
Windel Bouwman
parents: 333
diff changeset
286 if not zcc.zcc([open(fn, 'r')], imps, thumb_target, outs, self.diag):
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
287 # Set errors:
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
288 self.builderrors.setErrorList(self.diag.diags)
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
289 ce.setErrors(self.diag.diags)
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
290 return
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
291 return outs
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
292
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
293 def buildFile(self):
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
294 self.doBuild()
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
295
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
296 def buildFileAndFlash(self):
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
297 outs = self.doBuild()
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
298 if not outs:
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
299 return
917eab04b8b7 Added disasm
Windel Bouwman
parents: 292
diff changeset
300
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
301 code_s = outs.getSection('code')
282
c137f1fe3e65 Add codeship hook
Windel Bouwman
parents: 281
diff changeset
302 self.disasm.dm.setInstructions(code_s.instructions)
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
303 self.debugInfo = code_s.debugInfos()
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 249
diff changeset
304 if self.ctrlToolbar.device:
255
7416c923a02a Added more logging
Windel Bouwman
parents: 254
diff changeset
305 logging.info('Flashing stm32f4 discovery')
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 249
diff changeset
306 bts = code_s.to_bytes()
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 249
diff changeset
307 self.ctrlToolbar.device.writeFlash(0x08000000, bts)
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 249
diff changeset
308 stl = self.ctrlToolbar.device.iface
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 249
diff changeset
309 stl.reset()
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 249
diff changeset
310 stl.halt()
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
311 stl.run()
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
312 logging.info('Done!')
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
313 else:
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
314 self.logger.warning('Not connected to device, skipping flash')
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 248
diff changeset
315
256
225f444019b1 Added build and flash menu option
Windel Bouwman
parents: 255
diff changeset
316
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
317 if __name__ == '__main__':
333
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
318 logging.basicConfig(format=ppci.logformat, level=logging.DEBUG)
dcae6574c974 Increment to qt5
Windel Bouwman
parents: 311
diff changeset
319 app = QtWidgets.QApplication(sys.argv)
240
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
320 ide = Ide()
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
321 ide.show()
259
ac603eb66b63 Added function call
Windel Bouwman
parents: 258
diff changeset
322 ide.logger.info('IDE started')
240
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
323 app.exec_()