Mercurial > lcfOS
comparison python/target/arminstructionselector.py @ 300:158068af716c
yafm
author | Windel Bouwman |
---|---|
date | Tue, 03 Dec 2013 18:00:22 +0100 |
parents | 534b94b40aa8 |
children | 6753763d3bec |
comparison
equal
deleted
inserted
replaced
299:674789d9ff37 | 300:158068af716c |
---|---|
2 from irmach import AbstractInstruction as makeIns | 2 from irmach import AbstractInstruction as makeIns |
3 from .basetarget import Label, Comment, Alignment, LabelRef, DebugInfo, Nop | 3 from .basetarget import Label, Comment, Alignment, LabelRef, DebugInfo, Nop |
4 from .instructionselector import InstructionSelector | 4 from .instructionselector import InstructionSelector |
5 from .arminstructions import Orr, Lsl, Str2, Ldr2, Ldr3, B, Bl, Bgt, Blt, Beq | 5 from .arminstructions import Orr, Lsl, Str2, Ldr2, Ldr3, B, Bl, Bgt, Blt, Beq |
6 from .arminstructions import Mov2, Mov3 | 6 from .arminstructions import Mov2, Mov3 |
7 from .arminstructions import Add, Sub, Cmp | 7 from .arminstructions import Add, Sub, Cmp, Sub2, Add2, Mul |
8 from .basetarget import Imm8, Imm7, Imm3 | 8 from .basetarget import Imm8, Imm7, Imm3 |
9 | 9 |
10 | 10 |
11 class ArmInstructionSelector(InstructionSelector): | 11 class ArmInstructionSelector(InstructionSelector): |
12 """ Instruction selector for the arm architecture """ | 12 """ Instruction selector for the arm architecture """ |
16 elif isinstance(e, ir.Binop) and e.operation == '+' and \ | 16 elif isinstance(e, ir.Binop) and e.operation == '+' and \ |
17 isinstance(e.b, ir.Const) and e.b.value < 8: | 17 isinstance(e.b, ir.Const) and e.b.value < 8: |
18 a = self.munchExpr(e.a) | 18 a = self.munchExpr(e.a) |
19 d = self.newTmp() | 19 d = self.newTmp() |
20 c = Imm3(e.b.value) | 20 c = Imm3(e.b.value) |
21 self.emit(arm.addregregimm3_ins, others=[c], dst=[d], src=[a]) | 21 self.emit(Add2, others=[c], dst=[d], src=[a]) |
22 return d | 22 return d |
23 elif isinstance(e, ir.Binop) and e.operation == '+': | 23 elif isinstance(e, ir.Binop) and e.operation == '+': |
24 a = self.munchExpr(e.a) | 24 a = self.munchExpr(e.a) |
25 b = self.munchExpr(e.b) | 25 b = self.munchExpr(e.b) |
26 d = self.newTmp() | 26 d = self.newTmp() |
29 elif isinstance(e, ir.Binop) and e.operation == '-' and \ | 29 elif isinstance(e, ir.Binop) and e.operation == '-' and \ |
30 isinstance(e.b, ir.Const) and e.b.value < 8: | 30 isinstance(e.b, ir.Const) and e.b.value < 8: |
31 a = self.munchExpr(e.a) | 31 a = self.munchExpr(e.a) |
32 d = self.newTmp() | 32 d = self.newTmp() |
33 c = Imm3(e.b.value) | 33 c = Imm3(e.b.value) |
34 self.emit(arm.subregregimm3_ins, others=[c], dst=[d], src=[a]) | 34 self.emit(Sub2, others=[c], dst=[d], src=[a]) |
35 return d | 35 return d |
36 elif isinstance(e, ir.Binop) and e.operation == '-': | 36 elif isinstance(e, ir.Binop) and e.operation == '-': |
37 a = self.munchExpr(e.a) | 37 a = self.munchExpr(e.a) |
38 b = self.munchExpr(e.b) | 38 b = self.munchExpr(e.b) |
39 d = self.newTmp() | 39 d = self.newTmp() |
57 a = self.munchExpr(e.a) | 57 a = self.munchExpr(e.a) |
58 b = self.munchExpr(e.b) | 58 b = self.munchExpr(e.b) |
59 d = self.newTmp() | 59 d = self.newTmp() |
60 self.move(d, a) | 60 self.move(d, a) |
61 # this mul instruction has operands swapped: | 61 # this mul instruction has operands swapped: |
62 self.emit(arm.mulregreg_ins, dst=[d], src=[b, d]) | 62 self.emit(Mul, dst=[d], src=[b, d]) |
63 return d | 63 return d |
64 elif isinstance(e, ir.Const) and e.value < 256: | 64 elif isinstance(e, ir.Const) and e.value < 256: |
65 d = self.newTmp() | 65 d = self.newTmp() |
66 self.emit(Mov3, others=[Imm8(e.value)], dst=[d]) | 66 self.emit(Mov3, others=[Imm8(e.value)], dst=[d]) |
67 return d | 67 return d |