annotate python/testasm.py @ 277:046017431c6a

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