annotate test/testmsp430asm.py @ 290:7b38782ed496

File moves
author Windel Bouwman
date Sun, 24 Nov 2013 11:24:15 +0100
parents
children 534b94b40aa8
rev   line source
290
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
1 #!/usr/bin/python
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
2
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
3 import unittest
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
4 from asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
5 from asm import tokenize, Assembler
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
6 import msp430
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
7 import outstream
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
8 from target import Label
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
9 from testasm import AsmTestCaseBase
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
10
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
11
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
12 class AssemblerMSP430TestCase(AsmTestCaseBase):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
13 def setUp(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
14 self.t = msp430.msp430target
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
15 self.o = outstream.BinOutputStream()
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
16 self.o.selectSection('.text')
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
17 self.a = Assembler(target=self.t, stream=self.o)
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
18
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
19 def testMapMovInstruction(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
20 i = AInstruction('mov', [ASymbol('r14'), ASymbol('r15')])
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
21 ri = self.t.mapInstruction(i)
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
22
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
23 def testMapRetiInstruction(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
24 i = AInstruction('reti', [])
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
25 ri = self.t.mapInstruction(i)
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
26
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
27 def testMov(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
28 self.feed("mov r14, r15")
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
29 self.check('0F4E')
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
30
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
31 def testMov1337(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
32 self.feed("mov 0x1337, r12")
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
33 self.check('3C403713')
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
34
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
35 def testAdd(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
36 self.feed("add r15, r13")
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
37 self.check('0D5F')
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
38
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
39 def testReti(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
40 self.feed("reti")
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
41 self.check('0013')
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
42
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
43 def testMSPinstructionCount(self):
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
44 """ Check that there are 27 instructions """
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
45 self.assertEqual(27, len(self.t.instructions))
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
46
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
47
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
48 if __name__ == '__main__':
7b38782ed496 File moves
Windel Bouwman
parents:
diff changeset
49 unittest.main()