annotate python/target/armtarget.py @ 341:4d204f6f7d4e devel

Rewrite of assembler parts
author Windel Bouwman
date Fri, 28 Feb 2014 18:07:14 +0100
parents c7cc54c0dfdf
children
rev   line source
261
444b9df2ed99 try to split up code generation
Windel Bouwman
parents: 258
diff changeset
1 import struct
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
2 from .basetarget import Register, Instruction, Target, Label, Alignment
290
7b38782ed496 File moves
Windel Bouwman
parents: 287
diff changeset
3 from .basetarget import Imm32, Imm8, Imm7, Imm3
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
4 from .arminstructions import Add2, Sub, Add3, Cmp, Lsl, Orr
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
5 from .arminstructions import Dcd, Pop, Push, Yield, Mov2, Mov3
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
6 from .arminstructions import B, Bl, Bne, Beq, Blt, Bgt
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
7 from .arminstructions import Ldr, Str2, Ldr2, Str1, Ldr1
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents:
diff changeset
8
322
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents: 292
diff changeset
9 from .armframe import ArmFrame
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents: 292
diff changeset
10 from .arminstructionselector import ArmInstructionSelector
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
11 from .armregisters import R0, R1, R2, R3, R4, R5, R6, R7, SP, LR, PC
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
12 from .armregisters import register_range
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
13
290
7b38782ed496 File moves
Windel Bouwman
parents: 287
diff changeset
14
7b38782ed496 File moves
Windel Bouwman
parents: 287
diff changeset
15 """ ARM target description. """
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 280
diff changeset
16
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 216
diff changeset
17 # TODO: encode this in DSL (domain specific language)
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 268
diff changeset
18 # TBD: is this required?
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
19 # TODO: make a difference between armv7 and armv5?
219
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
20
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
21 thumb_assembly_rules = []
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
22 def add_rule(rhs, f):
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
23 thumb_assembly_rules.append(('instruction', rhs, f))
277
046017431c6a Started register allocator
Windel Bouwman
parents: 276
diff changeset
24
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
25
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
26 class ThumbTarget(Target):
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
27 def __init__(self):
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
28 super().__init__('thumb')
322
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents: 292
diff changeset
29 self.ins_sel = ArmInstructionSelector()
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents: 292
diff changeset
30 self.FrameClass = ArmFrame
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
31 self.add_rules()
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
32
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
33 def add_rules(self):
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
34
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
35 # Add instructions:
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
36 self.add_keyword('dcd')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
37 self.add_instruction(['dcd', 'imm32'], lambda rhs: Dcd(rhs[1]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
38
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
39 self.add_keyword('mov')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
40 self.add_instruction(['mov', 'reg8', ',', 'reg8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
41 lambda rhs: Mov2(rhs[1], rhs[3]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
42
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
43 self.add_instruction(['mov', 'reg8', ',', 'imm8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
44 lambda rhs: Mov3(rhs[1], rhs[3]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
45
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
46 self.add_keyword('add')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
47 self.add_instruction(['add', 'reg8', ',', 'reg8', ',', 'imm3'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
48 lambda rhs: Add2(rhs[1], rhs[3], rhs[5]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
49
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
50 self.add_instruction(['add', 'reg8', ',', 'reg8', ',', 'reg8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
51 lambda rhs: Add3(rhs[1], rhs[3], rhs[5]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
52
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
53 self.add_keyword('sub')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
54 self.add_instruction(['sub', 'reg8', ',', 'reg8', ',', 'imm3'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
55 lambda rhs: Sub(rhs[1], rhs[3], rhs[5]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
56
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
57 self.add_instruction(['sub', 'sp', ',', 'sp', ',', 'imm8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
58 lambda rhs: Sub(SP, SP, rhs[5]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
59
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
60 self.add_instruction(['add', 'sp', ',', 'sp', ',', 'imm8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
61 lambda rhs: Sub(SP, SP, rhs[5]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
62
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
63 self.add_keyword('cmp')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
64 self.add_instruction(['cmp', 'reg8', ',', 'reg8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
65 lambda rhs: Cmp(rhs[1], rhs[3]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
66
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
67 self.add_keyword('lsl')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
68 self.add_instruction(['lsl', 'reg8', ',', 'reg8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
69 lambda rhs: Lsl(rhs[1], rhs[3]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
70
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
71 self.add_keyword('str')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
72 self.add_instruction(['str', 'reg8', ',', '[', 'reg8', '+', 'imm5', ']'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
73 lambda rhs: Str2(rhs[1], rhs[4], rhs[6]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
74
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
75 self.add_keyword('ldr')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
76 self.add_instruction(['ldr', 'reg8', ',', '[', 'reg8', '+', 'imm5', ']'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
77 lambda rhs: Ldr2(rhs[1], rhs[4], rhs[6]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
78
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
79 self.add_instruction(['str', 'reg8', ',', '[', 'sp', '+', 'imm8', ']'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
80 lambda rhs: Str1(rhs[1], rhs[6]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
81
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
82 self.add_instruction(['ldr', 'reg8', ',', '[', 'sp', '+', 'imm8', ']'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
83 lambda rhs: Ldr1(rhs[1], rhs[6]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
84
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
85 self.add_keyword('pop')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
86 self.add_instruction(['pop', 'reg_list'], lambda rhs: Pop(rhs[1]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
87 self.add_keyword('push')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
88 self.add_instruction(['push', 'reg_list'], lambda rhs: Push(rhs[1]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
89
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
90 self.add_keyword('yield')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
91 self.add_instruction(['yield'], lambda rhs: Yield())
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
92
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
93 self.add_keyword('b')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
94 self.add_keyword('bl')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
95 self.add_instruction(['b', 'ID'], lambda rhs: B(rhs[1].val))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
96 self.add_instruction(['bl', 'ID'], lambda rhs: Bl(rhs[1].val))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
97 self.add_keyword('beq')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
98 self.add_keyword('bne')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
99 self.add_keyword('blt')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
100 self.add_keyword('bgt')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
101 self.add_instruction(['beq', 'ID'], lambda rhs: Beq(rhs[1].val))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
102 self.add_instruction(['bne', 'ID'], lambda rhs: Bne(rhs[1].val))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
103 self.add_instruction(['blt', 'ID'], lambda rhs: Blt(rhs[1].val))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
104 self.add_instruction(['bgt', 'ID'], lambda rhs: Bgt(rhs[1].val))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
105
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
106 self.add_keyword('align')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
107 self.add_instruction(['align', 'imm8'], lambda rhs: Alignment(rhs[1]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
108
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
109 self.add_instruction(['ldr', 'reg8', ',', 'ID'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
110 lambda rhs: Ldr(rhs[1], rhs[3].val))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
111
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
112 # Additional rules:
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
113
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
114 # Register list grammar:
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
115 self.add_rule('reg_list', ['{', 'reg_list_inner', '}'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
116 lambda rhs: rhs[1])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
117 self.add_rule('reg_list_inner', ['reg_or_range'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
118 lambda rhs: rhs[0])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
119 self.add_rule('reg_list_inner', ['reg_or_range', ',', 'reg_list_inner'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
120 lambda rhs: rhs[0] | rhs[2])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
121 self.add_rule('reg_or_range', ['reg8'], lambda rhs: {rhs[0]})
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
122 self.add_rule('reg_or_range', ['lr'], lambda rhs: {LR})
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
123 self.add_rule('reg_or_range', ['pc'], lambda rhs: {PC})
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
124
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
125 self.add_rule('reg_or_range', ['reg8', '-', 'reg8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
126 lambda rhs: register_range(rhs[0], rhs[2]))
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
127
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
128 self.add_keyword('r0')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
129 self.add_keyword('r1')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
130 self.add_keyword('r2')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
131 self.add_keyword('r3')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
132 self.add_keyword('r4')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
133 self.add_keyword('r5')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
134 self.add_keyword('r6')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
135 self.add_keyword('r7')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
136 self.add_keyword('sp')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
137 self.add_keyword('lr')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
138 self.add_keyword('pc')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
139 self.add_rule('reg8', ['r0'], lambda rhs: R0)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
140 self.add_rule('reg8', ['r1'], lambda rhs: R1)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
141 self.add_rule('reg8', ['r2'], lambda rhs: R2)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
142 self.add_rule('reg8', ['r3'], lambda rhs: R3)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
143 self.add_rule('reg8', ['r4'], lambda rhs: R4)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
144 self.add_rule('reg8', ['r5'], lambda rhs: R5)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
145 self.add_rule('reg8', ['r6'], lambda rhs: R6)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
146 self.add_rule('reg8', ['r7'], lambda rhs: R7)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
147 # Constants:
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
148 self.add_rule('imm32', ['val32'], lambda x: x[0].val)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
149 self.add_rule('imm32', ['imm8'], lambda x: x[0])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
150 self.add_rule('imm8', ['val8'], lambda x: x[0].val)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
151 self.add_rule('imm8', ['imm5'], lambda x: x[0])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
152 self.add_rule('imm5', ['val5'], lambda x: x[0].val)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
153 self.add_rule('imm5', ['imm3'], lambda x: x[0])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
154 self.add_rule('imm3', ['val3'], lambda x: x[0].val)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
155
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 334
diff changeset
156
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 334
diff changeset
157
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 334
diff changeset
158 class ArmArmTarget(Target):
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 334
diff changeset
159 def __init__(self):
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 334
diff changeset
160 super().__init__('arm_arm')
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 334
diff changeset
161
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
162 # Assembly grammar:
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
163 self.add_keyword('mov')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
164 self.add_keyword('r0')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
165 self.add_keyword('r1')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
166 self.add_keyword('r2')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
167 self.add_keyword('r3')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
168 self.add_keyword('r4')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
169 self.add_keyword('r5')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
170
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
171 self.add_rule('reg', ['r0'], lambda rhs: R0)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
172 self.add_rule('reg', ['r1'], lambda rhs: R1)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
173 self.add_rule('reg', ['r2'], lambda rhs: R2)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
174 self.add_rule('reg', ['r3'], lambda rhs: R3)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
175 self.add_rule('reg', ['r4'], lambda rhs: R4)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
176 self.add_rule('reg', ['r5'], lambda rhs: R5)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
177
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
178
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
179 self.add_instruction(['mov', 'reg', ',', 'imm8'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
180 lambda rhs: Yield())
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
181
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
182 self.add_rule('imm32', ['val32'], lambda x: x[0].val)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
183 self.add_rule('imm32', ['imm8'], lambda x: x[0])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
184 self.add_rule('imm8', ['val8'], lambda x: x[0].val)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
185 self.add_rule('imm8', ['imm5'], lambda x: x[0])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
186 self.add_rule('imm5', ['val5'], lambda x: x[0].val)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
187 self.add_rule('imm5', ['imm3'], lambda x: x[0])
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 340
diff changeset
188 self.add_rule('imm3', ['val3'], lambda x: x[0].val)