diff python/ide.py @ 249:e41e4109addd

Added current position arrow
author Windel Bouwman
date Fri, 26 Jul 2013 20:26:05 +0200
parents b10d46e5c8dd
children f5fba5b554d7
line wrap: on
line diff
--- a/python/ide.py	Fri Jul 26 16:46:02 2013 +0200
+++ b/python/ide.py	Fri Jul 26 20:26:05 2013 +0200
@@ -12,6 +12,8 @@
 from codeedit import CodeEdit
 stutil = __import__('st-util')
 import c3
+import zcc
+import outstream
 
 
 class BuildOutput(QTextEdit):
@@ -91,6 +93,7 @@
         # Create mdi area:
         self.mdiArea = QMdiArea()
         self.mdiArea.setViewMode(QMdiArea.TabbedView)
+        self.mdiArea.setTabsClosable(True)
         self.setCentralWidget(self.mdiArea)
 
         # Create components:
@@ -178,9 +181,10 @@
     # MDI:
     def newCodeEdit(self):
         ce = CodeEdit()
-        ce.textChanged.connect(self.buildFile)
+        ce.textChanged.connect(self.parseFile)
         w = self.mdiArea.addSubWindow(ce)
-        ce.show()
+        self.mdiArea.setActiveSubWindow(w)
+        ce.showMaximized()
         return ce
 
     def activeMdiChild(self):
@@ -233,16 +237,26 @@
             ce.clearErrors()
 
     def pointCode(self, p):
-        print('PC', p)
+        # Lookup pc in debug infos:
+        loc = None
+        if hasattr(self, 'debugInfo'):
+            for di in self.debugInfo:
+                if di.address > p:
+                    loc = di.info
+                    break
+        if loc:
+            ce = self.activeMdiChild()
+            if ce:
+                ce.ic.arrow = loc
+            self.showLoc(loc)
 
     # Build recepy:
-    def buildFile(self):
+    def parseFile(self):
         ce = self.activeMdiChild()
         if not ce:
             return
-        self.buildOutput.clear()
         self.diag.clear()
-        self.buildOutput.append('Starting build')
+        self.buildOutput.append('Starting parse')
         ir = self.c3front.build(ce.Source)
 
         # Set errors:
@@ -254,6 +268,27 @@
         self.astViewer.setAst(ast)
         self.buildOutput.append("Done!")
 
+    def buildFile(self):
+        ce = self.activeMdiChild()
+        if not ce:
+            return
+        self.diag.clear()
+        self.buildOutput.append('Starting build')
+        outs = outstream.TextOutputStream()
+        if not zcc.zcc(ce.Source, outs, self.diag):
+            # Set errors:
+            for err in self.diag.diags:
+                self.buildOutput.append(str(err))
+            self.builderrors.setErrorList(self.diag.diags)
+            ce.setErrors(self.diag.diags)
+            return
+
+        self.buildOutput.append("Flashing stm32f4 discovery")
+        code_s = outs.getSection('code')
+        self.debugInfo = code_s.debugInfos()
+
+        self.buildOutput.append("Done!")
+
 if __name__ == '__main__':
     app = QApplication(sys.argv)
     ide = Ide()