Mercurial > lcfOS
comparison python/target/arminstructionselector.py @ 322:44f336460c2a
Half of use of burg spec for arm
author | Windel Bouwman |
---|---|
date | Mon, 27 Jan 2014 19:58:07 +0100 |
parents | e84047f29c78 |
children | e9fe6988497c |
comparison
equal
deleted
inserted
replaced
321:8c569fbe60e4 | 322:44f336460c2a |
---|---|
1 import os | |
1 from ppci import ir | 2 from ppci import ir |
2 from ppci.irmach import AbstractInstruction as makeIns | 3 from ppci.irmach import AbstractInstruction as makeIns |
4 from ppci.ir2tree import makeTree | |
5 import pyburg | |
3 from .basetarget import Label, Comment, Alignment, LabelRef, DebugInfo, Nop | 6 from .basetarget import Label, Comment, Alignment, LabelRef, DebugInfo, Nop |
4 from .instructionselector import InstructionSelector | 7 from .instructionselector import InstructionSelector |
5 from .arminstructions import Orr, Lsl, Str2, Ldr2, Ldr3 | 8 from .arminstructions import Orr, Lsl, Str2, Ldr2, Ldr3 |
6 from .arminstructions import B, Bl, Bgt, Blt, Beq, Bne | 9 from .arminstructions import B, Bl, Bgt, Blt, Beq, Bne |
7 from .arminstructions import Mov2, Mov3 | 10 from .arminstructions import Mov2, Mov3 |
8 from .arminstructions import Add, Sub, Cmp, Sub2, Add2, Mul | 11 from .arminstructions import Add, Sub, Cmp, Sub2, Add2, Mul |
9 from .basetarget import Imm8, Imm7, Imm3 | 12 from .basetarget import Imm8, Imm7, Imm3 |
10 | 13 |
14 # Import BURG spec for arm: | |
15 spec_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'arm.brg') | |
16 arm_matcher = pyburg.load_as_module(spec_file) | |
17 | |
18 class ArmMatcher(arm_matcher.Matcher): | |
19 def __init__(self): | |
20 super().__init__() | |
21 | |
22 def newTmp(self): | |
23 pass | |
24 | |
25 def emit(self, *args, **kwargs): | |
26 pass | |
27 | |
11 | 28 |
12 class ArmInstructionSelector(InstructionSelector): | 29 class ArmInstructionSelector(InstructionSelector): |
13 """ Instruction selector for the arm architecture """ | 30 """ Instruction selector for the arm architecture """ |
31 def __init__(self): | |
32 super().__init__() | |
33 self.matcher = ArmMatcher() | |
34 | |
14 def munchExpr(self, e): | 35 def munchExpr(self, e): |
36 #t = makeTree(e) | |
37 #print(t) | |
38 #return self.matcher.gen(t) | |
39 | |
40 # TODO: below is obsolete: | |
15 if isinstance(e, ir.Binop) and e.operation == '+' and \ | 41 if isinstance(e, ir.Binop) and e.operation == '+' and \ |
16 isinstance(e.b, ir.Const) and e.b.value < 8: | 42 isinstance(e.b, ir.Const) and e.b.value < 8: |
17 a = self.munchExpr(e.a) | 43 a = self.munchExpr(e.a) |
18 d = self.newTmp() | 44 d = self.newTmp() |
19 c = Imm3(e.b.value) | 45 c = Imm3(e.b.value) |