annotate python/testasm.py @ 218:494828a7adf1

added some sort of cache to assembler
author Windel Bouwman
date Fri, 05 Jul 2013 15:30:22 +0200
parents 62386bcee1ba
children 1fa3e0050b49
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
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
9
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
10 class AssemblerLexingCase(unittest.TestCase):
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
11 """ Tests the assemblers lexer """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
12
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
13 def testLex0(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
14 """ Check if the lexer is OK """
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
15 asmline, toks = 'mov rax, rbx ', ['ID', 'ID', ',', 'ID']
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
16 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
17
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
18 def testLex1(self):
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
19 """ Test if lexer correctly maps some tokens """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
20 asmline, toks = 'lab1: mov rax, rbx ', ['ID', ':', 'ID', 'ID', ',', 'ID']
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
21 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
22
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
23 def testLex1(self):
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
24 """ Test if lexer correctly maps some tokens """
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
25 asmline, toks = 'mov 3.13 0xC 13', ['ID', 'REAL', 'NUMBER', 'NUMBER']
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
26 self.assertSequenceEqual([tok.typ for tok in tokenize(asmline)], toks)
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
27
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
28 def testLex2(self):
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
29 """ Test if lexer fails on a token that is invalid """
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
30 asmline = '0z4: mov rax, rbx $ '
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
31 with self.assertRaises(CompilerError):
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
32 list(tokenize(asmline))
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
33
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
34 class AssemblerParsingTestCase(unittest.TestCase):
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
35 """
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
36 Tests the assembler parts
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
37 """
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
38 def setUp(self):
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
39 self.a = Assembler()
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
40
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
41 def testParse(self):
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
42 asmline = 'lab1: mov rax, rbx'
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
43 self.a.parse_line(asmline)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
44
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
45 def testParse2(self):
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
46 asmline = 'a: mov rax, [rbx + 2]'
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
47 self.a.parse_line(asmline)
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
48 output = []
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
49 output.append(ALabel('a'))
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
50 output.append(AInstruction('mov', [ASymbol('rax'), AUnop('[]', ASymbol('rbx') + ANumber(2))]))
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
51 self.assertSequenceEqual(output, self.a.output)
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
52
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
53 def testParse3(self):
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
54 # A label must be optional:
b01429a5d695 Fixed test
Windel Bouwman
parents: 193
diff changeset
55 asmline = 'mov rax, 1'
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
56 self.a.parse_line(asmline)
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
57 output = [AInstruction('mov', [ASymbol('rax'), ANumber(1)])]
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
58 self.assertSequenceEqual(output, self.a.output)
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
59
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
60 def testParse4(self):
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
61 # Test 3 operands:
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
62 asmline = 'add rax, [4*rbx + 22], rcx'
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
63 self.a.parse_line(asmline)
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
64 ops = []
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
65 ops.append(ASymbol('rax'))
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
66 ops.append(AUnop('[]', ANumber(4) * ASymbol('rbx') + ANumber(22)))
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
67 ops.append(ASymbol('rcx'))
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
68 output = [AInstruction('add', ops)]
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
69 self.assertSequenceEqual(output, self.a.output)
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
70
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
71 def testParse5(self):
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
72 # An instruction must be optional:
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
73 asmline = 'lab1:'
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
74 self.a.parse_line(asmline)
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
75 output = []
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
76 output.append(ALabel('lab1'))
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
77 self.assertSequenceEqual(output, self.a.output)
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
78
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
79 def testParse6(self):
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
80 # A line can be empty
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
81 self.a.parse_line('')
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
82
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
83 class AssemblerOtherTestCase(unittest.TestCase):
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
84 def testWithoutTarget(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
85 a = Assembler()
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
86 with self.assertRaises(CompilerError):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
87 a.assemble_line('')
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
88
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
89 @unittest.skip
195
37ac6c016e0f Expanded asm subsystem
Windel Bouwman
parents: 194
diff changeset
90 def testX86(self):
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
91 testsrc = """ ; tst
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
92 begin:
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
93 mov rax, rbx ; 0x48, 0x89, 0xd8
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
94 xor rcx, rbx ; 0x48, 0x31, 0xd9
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
95 inc rcx ; 0x48 0xff 0xc1
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
96 """
198
33d50727a23c Fixup testscript
Windel Bouwman
parents: 196
diff changeset
97 a = Assembler()
196
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
98 a.assemble(testsrc)
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
99 # Compare with nasm output:
ec2b423cdbea Merge asm and asmlib files
Windel Bouwman
parents: 195
diff changeset
100 nasmbytes = [0x48, 0x89, 0xd8, 0x48, 0x31, 0xd9, 0x48, 0xff, 0xc1]
193
f091e7d70996 Added even more checks
Windel Bouwman
parents: 191
diff changeset
101
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
102 class AssemblerMSP430TestCase(unittest.TestCase):
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
103 def setUp(self):
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
104 self.t = msp430.msp430target
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
105 self.a = Assembler(target=self.t)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
106
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
107 def testMapMovInstruction(self):
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
108 i = AInstruction('mov', [ASymbol('r14'), ASymbol('r15')])
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
109 ri = self.t.mapInstruction(i)
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
110
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
111 def testMapRetiInstruction(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
112 i = AInstruction('reti', [])
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
113 ri = self.t.mapInstruction(i)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
114
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
115 @unittest.skip
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
116 def testMapOperand(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
117 o = ASymbol('r14')
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
118 mo = self.t.mapOperand(o)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
119 self.assertEqual(mo, msp430.r14)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
120
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
121 @unittest.skip
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
122 def testMapOperandIndirection(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
123 o = AUnop('[]', ASymbol('r14'))
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents: 199
diff changeset
124 mo = self.t.mapOperand(o)
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
125
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
126 def testMov(self):
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
127 line1 = "mov r14, r15"
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
128 self.a.assemble_line(line1)
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
129 self.assertEqual(bytes([0x0F, 0x4E]), self.a.binout)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
130
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
131 def testMov1337(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
132 line1 = "mov 0x1337, r12"
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
133 self.a.assemble_line(line1)
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
134 self.assertEqual(bytes.fromhex('3C403713'), self.a.binout)
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
135
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
136 def testAdd(self):
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
137 line1 = "add r15, r13"
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
138 self.a.assemble_line(line1)
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
139 self.assertEqual(bytes.fromhex('0D5F'), self.a.binout)
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
140
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
141 def testReti(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
142 line1 = "reti"
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
143 self.a.assemble_line(line1)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
144 self.assertEqual(bytes([0x0, 0x13]), self.a.binout)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
145
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
146 def testMSPinstructionCount(self):
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
147 """ Check that there are 27 instructions """
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
148 self.assertEqual(27, len(self.t.instructions))
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
149
a690473b79e2 Added msp430 target
Windel Bouwman
parents: 198
diff changeset
150
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
151 class AssemblerARMTestCase(unittest.TestCase):
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
152 def setUp(self):
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
153 self.t = arm.armtarget
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
154 self.a = Assembler(target=self.t)
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
155
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
156 def feed(self, line):
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
157 self.a.assemble(line)
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
158
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
159 def check(self, hexstr):
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
160 self.assertSequenceEqual(bytes.fromhex(hexstr), self.a.binout)
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
161
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
162 def testMapOperand(self):
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
163 pass
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
164
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
165 def testMovImm8(self):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
166 self.feed('mov r4, 100')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
167 self.check('6424')
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
168
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
169 def testYield(self):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
170 self.feed('yield')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
171 self.check('10bf')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
172
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
173 def testPush(self):
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
174 self.feed('push {r2,r3,lr}')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
175 self.check('0cb5')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
176
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
177 def testPop(self):
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
178 self.feed('pop {r4-r6, pc}')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
179 self.check('70bd')
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
180
212
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
181 def testStr5(self):
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
182 self.feed('str r4, [r1 + 0]')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
183 self.check('0c60')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
184
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
185 def testLdr5(self):
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
186 self.feed('ldr r4, [r0 + 0]')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
187 self.check('0468')
62386bcee1ba Added parser combinator lib
Windel Bouwman
parents: 207
diff changeset
188
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
189 def testCmpRegReg(self):
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
190 self.feed('cmp r0, r1')
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
191 self.check('8842')
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 212
diff changeset
192
203
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 202
diff changeset
193 def testSequence1(self):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
194 self.feed('mov r5, 3')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
195 self.feed('add r4, r5, 0')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
196 self.feed('loop: add r6, r4, 7')
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
197 self.feed('cmp r6, 5')
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 206
diff changeset
198 self.check('0325 2c1c e61d 052e')
202
f22b431f4113 Added arm add instruction
Windel Bouwman
parents: 201
diff changeset
199
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
200 if __name__ == '__main__':
203
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 202
diff changeset
201 #cProfile.run('unittest.main()')
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
202 unittest.main()
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents:
diff changeset
203