changeset 271:cf7d5fb7d9c8

Reorganization
author Windel Bouwman
date Tue, 20 Aug 2013 18:56:02 +0200
parents cdc76d183bcc
children e64bae57cda8
files python/c3/examples/blink.c3 python/c3/examples/burn.c3 python/c3/examples/burn2.c3 python/c3/examples/stm32f4xx.c3 python/ir/__init__.py python/ir/basicblock.py python/ir/function.py python/ir/module.py python/stm32f4/blink.c3 python/stm32f4/burn.c3 python/stm32f4/burn2.c3 python/stm32f4/stm32f4xx.c3
diffstat 12 files changed, 214 insertions(+), 235 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/c3/examples/blink.c3	Tue Aug 20 18:56:02 2013 +0200
@@ -0,0 +1,30 @@
+/* This file blinks a LED on the STM32F4 discovery board.
+
+the board has 4 leds on PD12, PD13, PD14 and PD15
+
+*/
+
+package blink;
+
+import stm32f4xx;
+
+// Functions:
+function void main()
+{
+    // Memory mapped control registers:
+    var GPIO_Type GPIOD;
+    GPIOD = cast<GPIO_Type>(0x40020C00);
+    var RCC_Type RCC;
+    RCC = cast<RCC_Type>(0x40023800);
+
+    // Enable the clock to port D:
+    RCC->AHB1ENR = RCC->AHB1ENR | 0x8;
+
+
+    // PD13 == output (01)
+    GPIOD->MODER = (1 << 26);
+    GPIOD->ODR = (1 << 13);
+
+    while(true) {}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/c3/examples/burn.c3	Tue Aug 20 18:56:02 2013 +0200
@@ -0,0 +1,39 @@
+/*
+
+This file blinks a LED on the STM32F4 discovery board.
+
+the board has 4 leds on PD12, PD13, PD14 and PD15
+
+*/
+
+package burn;
+
+import stm32f4xx;
+
+/*
+function void init()
+{
+}
+*/
+
+function void main()
+{
+    //init();
+    var RCC_Type RCC;
+    RCC = cast<RCC_Type>(0x40023800);
+
+    // Enable the clock to port D:
+    RCC->AHB1ENR = RCC->AHB1ENR | (1 << 3);
+    // Memory mapped control registers:
+    var GPIO_Type GPIOD;
+    GPIOD = cast<GPIO_Type>(0x40020C00);
+
+    var int pin;
+    pin = 15;
+    // PD13 == output (01)
+    GPIOD->MODER = (1 << (pin << 1));
+    GPIOD->ODR = (1 << pin);
+
+    while(true) {}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/c3/examples/burn2.c3	Tue Aug 20 18:56:02 2013 +0200
@@ -0,0 +1,45 @@
+/*
+
+This file blinks a LED on the STM32F4 discovery board.
+
+the board has 4 leds on PD12, PD13, PD14 and PD15
+
+*/
+
+package burn2;
+
+import stm32f4xx;
+
+function void init()
+{
+    var RCC_Type RCC;
+    RCC = cast<RCC_Type>(0x40023800);
+
+    // Enable the clock to port D:
+    RCC->AHB1ENR = RCC->AHB1ENR | (1 << 3);
+    // Memory mapped control registers:
+    var GPIO_Type GPIOD;
+    GPIOD = cast<GPIO_Type>(0x40020C00);
+
+    var int pin;
+    pin = 15;
+    // PD13 == output (01)
+    GPIOD->MODER = (1 << (pin * 2));
+    GPIOD->ODR = (1 << pin);
+}
+
+
+function void main()
+{
+    init();
+
+    var int a;
+    a = 0
+    while (a < 1000)
+    {
+      a = a + 1;
+    }
+
+    while(true) {}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/c3/examples/stm32f4xx.c3	Tue Aug 20 18:56:02 2013 +0200
@@ -0,0 +1,31 @@
+
+package stm32f4xx;
+
+type struct {
+    int MODER;
+    int OTYPER;
+    int OSPEEDR;
+    int PUPDR;
+    int IDR;
+    int ODR;
+}* GPIO_Type;
+
+type struct {
+    int CR;
+    int PLLCFGR;
+    int CFGR;
+    int CIR;
+    int AHB1RSTR;
+    int AHB2RSTR;
+    int AHB3RSTR;
+    int reserved0;
+    int APB1RSTR;
+    int APB2RSTR;
+    int reserved1a, reserved1b;
+    int AHB1ENR;
+    int AHB2ENR;
+    int AHB3ENR;
+    int reserved2;
+    int APB1ENR, APB2ENR;
+}* RCC_Type;
+
--- a/python/ir/__init__.py	Mon Aug 19 21:14:28 2013 +0200
+++ b/python/ir/__init__.py	Tue Aug 20 18:56:02 2013 +0200
@@ -1,6 +1,5 @@
 from .module import *
 from .instruction import *
-from .function import Function
+from .function import Function, Block
 from .builder import Builder
-from .basicblock import Block
 
--- a/python/ir/basicblock.py	Mon Aug 19 21:14:28 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-
-class Block:
-    """ 
-        Uninterrupted sequence of instructions with a label at the start.
-    """
-    def __init__(self, name):
-        self.name = name
-        self.instructions = []
-
-    def __repr__(self):
-        return 'Block {0}'.format(self.name)
-
-    def addInstruction(self, i):
-        i.parent = self
-        self.instructions.append(i)
-
-    def replaceInstruction(self, i1, i2):
-        idx = self.instructions.index(i1)
-        i1.parent = None
-        i1.delete()
-        i2.parent = self
-        self.instructions[idx] = i2
-
-    def removeInstruction(self, i):
-        i.parent = None
-        i.delete()
-        self.instructions.remove(i)
-
-    def getInstructions(self):
-        return self.instructions
-    Instructions = property(getInstructions)
-
-    def getLastIns(self):
-        return self.instructions[-1]
-    LastInstruction = property(getLastIns)
-
-    @property
-    def Empty(self):
-        return len(self.instructions) == 0
-
-    @property
-    def FirstInstruction(self):
-        return self.instructions[0]
-
-    def getSuccessors(self):
-        if not self.Empty:
-            return self.LastInstruction.Targets
-        return []
-    Successors = property(getSuccessors)
-
-    def getPredecessors(self):
-        preds = []
-        for bb in self.parent.BasicBlocks:
-            if self in bb.Successors:
-                preds.append(bb)
-        return preds
-    Predecessors = property(getPredecessors)
-
-    def precedes(self, other):
-        raise NotImplementedError()
-
-    def check(self):
-        pass
-
--- a/python/ir/function.py	Mon Aug 19 21:14:28 2013 +0200
+++ b/python/ir/function.py	Tue Aug 20 18:56:02 2013 +0200
@@ -1,4 +1,3 @@
-from .basicblock import Block
 
 class Function:
     def __init__(self, name):
@@ -47,8 +46,7 @@
         return self.entry
 
     def check(self):
-        for bb in self.BasicBlocks:
-            bb.check()
+        pass
 
     def call(self, *args):
         varmap = {}
@@ -60,3 +58,65 @@
             return
 
 
+class Block:
+    """ 
+        Uninterrupted sequence of instructions with a label at the start.
+    """
+    def __init__(self, name):
+        self.name = name
+        self.instructions = []
+
+    def __repr__(self):
+        return 'Block {0}'.format(self.name)
+
+    def addInstruction(self, i):
+        i.parent = self
+        self.instructions.append(i)
+
+    def replaceInstruction(self, i1, i2):
+        idx = self.instructions.index(i1)
+        i1.parent = None
+        i1.delete()
+        i2.parent = self
+        self.instructions[idx] = i2
+
+    def removeInstruction(self, i):
+        i.parent = None
+        i.delete()
+        self.instructions.remove(i)
+
+    def getInstructions(self):
+        return self.instructions
+    Instructions = property(getInstructions)
+
+    def getLastIns(self):
+        return self.instructions[-1]
+    LastInstruction = property(getLastIns)
+
+    @property
+    def Empty(self):
+        return len(self.instructions) == 0
+
+    @property
+    def FirstInstruction(self):
+        return self.instructions[0]
+
+    def getSuccessors(self):
+        if not self.Empty:
+            return self.LastInstruction.Targets
+        return []
+    Successors = property(getSuccessors)
+
+    def getPredecessors(self):
+        preds = []
+        for bb in self.parent.BasicBlocks:
+            if self in bb.Successors:
+                preds.append(bb)
+        return preds
+    Predecessors = property(getPredecessors)
+
+    def precedes(self, other):
+        raise NotImplementedError()
+
+    def check(self):
+        pass
--- a/python/ir/module.py	Mon Aug 19 21:14:28 2013 +0200
+++ b/python/ir/module.py	Tue Aug 20 18:56:02 2013 +0200
@@ -1,6 +1,6 @@
 # IR-Structures:
 from .instruction import *
-from .basicblock import Block
+from .function import Block
 
 class Module:
     """ Main container for a piece of code. """
@@ -12,22 +12,9 @@
     def __repr__(self):
         return 'IR-module [{0}]'.format(self.name)
 
-    def getInstructions(self):
-      ins = []
-      for bb in self.BasicBlocks:
-         ins += bb.Instructions
-      return ins
-    Instructions = property(getInstructions)
-
-    def getBBs(self):
-        bbs = []
-        for f in self.Functions:
-            bbs += f.BasicBlocks
-        return bbs
-
-    BasicBlocks = property(getBBs)
     def addFunc(self, f):
         self.funcs.append(f)
+
     addFunction = addFunc
 
     def addVariable(self, v):
@@ -35,10 +22,12 @@
 
     def getVariables(self):
         return self.variables
+
     Variables = property(getVariables)
 
     def getFunctions(self):
         return self.funcs
+
     Functions = property(getFunctions)
 
     def findFunction(self, name):
@@ -46,6 +35,7 @@
             if f.name == name:
                 return f
         raise KeyError(name)
+
     getFunction = findFunction
 
     def dump(self):
@@ -69,10 +59,6 @@
             outf.write('{0} [shape=note label="{1}"];\n'.format(id(bb), contents))
             for successor in bb.Successors:
                outf.write('"{0}" -> "{1}"\n'.format(id(bb), id(successor)))
-            # Draw dags if any:
-            if hasattr(bb, 'dag'):
-               outf.write('{0} -> {1}\n'.format(id(bb), id(bb.dag)))
-               bb.dag.dumpgv(outf)
 
          outf.write('"{0}" -> "{1}" [label="entry"]\n'.format(id(f), id(f.entry)))
       outf.write('}\n')
@@ -80,8 +66,6 @@
     # Analysis functions:
     def check(self):
         """ Perform sanity check on module """
-        for i in self.Instructions:
-            pass
         for f in self.Functions:
             f.check()
             
--- a/python/stm32f4/blink.c3	Mon Aug 19 21:14:28 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/* This file blinks a LED on the STM32F4 discovery board.
-
-the board has 4 leds on PD12, PD13, PD14 and PD15
-
-*/
-
-package blink;
-
-import stm32f4xx;
-
-// Functions:
-function void main()
-{
-    // Memory mapped control registers:
-    var GPIO_Type GPIOD;
-    GPIOD = cast<GPIO_Type>(0x40020C00);
-    var RCC_Type RCC;
-    RCC = cast<RCC_Type>(0x40023800);
-
-    // Enable the clock to port D:
-    RCC->AHB1ENR = RCC->AHB1ENR | 0x8;
-
-
-    // PD13 == output (01)
-    GPIOD->MODER = (1 << 26);
-    GPIOD->ODR = (1 << 13);
-
-    while(true) {}
-}
-
--- a/python/stm32f4/burn.c3	Mon Aug 19 21:14:28 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
-
-This file blinks a LED on the STM32F4 discovery board.
-
-the board has 4 leds on PD12, PD13, PD14 and PD15
-
-*/
-
-package burn;
-
-import stm32f4xx;
-
-/*
-function void init()
-{
-}
-*/
-
-function void main()
-{
-    //init();
-    var RCC_Type RCC;
-    RCC = cast<RCC_Type>(0x40023800);
-
-    // Enable the clock to port D:
-    RCC->AHB1ENR = RCC->AHB1ENR | (1 << 3);
-    // Memory mapped control registers:
-    var GPIO_Type GPIOD;
-    GPIOD = cast<GPIO_Type>(0x40020C00);
-
-    var int pin;
-    pin = 15;
-    // PD13 == output (01)
-    GPIOD->MODER = (1 << (pin << 1));
-    GPIOD->ODR = (1 << pin);
-
-    while(true) {}
-}
-
--- a/python/stm32f4/burn2.c3	Mon Aug 19 21:14:28 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
-
-This file blinks a LED on the STM32F4 discovery board.
-
-the board has 4 leds on PD12, PD13, PD14 and PD15
-
-*/
-
-package burn2;
-
-import stm32f4xx;
-
-function void init()
-{
-    var RCC_Type RCC;
-    RCC = cast<RCC_Type>(0x40023800);
-
-    // Enable the clock to port D:
-    RCC->AHB1ENR = RCC->AHB1ENR | (1 << 3);
-    // Memory mapped control registers:
-    var GPIO_Type GPIOD;
-    GPIOD = cast<GPIO_Type>(0x40020C00);
-
-    var int pin;
-    pin = 15;
-    // PD13 == output (01)
-    GPIOD->MODER = (1 << (pin * 2));
-    GPIOD->ODR = (1 << pin);
-}
-
-
-function void main()
-{
-    init();
-
-    var int a;
-    a = 0
-    while (a < 1000)
-    {
-      a = a + 1;
-    }
-
-    while(true) {}
-}
-
--- a/python/stm32f4/stm32f4xx.c3	Mon Aug 19 21:14:28 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-
-package stm32f4xx;
-
-type struct {
-    int MODER;
-    int OTYPER;
-    int OSPEEDR;
-    int PUPDR;
-    int IDR;
-    int ODR;
-}* GPIO_Type;
-
-type struct {
-    int CR;
-    int PLLCFGR;
-    int CFGR;
-    int CIR;
-    int AHB1RSTR;
-    int AHB2RSTR;
-    int AHB3RSTR;
-    int reserved0;
-    int APB1RSTR;
-    int APB2RSTR;
-    int reserved1a, reserved1b;
-    int AHB1ENR;
-    int AHB2ENR;
-    int AHB3ENR;
-    int reserved2;
-    int APB1ENR, APB2ENR;
-}* RCC_Type;
-