annotate test/testarmasm.py @ 299:674789d9ff37

Added a doc
author Windel Bouwman
date Sun, 01 Dec 2013 18:37:23 +0100
parents 534b94b40aa8
children 44f336460c2a
rev   line source
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
1 import unittest
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
2 import outstream
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
3 from asm import Assembler
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
4 from testasm import AsmTestCaseBase
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
5 from target import armtarget
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
6
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
7
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
8 class AssemblerARMTestCase(AsmTestCaseBase):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
9 def setUp(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
10 self.t = armtarget
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
11 self.o = outstream.BinOutputStream()
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
12 self.o.selectSection('.text')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
13 self.a = Assembler(target=self.t, stream=self.o)
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
14
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
15 def testMapOperand(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
16 pass
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
17
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
18 def testMovImm8(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
19 self.feed('mov r4, 100')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
20 self.check('6424')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
21
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
22 @unittest.skip
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
23 def testMovExt(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
24 self.feed('mov r3, sp')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
25 self.check('')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
26
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
27 def testYield(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
28 self.feed('yield')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
29 self.check('10bf')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
30
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
31 def testPush(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
32 self.feed('push {r2,r3,lr}')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
33 self.check('0cb5')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
34
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
35 def testPop(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
36 self.feed('pop {r4-r6, pc}')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
37 self.check('70bd')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
38
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
39 def testStr5(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
40 self.feed('str r4, [r1 + 0]')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
41 self.check('0c60')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
42
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
43 def testLdr5(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
44 self.feed('ldr r4, [r0 + 0]')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
45 self.check('0468')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
46
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
47 def testLdrSpRel(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
48 self.feed('ldr r0, [sp + 4]')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
49 self.check('0198')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
50
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
51 def testStrSpRel(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
52 self.feed('str r0, [sp + 4]')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
53 self.check('0190')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
54
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
55 def testLdrPcRel(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
56 self.feed('ldr r7, henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
57 self.feed('ldr r6, henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
58 self.feed('ldr r1, henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
59 self.feed('align 4')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
60 self.feed('dcd 1')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
61 self.feed('henkie: dcd 2')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
62 self.check('024F024E 01490000 01000000 02000000')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
63
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
64 def testBranch(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
65 self.feed('start: b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
66 self.feed('beq henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
67 self.feed('bne henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
68 self.feed('henkie: b start')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
69 self.feed('eof: b eof')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
70 self.check('01e000d0 ffd1fbe7 fee7')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
71
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
72 def testConditions(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
73 self.feed('blt x')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
74 self.feed('bgt x')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
75 self.feed('x:')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
76 self.check('00dbffdc')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
77
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
78 def testBoff(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
79 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
80 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
81 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
82 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
83 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
84 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
85 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
86 self.feed('henkie:')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
87 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
88 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
89 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
90 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
91 self.check('05e004e0 03e002e0 01e000e0 ffe7fee7 fde7fce7 fbe7')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
92
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
93 def testBl(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
94 self.feed('bl henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
95 self.feed('bl henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
96 self.feed('henkie:')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
97 self.feed('bl henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
98 self.feed('bl henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
99 self.check('00f0 02f8 00f0 00f8 fff7 feff fff7 fcff')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
100
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
101 def testCmpRegReg(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
102 self.feed('cmp r0, r1')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
103 self.check('8842')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
104
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
105 def testAddimm3(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
106 self.feed('add r3, r5, 2')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
107 self.feed('add r4, r1, 6')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
108 self.check('ab1c8c1d')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
109
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
110 def testSubImm3(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
111 self.feed('sub r3, r5, 2')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
112 self.feed('sub r4, r1, 6')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
113 self.check('ab1e8c1f')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
114
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
115 def testLeftShift(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
116 self.feed('lsl r3, r5')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
117 self.check('ab40')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
118
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
119 def testAddSp(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
120 self.feed('add sp,sp,8')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
121 self.feed('add sp,sp,16')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
122 self.check('02b004b0')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
123
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
124 def testSubSp(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
125 self.feed('sub sp,sp,32')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
126 self.feed('sub sp,sp,4')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
127 self.check('88b081b0')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
128
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
129 def testSequence1(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
130 self.feed('mov r5, 3')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
131 self.feed('add r4, r5, 0')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
132 self.feed('loop: add r6, r4, 7')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
133 self.feed('cmp r6, 5')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
134 self.check('0325 2c1c e61d 052e')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
135
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
136 def testSequence2(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
137 self.feed('henkie:')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
138 self.feed('push {r1,r4,r5}')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
139 self.feed('add r5, r2, r4')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
140 self.feed('cmp r4, r2')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
141 self.feed('ldr r0, [sp + 4]')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
142 self.feed('str r3, [sp + 16]')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
143 self.feed('pop {r1, r4, r5}')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
144 self.feed('lsl r3, r4')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
145 self.feed('cmp r3, r5')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
146 self.feed('beq henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
147 self.feed('bne henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
148 self.feed('b henkie')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents:
diff changeset
149 self.check('32b41519 94420198 049332bc a340ab42 f6d0f5d1 f4e7')