Mercurial > lcfOS
diff python/codegenarm.py @ 232:e621e3ba78d2
Added left shift instruction
author | Windel Bouwman |
---|---|
date | Sun, 14 Jul 2013 11:50:58 +0200 |
parents | 1c7364bd74c7 |
children | 83781bd10fdb |
line wrap: on
line diff
--- a/python/codegenarm.py Sat Jul 13 20:20:44 2013 +0200 +++ b/python/codegenarm.py Sun Jul 14 11:50:58 2013 +0200 @@ -26,6 +26,11 @@ 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 + for f in ircode.Functions: # Add global variable addresses to immediate list: for gvar in ircode.Variables: @@ -63,45 +68,48 @@ self.emit(AComment(txt)) def generateInstruction(self, ins): + self.comment(str(ins)) if type(ins) is ir.Branch: tgt = ALabel(ins.target.name) self.emit(arm.jmp_ins(tgt)) elif type(ins) is ir.ImmLoad: - self.comment(str(ins)) lname = ins.target.name + '_ivalue' self.emit(arm.ldr_pcrel(arm.r0, ALabel(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: - self.comment(str(ins)) # Load value in r0: self.loadStack(arm.r0, ins.value) # store in memory: - self.getGlobal(arm.r1, ins.location) + # TODO: split globals and locals?? + #self.getGlobal(arm.r1, ins.location) + self.loadStack(arm.r1, ins.location) self.emit(arm.storeimm5_ins(arm.r0, arm.MemR8Rel(arm.r1, 0))) elif type(ins) is ir.Load: - self.comment(str(ins)) - self.getGlobal(arm.r0, ins.location) + # TODO: differ global and local?? + #self.getGlobal(arm.r0, ins.location) + self.loadStack(arm.r0, ins.location) self.emit(arm.loadimm5_ins(arm.r0, arm.MemR8Rel(arm.r0, 0))) # Store value on stack: self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.value)))) elif type(ins) is ir.BinaryOperator: - self.comment(str(ins)) # Load operands: self.loadStack(arm.r0, ins.value1) self.loadStack(arm.r1, ins.value2) # do operation: if ins.operation == '+': self.emit(arm.addregs_ins(arm.r0, arm.r0, arm.r1)) + elif ins.operation == '<<': + self.emit(arm.lslregs_ins(arm.r0, arm.r1)) + elif ins.operation == '|': + self.emit(arm.orrregs_ins(arm.r0, arm.r1)) else: print('operation not implemented', ins.operation) # Store value back: self.emit(arm.str_sprel(arm.r0, arm.MemSpRel(self.addStack(ins.result)))) elif type(ins) is ir.Return: - self.comment(str(ins)) self.emit(arm.pop_ins(arm.RegisterSet({arm.r4, arm.r5, arm.r6, arm.r7, arm.pc}))) elif type(ins) is ir.ConditionalBranch: - self.comment(str(ins)) self.loadStack(arm.r0, ins.a) self.loadStack(arm.r1, ins.b) self.emit(arm.cmp_ins(arm.r1, arm.r0)) @@ -113,6 +121,7 @@ tgt_no = ALabel(ins.lab2.name) self.emit(arm.jmp_ins(tgt_no)) elif type(ins) is ir.Alloc: + # Local variables are added to stack self.addStack(ins.value) else: raise CompilerError('IR "{}" not covered'.format(ins))