comparison python/codegenarm.py @ 237:81752b0f85a5

Added burn led test program
author Windel Bouwman
date Wed, 17 Jul 2013 22:31:54 +0200
parents 8786811a5a59
children 6259856841a0
comparison
equal deleted inserted replaced
236:8786811a5a59 237:81752b0f85a5
26 self.imms = [] # list with immediates relative to PC. 26 self.imms = [] # list with immediates relative to PC.
27 self.outs.selectSection('code') 27 self.outs.selectSection('code')
28 28
29 # Manually inserted startup code: 29 # Manually inserted startup code:
30 self.dcd(0x20000678) # initial stack ptr 30 self.dcd(0x20000678) # initial stack ptr
31 self.dcd(0x08000401) # reset vector 31 # TODO: use label here:
32 #self.emit(arm.dcd_ins(LabelRef('reset'))) # reset vector
33 self.dcd(0x08000009) # reset vector, lsb indicates thumb mode
32 34
35 self.emit(Label('reset'))
33 for f in ircode.Functions: 36 for f in ircode.Functions:
34 # Add global variable addresses to immediate list: 37 # Add global variable addresses to immediate list:
35 for gvar in ircode.Variables: 38 for gvar in ircode.Variables:
36 pass #self.imms.append(( 39 pass #self.imms.append((
37 40
48 while self.imms: 51 while self.imms:
49 l, v = self.imms.pop() 52 l, v = self.imms.pop()
50 self.emit(Label(l)) 53 self.emit(Label(l))
51 self.dcd(v) 54 self.dcd(v)
52 self.align() 55 self.align()
56 self.outs.backpatch()
57 self.outs.backpatch()
53 58
54 def dcd(self, x): 59 def dcd(self, x):
55 self.emit(arm.dcd_ins(Imm32(x))) 60 self.emit(arm.dcd_ins(Imm32(x)))
56 61
57 def align(self): 62 def align(self):
72 self.emit(Comment(txt)) 77 self.emit(Comment(txt))
73 78
74 def generateInstruction(self, ins): 79 def generateInstruction(self, ins):
75 self.comment(str(ins)) 80 self.comment(str(ins))
76 if type(ins) is ir.Branch: 81 if type(ins) is ir.Branch:
77 tgt = Label(ins.target.name) 82 tgt = LabelRef(ins.target.name)
78 self.emit(arm.jmp_ins(tgt)) 83 self.emit(arm.b_ins(tgt))
79 elif type(ins) is ir.ImmLoad: 84 elif type(ins) is ir.ImmLoad:
80 lname = ins.target.name + '_ivalue' 85 lname = ins.target.name + '_ivalue'
81 self.emit(arm.ldr_pcrel(arm.r0, LabelRef(lname))) 86 self.emit(arm.ldr_pcrel(arm.r0, LabelRef(lname)))
82 self.imms.append((lname, ins.value)) 87 self.imms.append((lname, ins.value))
83 self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.target)))) 88 self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.target))))
106 elif ins.operation == '<<': 111 elif ins.operation == '<<':
107 self.emit(arm.lslregs_ins(arm.r0, arm.r1)) 112 self.emit(arm.lslregs_ins(arm.r0, arm.r1))
108 elif ins.operation == '|': 113 elif ins.operation == '|':
109 self.emit(arm.orrregs_ins(arm.r0, arm.r1)) 114 self.emit(arm.orrregs_ins(arm.r0, arm.r1))
110 else: 115 else:
111 print('operation not implemented', ins.operation) 116 raise NotImplementedError('operation {} not implemented'.format(ins.operation))
112 # Store value back: 117 # Store value back:
113 self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.result)))) 118 self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.result))))
114 elif type(ins) is ir.Return: 119 elif type(ins) is ir.Return:
115 self.emit(arm.pop_ins(arm.RegisterSet({arm.r4, arm.r5, arm.r6, arm.r7, arm.pc}))) 120 self.emit(arm.pop_ins(arm.RegisterSet({arm.r4, arm.r5, arm.r6, arm.r7, arm.pc})))
116 elif type(ins) is ir.ConditionalBranch: 121 elif type(ins) is ir.ConditionalBranch:
119 self.emit(arm.cmp_ins(arm.r1, arm.r0)) 124 self.emit(arm.cmp_ins(arm.r1, arm.r0))
120 tgt_yes = Label(ins.lab1.name) 125 tgt_yes = Label(ins.lab1.name)
121 if ins.cond == '==': 126 if ins.cond == '==':
122 self.emit(arm.beq_ins(tgt_yes)) 127 self.emit(arm.beq_ins(tgt_yes))
123 else: 128 else:
124 print('TODO', ins.cond) 129 raise NotImplementedError('"{}" not covered'.format(ins.cond))
125 tgt_no = Label(ins.lab2.name) 130 tgt_no = Label(ins.lab2.name)
126 self.emit(arm.jmp_ins(tgt_no)) 131 self.emit(arm.jmp_ins(tgt_no))
127 elif type(ins) is ir.Alloc: 132 elif type(ins) is ir.Alloc:
128 # Local variables are added to stack 133 # Local variables are added to stack
129 self.addStack(ins.value) 134 self.addStack(ins.value)
130 else: 135 else:
131 raise CompilerError('IR "{}" not covered'.format(ins)) 136 raise NotImplementedError('IR "{}" not covered'.format(ins))
132 137
133 138