Mercurial > lcfOS
comparison python/codegenarm.py @ 218:494828a7adf1
added some sort of cache to assembler
author | Windel Bouwman |
---|---|
date | Fri, 05 Jul 2013 15:30:22 +0200 |
parents | 62386bcee1ba |
children | 1fa3e0050b49 |
comparison
equal
deleted
inserted
replaced
217:8b2e5f3cd579 | 218:494828a7adf1 |
---|---|
1 import ir | 1 import ir |
2 from asmnodes import ALabel | 2 from asmnodes import ALabel |
3 import arm_cm3 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 """ Simple code generator """ | 7 """ Simple code generator """ |
8 def __init__(self, out): | 8 def __init__(self, out): |
22 self.emit(arm.dcd_ins(0)) | 22 self.emit(arm.dcd_ins(0)) |
23 | 23 |
24 self.outs.selectSection('code') | 24 self.outs.selectSection('code') |
25 for f in ircode.Functions: | 25 for f in ircode.Functions: |
26 self.emit(ALabel(f.name)) | 26 self.emit(ALabel(f.name)) |
27 self.emit(arm.push_ins(arm.RegisterSet({arm.r2, arm.r3,arm.lr}))) | 27 # Save some registers: |
28 self.emit(arm.push_ins(arm.RegisterSet({arm.r4, arm.r5, arm.r6,arm.r7,arm.lr}))) | |
28 for bb in f.BasicBlocks: | 29 for bb in f.BasicBlocks: |
29 self.emit(ALabel(bb.name)) | 30 self.emit(ALabel(bb.name)) |
30 for ins in bb.Instructions: | 31 for ins in bb.Instructions: |
31 self.generateInstruction(ins) | 32 self.generateInstruction(ins) |
32 | 33 |
41 elif type(ins) is ir.ImmLoad and ins.value < (2**32): | 42 elif type(ins) is ir.ImmLoad and ins.value < (2**32): |
42 print(ins) | 43 print(ins) |
43 elif type(ins) is ir.Store: | 44 elif type(ins) is ir.Store: |
44 print(ins) | 45 print(ins) |
45 elif type(ins) is ir.Return: | 46 elif type(ins) is ir.Return: |
46 self.emit(arm.pop_ins(arm.RegisterSet({arm.r2, arm.r3, arm.pc}))) | 47 self.emit(arm.pop_ins(arm.RegisterSet({arm.r5, arm.r6, arm.pc}))) |
47 elif type(ins) is ir.Load: | 48 elif type(ins) is ir.Load: |
48 print(ins) | 49 print(ins) |
49 elif type(ins) is ir.BinaryOperator: | 50 elif type(ins) is ir.BinaryOperator: |
50 print(ins) | 51 print(ins) |
51 elif type(ins) is ir.ConditionalBranch: | 52 elif type(ins) is ir.ConditionalBranch: |
52 print(ins) | 53 print(ins) |
54 self.emit(arm.cmp_ins(arm.r1, arm.r0)) | |
53 else: | 55 else: |
54 print(ins) | |
55 raise CompilerError('IR "{}" not covered'.format(ins)) | 56 raise CompilerError('IR "{}" not covered'.format(ins)) |
56 | 57 |
57 | 58 |