290
|
1 #!/usr/bin/python
|
|
2
|
|
3 import unittest
|
334
|
4 from ppci.asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber
|
|
5 from ppci.assembler import tokenize, Assembler
|
335
|
6 from ppci.objectfile import ObjectFile
|
290
|
7 import outstream
|
322
|
8 from target import Label
|
|
9 from target.target_list import msp430target
|
290
|
10 from testasm import AsmTestCaseBase
|
|
11
|
|
12
|
|
13 class AssemblerMSP430TestCase(AsmTestCaseBase):
|
|
14 def setUp(self):
|
292
|
15 self.t = msp430target
|
335
|
16 self.obj = ObjectFile()
|
|
17 self.o = outstream.BinaryOutputStream(self.obj)
|
290
|
18 self.o.selectSection('.text')
|
|
19 self.a = Assembler(target=self.t, stream=self.o)
|
|
20
|
|
21 def testMapMovInstruction(self):
|
|
22 i = AInstruction('mov', [ASymbol('r14'), ASymbol('r15')])
|
|
23 ri = self.t.mapInstruction(i)
|
|
24
|
|
25 def testMapRetiInstruction(self):
|
|
26 i = AInstruction('reti', [])
|
|
27 ri = self.t.mapInstruction(i)
|
|
28
|
|
29 def testMov(self):
|
|
30 self.feed("mov r14, r15")
|
|
31 self.check('0F4E')
|
|
32
|
|
33 def testMov1337(self):
|
|
34 self.feed("mov 0x1337, r12")
|
|
35 self.check('3C403713')
|
|
36
|
|
37 def testAdd(self):
|
|
38 self.feed("add r15, r13")
|
|
39 self.check('0D5F')
|
|
40
|
|
41 def testReti(self):
|
|
42 self.feed("reti")
|
|
43 self.check('0013')
|
|
44
|
|
45 def testMSPinstructionCount(self):
|
|
46 """ Check that there are 27 instructions """
|
|
47 self.assertEqual(27, len(self.t.instructions))
|
|
48
|
|
49
|
|
50 if __name__ == '__main__':
|
|
51 unittest.main()
|