Mercurial > lcfOS
comparison python/codegenarm.py @ 270:cdc76d183bcc
first register allocator
author | Windel Bouwman |
---|---|
date | Mon, 19 Aug 2013 21:14:28 +0200 |
parents | 5f8c04a8d26b |
children | e64bae57cda8 |
comparison
equal
deleted
inserted
replaced
269:5f8c04a8d26b | 270:cdc76d183bcc |
---|---|
1 import logging | 1 import logging |
2 import ir | 2 import ir |
3 from target import Label, Comment, Alignment, LabelRef, Imm32, DebugInfo | 3 from target import Label, Comment, Alignment, LabelRef, Imm32, DebugInfo |
4 import cortexm3 as arm | 4 import cortexm3 as arm |
5 from ppci import CompilerError | 5 from ppci import CompilerError |
6 import graph | |
7 import flowgraph | 6 import flowgraph |
8 import registerallocator | 7 import registerallocator |
9 from instructionselector import InstructionSelector | 8 from instructionselector import InstructionSelector |
10 | 9 |
11 | 10 |
98 self.ins_sel = ArmInstructionSelector() | 97 self.ins_sel = ArmInstructionSelector() |
99 self.outs = outs | 98 self.outs = outs |
100 self.outs.getSection('code').address = 0x08000000 | 99 self.outs.getSection('code').address = 0x08000000 |
101 self.outs.getSection('data').address = 0x20000000 | 100 self.outs.getSection('data').address = 0x20000000 |
102 | 101 |
102 def useUnused(self, inslist): | |
103 # Use unused temporaries at the end of the list | |
104 defTemps = [] | |
105 for d in (i.dst for i in inslist): | |
106 print(d) | |
107 defTemps.append(d) | |
108 useTemps = [d for d in ([i.src] for i in inslist)] | |
109 print(defTemps) | |
110 print(useTemps) | |
111 | |
103 def generate(self, ircode, cfg_file=None, ig_file=None): | 112 def generate(self, ircode, cfg_file=None, ig_file=None): |
104 x = self.ins_sel.munchProgram(ircode) | 113 ir2 = self.ins_sel.munchProgram(ircode) |
105 cfg = flowgraph.FlowGraph(x) | 114 self.useUnused(ir2) |
115 cfg = flowgraph.FlowGraph(ir2) | |
106 if cfg_file: | 116 if cfg_file: |
107 cfg.to_dot(cfg_file) | 117 cfg.to_dot(cfg_file) |
108 ig = registerallocator.InterferenceGraph(cfg) | 118 ig = registerallocator.InterferenceGraph(cfg) |
109 if ig_file: | 119 if ig_file: |
110 ig.to_dot(ig_file) | 120 ig.to_dot(ig_file) |
111 | 121 |
112 regs = ['r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7'] | 122 regs = ['r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7'] |
113 ra = registerallocator.RegisterAllocator() | 123 ra = registerallocator.RegisterAllocator() |
114 ra.registerAllocate(ig, regs) | 124 regMap = ra.registerAllocate(ig, regs) |
125 print(regMap) | |
126 for i in ir2: | |
127 i.src = tuple(regMap[t] for t in i.src) | |
128 i.dst = tuple(regMap[t] for t in i.dst) | |
129 print(i) | |
115 | 130 |
116 | 131 |
132 |