Mercurial > lcfOS
comparison python/ppci/target/arm/__init__.py @ 346:3bb7dcfe5529
expanded arm target
author | Windel Bouwman |
---|---|
date | Fri, 07 Mar 2014 17:05:32 +0100 |
parents | b4882ff0ed06 |
children | 2b02bd286fe9 |
comparison
equal
deleted
inserted
replaced
345:b4882ff0ed06 | 346:3bb7dcfe5529 |
---|---|
2 from ..basetarget import Target | 2 from ..basetarget import Target |
3 from ..arm.registers import R0, R1, R2, R3, R4, R5, R6, R7 | 3 from ..arm.registers import R0, R1, R2, R3, R4, R5, R6, R7 |
4 from ..arm.registers import R8, R9, R10, R11, R12, SP, LR, PC | 4 from ..arm.registers import R8, R9, R10, R11, R12, SP, LR, PC |
5 from ..arm.registers import register_range | 5 from ..arm.registers import register_range |
6 | 6 |
7 from .instructions import Mov, Add, Sub, Orr1, B, Bl, Ble, Bgt, Beq | 7 from .instructions import Dcd, Mov, Add, Sub, Orr1, Mul, Mov2 |
8 from .instructions import B, Bl, Ble, Bgt, Beq, Blt | |
9 from .instructions import Push, Pop, Str, Ldr, Ldr3, Str1, Ldr1 | |
10 from .selector import ArmInstructionSelector | |
11 from .frame import ArmFrame | |
8 | 12 |
9 class ArmTarget(Target): | 13 class ArmTarget(Target): |
10 def __init__(self): | 14 def __init__(self): |
11 super().__init__('arm_arm') | 15 super().__init__('arm') |
16 self.make_parser() | |
17 self.ins_sel = ArmInstructionSelector() | |
18 self.FrameClass = ArmFrame | |
12 | 19 |
20 self.add_lowering(Ldr3, lambda im: Ldr3(im.dst[0], im.others[0])) | |
21 self.add_lowering(Str1, lambda im: Str1(im.src[1], im.src[0], im.others[0])) | |
22 self.add_lowering(Ldr1, lambda im: Ldr1(im.dst[0], im.src[0], im.others[0])) | |
23 self.add_lowering(Mov2, lambda im: Mov2(im.dst[0], im.src[0])) | |
24 | |
25 def make_parser(self): | |
13 # Assembly grammar: | 26 # Assembly grammar: |
14 self.add_keyword('r0') | 27 self.add_keyword('r0') |
15 self.add_keyword('r1') | 28 self.add_keyword('r1') |
16 self.add_keyword('r2') | 29 self.add_keyword('r2') |
17 self.add_keyword('r3') | 30 self.add_keyword('r3') |
22 self.add_keyword('r8') | 35 self.add_keyword('r8') |
23 self.add_keyword('r9') | 36 self.add_keyword('r9') |
24 self.add_keyword('r10') | 37 self.add_keyword('r10') |
25 self.add_keyword('r11') | 38 self.add_keyword('r11') |
26 self.add_keyword('r12') | 39 self.add_keyword('r12') |
40 self.add_keyword('sp') | |
41 self.add_keyword('lr') | |
42 self.add_keyword('pc') | |
27 | 43 |
28 self.add_rule('reg', ['r0'], lambda rhs: R0) | 44 self.add_rule('reg', ['r0'], lambda rhs: R0) |
29 self.add_rule('reg', ['r1'], lambda rhs: R1) | 45 self.add_rule('reg', ['r1'], lambda rhs: R1) |
30 self.add_rule('reg', ['r2'], lambda rhs: R2) | 46 self.add_rule('reg', ['r2'], lambda rhs: R2) |
31 self.add_rule('reg', ['r3'], lambda rhs: R3) | 47 self.add_rule('reg', ['r3'], lambda rhs: R3) |
36 self.add_rule('reg', ['r8'], lambda rhs: R8) | 52 self.add_rule('reg', ['r8'], lambda rhs: R8) |
37 self.add_rule('reg', ['r9'], lambda rhs: R9) | 53 self.add_rule('reg', ['r9'], lambda rhs: R9) |
38 self.add_rule('reg', ['r10'], lambda rhs: R10) | 54 self.add_rule('reg', ['r10'], lambda rhs: R10) |
39 self.add_rule('reg', ['r11'], lambda rhs: R11) | 55 self.add_rule('reg', ['r11'], lambda rhs: R11) |
40 self.add_rule('reg', ['r12'], lambda rhs: R12) | 56 self.add_rule('reg', ['r12'], lambda rhs: R12) |
57 self.add_rule('reg', ['sp'], lambda rhs: SP) | |
58 self.add_rule('reg', ['lr'], lambda rhs: LR) | |
59 self.add_rule('reg', ['pc'], lambda rhs: PC) | |
41 | 60 |
61 self.add_keyword('dcd') | |
62 self.add_instruction(['dcd', 'imm32'], | |
63 lambda rhs: Dcd(rhs[1])) | |
42 | 64 |
43 self.add_keyword('mov') | 65 self.add_keyword('mov') |
44 self.add_instruction(['mov', 'reg', ',', 'imm8'], | 66 self.add_instruction(['mov', 'reg', ',', 'imm32'], |
45 lambda rhs: Mov(rhs[1], rhs[3])) | 67 lambda rhs: Mov(rhs[1], rhs[3])) |
46 | 68 |
47 self.add_keyword('add') | 69 self.add_keyword('add') |
48 self.add_instruction(['add', 'reg', ',', 'reg', ',', 'imm32'], | 70 self.add_instruction(['add', 'reg', ',', 'reg', ',', 'imm32'], |
49 lambda rhs: Add(rhs[1], rhs[3], rhs[5])) | 71 lambda rhs: Add(rhs[1], rhs[3], rhs[5])) |
56 lambda rhs: Sub(rhs[1], rhs[3], rhs[5])) | 78 lambda rhs: Sub(rhs[1], rhs[3], rhs[5])) |
57 | 79 |
58 self.add_instruction(['sub', 'reg', ',', 'reg', ',', 'reg'], | 80 self.add_instruction(['sub', 'reg', ',', 'reg', ',', 'reg'], |
59 lambda rhs: Sub(rhs[1], rhs[3], rhs[5])) | 81 lambda rhs: Sub(rhs[1], rhs[3], rhs[5])) |
60 | 82 |
83 self.add_keyword('mul') | |
84 self.add_instruction(['mul', 'reg', ',', 'reg', ',', 'reg'], | |
85 lambda rhs: Mul(rhs[1], rhs[3], rhs[5])) | |
86 | |
61 self.add_keyword('orr') | 87 self.add_keyword('orr') |
62 self.add_instruction(['orr', 'reg', ',', 'reg', ',', 'reg'], | 88 self.add_instruction(['orr', 'reg', ',', 'reg', ',', 'reg'], |
63 lambda rhs: Orr1(rhs[1], rhs[3], rhs[5])) | 89 lambda rhs: Orr1(rhs[1], rhs[3], rhs[5])) |
64 | 90 |
65 | 91 |
70 self.add_instruction(['ble', 'ID'], lambda rhs: Ble(rhs[1].val)) | 96 self.add_instruction(['ble', 'ID'], lambda rhs: Ble(rhs[1].val)) |
71 self.add_keyword('bgt') | 97 self.add_keyword('bgt') |
72 self.add_instruction(['bgt', 'ID'], lambda rhs: Bgt(rhs[1].val)) | 98 self.add_instruction(['bgt', 'ID'], lambda rhs: Bgt(rhs[1].val)) |
73 self.add_keyword('beq') | 99 self.add_keyword('beq') |
74 self.add_instruction(['beq', 'ID'], lambda rhs: Beq(rhs[1].val)) | 100 self.add_instruction(['beq', 'ID'], lambda rhs: Beq(rhs[1].val)) |
101 self.add_keyword('blt') | |
102 self.add_instruction(['blt', 'ID'], lambda rhs: Blt(rhs[1].val)) | |
75 | 103 |
76 self.add_keyword('bl') | 104 self.add_keyword('bl') |
77 self.add_instruction(['bl', 'ID'], lambda rhs: Bl(rhs[1].val)) | 105 self.add_instruction(['bl', 'ID'], lambda rhs: Bl(rhs[1].val)) |
106 | |
107 # memory: | |
108 self.add_keyword('pop') | |
109 self.add_instruction(['pop', 'reg_list'], lambda rhs: Pop(rhs[1])) | |
110 | |
111 self.add_keyword('push') | |
112 self.add_instruction(['push', 'reg_list'], lambda rhs: Push(rhs[1])) | |
113 | |
114 self.add_keyword('ldr') | |
115 self.add_instruction(['ldr', 'reg', ',', '[', 'reg', ',', 'imm8', ']'], | |
116 lambda rhs: Ldr(rhs[1], rhs[4], rhs[6])) | |
117 | |
118 self.add_keyword('str') | |
119 self.add_instruction(['str', 'reg', ',', '[', 'reg', ',', 'imm8', ']'], | |
120 lambda rhs: Str(rhs[1], rhs[4], rhs[6])) | |
121 | |
122 self.add_instruction(['str', 'reg', ',', '[', 'reg', ',', 'reg', ']'], | |
123 lambda rhs: Str(rhs[1], rhs[4], rhs[6])) | |
124 | |
125 # Register list grammar: | |
126 self.add_rule('reg_list', ['{', 'reg_list_inner', '}'], | |
127 lambda rhs: rhs[1]) | |
128 self.add_rule('reg_list_inner', ['reg_or_range'], | |
129 lambda rhs: rhs[0]) | |
130 self.add_rule('reg_list_inner', ['reg_or_range', ',', 'reg_list_inner'], | |
131 lambda rhs: rhs[0] | rhs[2]) | |
132 self.add_rule('reg_or_range', ['reg'], lambda rhs: {rhs[0]}) | |
133 | |
134 self.add_rule('reg_or_range', ['reg', '-', 'reg'], | |
135 lambda rhs: register_range(rhs[0], rhs[2])) |