diff python/codegenarm.py @ 235:ff40407c0240

Fix ALabel to Label
author Windel Bouwman
date Mon, 15 Jul 2013 17:20:37 +0200
parents 83781bd10fdb
children 8786811a5a59
line wrap: on
line diff
--- a/python/codegenarm.py	Sun Jul 14 19:29:21 2013 +0200
+++ b/python/codegenarm.py	Mon Jul 15 17:20:37 2013 +0200
@@ -1,5 +1,5 @@
 import ir
-from target import Label, Comment
+from target import Label, Comment, Alignment, LabelRef, Imm32
 import cortexm3 as arm
 from ppci import CompilerError
 
@@ -20,16 +20,16 @@
         self.outs.selectSection('data')
 
         for gvar in ircode.Variables:
-            self.emit(ALabel(gvar.name))
+            self.emit(Label(gvar.name))
             # TODO: use initial value:
-            self.emit(arm.dcd_ins(0))
+            self.dcd(0)
 
         self.imms = [] # list with immediates relative to PC.
         self.outs.selectSection('code')
 
         # Manually inserted startup code:
-        self.emit(arm.dcd_ins(0x20000678)) # initial stack ptr
-        self.emit(arm.dcd_ins(0x08000401)) # reset vector
+        self.dcd(0x20000678) # initial stack ptr
+        self.dcd(0x08000401) # reset vector
 
         for f in ircode.Functions:
             # Add global variable addresses to immediate list:
@@ -45,13 +45,18 @@
                 for ins in bb.Instructions:
                     self.generateInstruction(ins)
 
-            self.outs.align(4)
+            self.align()
             while self.imms:
                 l, v = self.imms.pop()
                 self.emit(Label(l))
-                self.emit(arm.dcd_ins(v))
-            self.outs.align(4)
+                self.dcd(v)
+            self.align()
 
+    def dcd(self, x):
+        self.emit(arm.dcd_ins(Imm32(x)))
+
+    def align(self):
+        self.outs.emit(Alignment(4))
     # Helper functions:
     def getStack(self, v):
         off = self.stack_frame.index(v)
@@ -61,7 +66,7 @@
         return self.getStack(v)
     def getGlobal(self, r, g):
         _global_address = g.name + '__global'
-        self.emit(arm.ldr_pcrel(r, ALabel(_global_address)))
+        self.emit(arm.ldr_pcrel(r, LabelRef(_global_address)))
     def loadStack(self, reg, val):
         self.emit(arm.ldr_sprel(reg, arm.MemSpRel(self.getStack(val))))
     def comment(self, txt):
@@ -74,7 +79,7 @@
             self.emit(arm.jmp_ins(tgt))
         elif type(ins) is ir.ImmLoad:
             lname = ins.target.name + '_ivalue'
-            self.emit(arm.ldr_pcrel(arm.r0, Label(lname)))
+            self.emit(arm.ldr_pcrel(arm.r0, LabelRef(lname)))
             self.imms.append((lname, ins.value))
             self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.target))))
         elif type(ins) is ir.Store:
@@ -113,12 +118,12 @@
             self.loadStack(arm.r0, ins.a)
             self.loadStack(arm.r1, ins.b)
             self.emit(arm.cmp_ins(arm.r1, arm.r0))
-            tgt_yes = ALabel(ins.lab1.name)
+            tgt_yes = Label(ins.lab1.name)
             if ins.cond == '==':
                 self.emit(arm.beq_ins(tgt_yes))
             else:
                 print('TODO', ins.cond)
-            tgt_no = ALabel(ins.lab2.name)
+            tgt_no = Label(ins.lab2.name)
             self.emit(arm.jmp_ins(tgt_no))
         elif type(ins) is ir.Alloc:
             # Local variables are added to stack