comparison python/codegenarm.py @ 249:e41e4109addd

Added current position arrow
author Windel Bouwman
date Fri, 26 Jul 2013 20:26:05 +0200
parents ef683881c64e
children f5fba5b554d7
comparison
equal deleted inserted replaced
248:b10d46e5c8dd 249:e41e4109addd
1 import ir 1 import ir
2 from target import Label, Comment, Alignment, LabelRef, Imm32 2 from target import Label, Comment, Alignment, LabelRef, Imm32, DebugInfo
3 import cortexm3 as arm 3 import cortexm3 as arm
4 from ppci import CompilerError 4 from ppci import CompilerError
5 5
6 class ArmCodeGenerator: 6 class ArmCodeGenerator:
7 """ 7 """
60 def dcd(self, x): 60 def dcd(self, x):
61 self.emit(arm.dcd_ins(Imm32(x))) 61 self.emit(arm.dcd_ins(Imm32(x)))
62 62
63 def align(self): 63 def align(self):
64 self.outs.emit(Alignment(4)) 64 self.outs.emit(Alignment(4))
65
65 # Helper functions: 66 # Helper functions:
66 def getStack(self, v): 67 def getStack(self, v):
67 off = self.stack_frame.index(v) 68 off = self.stack_frame.index(v)
68 return off * 4 69 return off * 4
70
69 def addStack(self, v): 71 def addStack(self, v):
70 self.stack_frame.append(v) 72 self.stack_frame.append(v)
71 return self.getStack(v) 73 return self.getStack(v)
74
72 def getGlobal(self, r, g): 75 def getGlobal(self, r, g):
73 _global_address = g.name + '__global' 76 _global_address = g.name + '__global'
74 self.emit(arm.ldr_pcrel(r, LabelRef(_global_address))) 77 self.emit(arm.ldr_pcrel(r, LabelRef(_global_address)))
78
75 def loadStack(self, reg, val): 79 def loadStack(self, reg, val):
76 self.emit(arm.ldr_sprel(reg, arm.MemSpRel(self.getStack(val)))) 80 self.emit(arm.ldr_sprel(reg, arm.MemSpRel(self.getStack(val))))
81
77 def comment(self, txt): 82 def comment(self, txt):
78 self.emit(Comment(txt)) 83 self.emit(Comment(txt))
79 84
85 def debugInfo(self, loc):
86 if loc:
87 self.emit(DebugInfo(loc))
88
80 def generateInstruction(self, ins): 89 def generateInstruction(self, ins):
81 self.comment(str(ins)) 90 self.comment(str(ins))
91 if hasattr(ins, 'debugLoc'):
92 self.debugInfo(ins.debugLoc)
82 if type(ins) is ir.Branch: 93 if type(ins) is ir.Branch:
83 tgt = LabelRef(ins.target.name) 94 tgt = LabelRef(ins.target.name)
84 self.emit(arm.b_ins(tgt)) 95 self.emit(arm.b_ins(tgt))
85 elif type(ins) is ir.ImmLoad: 96 elif type(ins) is ir.ImmLoad:
86 lname = ins.target.name + '_ivalue' 97 lname = ins.target.name + '_ivalue'