annotate test/testasm.py @ 290:7b38782ed496

File moves
author Windel Bouwman
date Sun, 24 Nov 2013 11:24:15 +0100
parents 05184b95fa16
children 534b94b40aa8
rev   line source
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
1 #!/usr/bin/python
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
2
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
3 import unittest, cProfile
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
4 from ppci import CompilerError
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
5 from asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
6 from asm import tokenize, Assembler
290
7b38782ed496 File moves
Windel Bouwman
parents: 284
diff changeset
7 import target.armtarget as arm
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
8 import outstream
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
9 from target import Label
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
10
290
7b38782ed496 File moves
Windel Bouwman
parents: 284
diff changeset
11
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
12 class AssemblerLexingCase(unittest.TestCase):
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
13 """ Tests the assemblers lexer """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
14
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
15 def testLex0(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
16 """ Check if the lexer is OK """
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
17 asmline, toks = 'mov rax, rbx ', ['ID', 'ID', ',', 'ID']
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
18 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
19
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
20 def testLex1(self):
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
21 """ Test if lexer correctly maps some tokens """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
22 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID']
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
23 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
24
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
25 def testLex1(self):
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
26 """ Test if lexer correctly maps some tokens """
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
27 asmline, toks = 'mov 3.13 0xC 13', ['ID', 'REAL', 'NUMBER', 'NUMBER']
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
28 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
29
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
30 def testLex2(self):
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
31 """ Test if lexer fails on a token that is invalid """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
32 asmline = '0z4: mov rax, rbx $ '
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
33 with self.assertRaises(CompilerError):
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
34 list(tokenize(asmline))
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
35
290
7b38782ed496 File moves
Windel Bouwman
parents: 284
diff changeset
36
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
37 class AssemblerParsingTestCase(unittest.TestCase):
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
38 """
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
39 Tests the assembler parts
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
40 """
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
41 def setUp(self):
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
42 self.a = Assembler()
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
43
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
44 def testParse(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
45 asmline = 'lab1: mov rax, rbx'
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
46 self.a.parse_line(asmline)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
47
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
48 def expectTree(self, asmline, stack):
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
49 self.a.parse_line(asmline)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
50 self.assertSequenceEqual(stack, self.a.stack)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
51
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
52 def testParse2(self):
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
53 asmline = 'a: mov rax, [rbx + 2]'
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
54 output = []
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
55 output.append(ALabel('a'))
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
56 output.append(AInstruction('mov', [ASymbol('rax'), AUnop('[]', ASymbol('rbx') + ANumber(2))]))
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
57 self.expectTree(asmline, output)
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
58
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
59 def testParse3(self):
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
60 # A label must be optional:
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
61 asmline = 'mov rax, 1'
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
62 output = [AInstruction('mov', [ASymbol('rax'), ANumber(1)])]
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
63 self.expectTree(asmline, output)
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
64
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
65 def testParse4(self):
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
66 # Test 3 operands:
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
67 asmline = 'add rax, [4*rbx + 22], rcx'
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
68 ops = []
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
69 ops.append(ASymbol('rax'))
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
70 ops.append(AUnop('[]', ANumber(4) * ASymbol('rbx') + ANumber(22)))
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
71 ops.append(ASymbol('rcx'))
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
72 output = [AInstruction('add', ops)]
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
73 self.expectTree(asmline, output)
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
74
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
75 def testParse5(self):
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
76 # An instruction must be optional:
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
77 asmline = 'lab1:'
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
78 output = []
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
79 output.append(ALabel('lab1'))
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
80 self.expectTree(asmline, output)
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
81
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
82 def testParse6(self):
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
83 # A line can be empty
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
84 self.a.parse_line('')
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
85
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
86 class AssemblerOtherTestCase(unittest.TestCase):
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
87 def testWithoutTarget(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
88 a = Assembler()
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
89 with self.assertRaises(CompilerError):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
90 a.assemble_line('')
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
91
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
92 @unittest.skip
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
93 def testX86(self):
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
94 testsrc = """ ; tst
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
95 begin:
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
96 mov rax, rbx ; 0x48, 0x89, 0xd8
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
97 xor rcx, rbx ; 0x48, 0x31, 0xd9
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
98 inc rcx ; 0x48 0xff 0xc1
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
99 """
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
100 a = Assembler()
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
101 a.assemble(testsrc)
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
102 # Compare with nasm output:
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
103 nasmbytes = [0x48, 0x89, 0xd8, 0x48, 0x31, 0xd9, 0x48, 0xff, 0xc1]
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
104
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
105
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
106 class OustreamTestCase(unittest.TestCase):
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
107 def test1(self):
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
108 o = outstream.BinOutputStream()
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
109 o.selectSection('.text')
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
110 o.emit(Label('a'))
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
111 self.assertSequenceEqual(bytes(), o.Data)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
112
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
113
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
114 class AsmTestCaseBase(unittest.TestCase):
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
115 def feed(self, line):
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
116 self.a.assemble(line)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
117
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
118 def check(self, hexstr):
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
119 self.assertSequenceEqual(bytes.fromhex(hexstr), self.o.Data)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
120
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
121
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
122 class AssemblerMSP430TestCase(AsmTestCaseBase):
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
123 def setUp(self):
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
124 self.t = msp430.msp430target
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
125 self.o = outstream.BinOutputStream()
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
126 self.o.selectSection('.text')
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
127 self.a = Assembler(target=self.t, stream=self.o)
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
128
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
129 def testMapMovInstruction(self):
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
130 i = AInstruction('mov', [ASymbol('r14'), ASymbol('r15')])
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
131 ri = self.t.mapInstruction(i)
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
132
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
133 def testMapRetiInstruction(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
134 i = AInstruction('reti', [])
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
135 ri = self.t.mapInstruction(i)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
136
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
137 @unittest.skip
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
138 def testMapOperand(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
139 o = ASymbol('r14')
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
140 mo = self.t.mapOperand(o)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
141 self.assertEqual(mo, msp430.r14)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
142
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
143 @unittest.skip
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
144 def testMapOperandIndirection(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
145 o = AUnop('[]', ASymbol('r14'))
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
146 mo = self.t.mapOperand(o)
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
147
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
148 def testMov(self):
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
149 line1 = "mov r14, r15"
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
150 self.feed(line1)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
151 self.check('0F4E')
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
152
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
153 def testMov1337(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
154 line1 = "mov 0x1337, r12"
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
155 self.feed(line1)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
156 self.check('3C403713')
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
157
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
158 def testAdd(self):
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
159 line1 = "add r15, r13"
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
160 self.feed(line1)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
161 self.check('0D5F')
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
162
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
163 def testReti(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
164 line1 = "reti"
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
165 self.feed(line1)
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
166 self.check('0013')
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
167
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
168 def testMSPinstructionCount(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
169 """ Check that there are 27 instructions """
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
170 self.assertEqual(27, len(self.t.instructions))
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
171
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
172
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
173 class AssemblerARMTestCase(AsmTestCaseBase):
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
174 def setUp(self):
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
175 self.t = arm.armtarget
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
176 self.o = outstream.BinOutputStream()
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
177 self.o.selectSection('.text')
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
178 self.a = Assembler(target=self.t, stream=self.o)
232
e621e3ba78d2 Added left shift instruction
Windel Bouwman
parents: 224
diff changeset
179
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
180 def testMapOperand(self):
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
181 pass
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
182
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
183 def testMovImm8(self):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
184 self.feed('mov r4, 100')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
185 self.check('6424')
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
186
277
046017431c6a Started register allocator
Windel Bouwman
parents: 276
diff changeset
187 @unittest.skip
046017431c6a Started register allocator
Windel Bouwman
parents: 276
diff changeset
188 def testMovExt(self):
046017431c6a Started register allocator
Windel Bouwman
parents: 276
diff changeset
189 self.feed('mov r3, sp')
046017431c6a Started register allocator
Windel Bouwman
parents: 276
diff changeset
190 self.check('')
046017431c6a Started register allocator
Windel Bouwman
parents: 276
diff changeset
191
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
192 def testYield(self):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
193 self.feed('yield')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
194 self.check('10bf')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
195
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
196 def testPush(self):
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
197 self.feed('push {r2,r3,lr}')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
198 self.check('0cb5')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
199
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
200 def testPop(self):
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
201 self.feed('pop {r4-r6, pc}')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
202 self.check('70bd')
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
203
212
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
204 def testStr5(self):
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
205 self.feed('str r4, [r1 + 0]')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
206 self.check('0c60')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
207
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
208 def testLdr5(self):
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
209 self.feed('ldr r4, [r0 + 0]')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
210 self.check('0468')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
211
219
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
212 def testLdrSpRel(self):
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
213 self.feed('ldr r0, [sp + 4]')
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
214 self.check('0198')
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
215
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
216 def testStrSpRel(self):
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
217 self.feed('str r0, [sp + 4]')
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
218 self.check('0190')
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
219
234
Windel Bouwman
parents: 232
diff changeset
220 def testLdrPcRel(self):
237
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
221 self.feed('ldr r7, henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
222 self.feed('ldr r6, henkie')
234
Windel Bouwman
parents: 232
diff changeset
223 self.feed('ldr r1, henkie')
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 234
diff changeset
224 self.feed('align 4')
234
Windel Bouwman
parents: 232
diff changeset
225 self.feed('dcd 1')
Windel Bouwman
parents: 232
diff changeset
226 self.feed('henkie: dcd 2')
237
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
227 self.check('024F024E 01490000 01000000 02000000')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
228
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
229 def testBranch(self):
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
230 self.feed('start: b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
231 self.feed('beq henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
232 self.feed('bne henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
233 self.feed('henkie: b start')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
234 self.feed('eof: b eof')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
235 self.check('01e000d0 ffd1fbe7 fee7')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
236
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents: 251
diff changeset
237 def testConditions(self):
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents: 251
diff changeset
238 self.feed('blt x')
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents: 251
diff changeset
239 self.feed('bgt x')
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents: 251
diff changeset
240 self.feed('x:')
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents: 251
diff changeset
241 self.check('00dbffdc')
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents: 251
diff changeset
242
237
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
243 def testBoff(self):
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
244 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
245 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
246 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
247 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
248 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
249 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
250 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
251 self.feed('henkie:')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
252 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
253 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
254 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
255 self.feed('b henkie')
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 236
diff changeset
256 self.check('05e004e0 03e002e0 01e000e0 ffe7fee7 fde7fce7 fbe7')
234
Windel Bouwman
parents: 232
diff changeset
257
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
258 def testBl(self):
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
259 self.feed('bl henkie')
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
260 self.feed('bl henkie')
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
261 self.feed('henkie:')
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
262 self.feed('bl henkie')
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
263 self.feed('bl henkie')
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
264 self.check('00f0 02f8 00f0 00f8 fff7 feff fff7 fcff')
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 238
diff changeset
265
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
266 def testCmpRegReg(self):
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
267 self.feed('cmp r0, r1')
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
268 self.check('8842')
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
269
276
Windel Bouwman
parents: 275
diff changeset
270 def testAddimm3(self):
Windel Bouwman
parents: 275
diff changeset
271 self.feed('add r3, r5, 2')
Windel Bouwman
parents: 275
diff changeset
272 self.feed('add r4, r1, 6')
Windel Bouwman
parents: 275
diff changeset
273 self.check('ab1c8c1d')
Windel Bouwman
parents: 275
diff changeset
274
Windel Bouwman
parents: 275
diff changeset
275 def testSubImm3(self):
Windel Bouwman
parents: 275
diff changeset
276 self.feed('sub r3, r5, 2')
Windel Bouwman
parents: 275
diff changeset
277 self.feed('sub r4, r1, 6')
Windel Bouwman
parents: 275
diff changeset
278 self.check('ab1e8c1f')
Windel Bouwman
parents: 275
diff changeset
279
Windel Bouwman
parents: 275
diff changeset
280 def testLeftShift(self):
232
e621e3ba78d2 Added left shift instruction
Windel Bouwman
parents: 224
diff changeset
281 self.feed('lsl r3, r5')
e621e3ba78d2 Added left shift instruction
Windel Bouwman
parents: 224
diff changeset
282 self.check('ab40')
e621e3ba78d2 Added left shift instruction
Windel Bouwman
parents: 224
diff changeset
283
276
Windel Bouwman
parents: 275
diff changeset
284 def testAddSp(self):
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 262
diff changeset
285 self.feed('add sp,sp,8')
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 262
diff changeset
286 self.feed('add sp,sp,16')
276
Windel Bouwman
parents: 275
diff changeset
287 self.check('02b004b0')
Windel Bouwman
parents: 275
diff changeset
288
Windel Bouwman
parents: 275
diff changeset
289 def testSubSp(self):
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 262
diff changeset
290 self.feed('sub sp,sp,32')
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 262
diff changeset
291 self.feed('sub sp,sp,4')
276
Windel Bouwman
parents: 275
diff changeset
292 self.check('88b081b0')
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 262
diff changeset
293
203
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 202
diff changeset
294 def testSequence1(self):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
295 self.feed('mov r5, 3')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
296 self.feed('add r4, r5, 0')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
297 self.feed('loop: add r6, r4, 7')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
298 self.feed('cmp r6, 5')
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 206
diff changeset
299 self.check('0325 2c1c e61d 052e')
262
ed14e077124c Added conditional branch instructions
Windel Bouwman
parents: 251
diff changeset
300
238
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
301 def testSequence2(self):
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
302 self.feed('henkie:')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
303 self.feed('push {r1,r4,r5}')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
304 self.feed('add r5, r2, r4')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
305 self.feed('cmp r4, r2')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
306 self.feed('ldr r0, [sp + 4]')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
307 self.feed('str r3, [sp + 16]')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
308 self.feed('pop {r1, r4, r5}')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
309 self.feed('lsl r3, r4')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
310 self.feed('cmp r3, r5')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
311 self.feed('beq henkie')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
312 self.feed('bne henkie')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
313 self.feed('b henkie')
90637d1bbfad Added test sequence 2
Windel Bouwman
parents: 237
diff changeset
314 self.check('32b41519 94420198 049332bc a340ab42 f6d0f5d1 f4e7')
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
315
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
316 if __name__ == '__main__':
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
317 unittest.main()