Mercurial > lcfOS
comparison python/target/arminstructionselector.py @ 336:d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
author | Windel Bouwman |
---|---|
date | Wed, 19 Feb 2014 22:32:15 +0100 |
parents | e9fe6988497c |
children | 4d204f6f7d4e |
comparison
equal
deleted
inserted
replaced
335:582a1aaa3983 | 336:d1ecc493384e |
---|---|
1 import os | 1 import os |
2 from ppci import ir | 2 from ppci import ir, same_dir |
3 from ppci.irmach import AbstractInstruction as makeIns | 3 from ppci.irmach import AbstractInstruction as makeIns |
4 from ppci.ir2tree import makeTree | 4 from ppci.ir2tree import makeTree |
5 import pyburg | 5 import pyburg |
6 from .basetarget import Label, Comment, Alignment, LabelRef, DebugInfo, Nop | 6 from .basetarget import Label, Comment, Alignment, LabelRef, DebugInfo, Nop |
7 from .instructionselector import InstructionSelector | 7 from .instructionselector import InstructionSelector |
10 from .arminstructions import Mov2, Mov3 | 10 from .arminstructions import Mov2, Mov3 |
11 from .arminstructions import Add, Sub, Cmp, Sub2, Add2, Mul | 11 from .arminstructions import Add, Sub, Cmp, Sub2, Add2, Mul |
12 from .basetarget import Imm8, Imm7, Imm3 | 12 from .basetarget import Imm8, Imm7, Imm3 |
13 | 13 |
14 # Import BURG spec for arm: | 14 # Import BURG spec for arm: |
15 spec_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'arm.brg') | 15 spec_file = same_dir(__file__, 'arm.brg') |
16 arm_matcher = pyburg.load_as_module(spec_file) | 16 arm_matcher = pyburg.load_as_module(spec_file) |
17 | 17 |
18 | 18 |
19 class ArmMatcher(arm_matcher.Matcher): | 19 class ArmMatcher(arm_matcher.Matcher): |
20 """ Matcher that derives from a burg spec generated matcher """ | 20 """ Matcher that derives from a burg spec generated matcher """ |
73 # Generate expression code and discard the result. | 73 # Generate expression code and discard the result. |
74 x = self.munchExpr(s.e) | 74 x = self.munchExpr(s.e) |
75 self.emit(Nop(), src=[x]) | 75 self.emit(Nop(), src=[x]) |
76 elif isinstance(s, ir.Jump): | 76 elif isinstance(s, ir.Jump): |
77 tgt = self.targets[s.target] | 77 tgt = self.targets[s.target] |
78 self.emit(B(LabelRef(s.target.name)), jumps=[tgt]) | 78 self.emit(B(LabelRef(ir.label_name(s.target))), jumps=[tgt]) |
79 elif isinstance(s, ir.CJump): | 79 elif isinstance(s, ir.CJump): |
80 a = self.munchExpr(s.a) | 80 a = self.munchExpr(s.a) |
81 b = self.munchExpr(s.b) | 81 b = self.munchExpr(s.b) |
82 self.emit(Cmp, src=[a, b]) | 82 self.emit(Cmp, src=[a, b]) |
83 ntgt = self.targets[s.lab_no] | 83 ntgt = self.targets[s.lab_no] |
84 ytgt = self.targets[s.lab_yes] | 84 ytgt = self.targets[s.lab_yes] |
85 jmp_ins = makeIns(B(LabelRef(s.lab_no.name)), jumps=[ntgt]) | 85 jmp_ins = makeIns(B(LabelRef(ir.label_name(s.lab_no))), jumps=[ntgt]) |
86 opnames = {'<': Blt, '>':Bgt, '==':Beq, '!=':Bne} | 86 opnames = {'<': Blt, '>':Bgt, '==':Beq, '!=':Bne} |
87 op = opnames[s.cond](LabelRef(s.lab_yes.name)) | 87 op = opnames[s.cond](LabelRef(ir.label_name(s.lab_yes))) |
88 self.emit(op, jumps=[ytgt, jmp_ins]) # Explicitely add fallthrough | 88 self.emit(op, jumps=[ytgt, jmp_ins]) # Explicitely add fallthrough |
89 self.emit2(jmp_ins) | 89 self.emit2(jmp_ins) |
90 else: | 90 else: |
91 raise NotImplementedError('Stmt --> {}'.format(s)) | 91 raise NotImplementedError('Stmt --> {}'.format(s)) |
92 | 92 |