342
|
1 import struct
|
|
2 import types
|
|
3 from ..basetarget import Register, Instruction, Target
|
201
|
4 from ppci import CompilerError
|
342
|
5 from .registers import r10, r11, r12, r13, r14, r15
|
|
6 from .instructions import Reti, Mov, Add
|
381
|
7 from ...assembler import BaseAssembler
|
|
8
|
201
|
9
|
|
10 # Create the target class (singleton):
|
341
|
11
|
381
|
12 class Msp430Assembler(BaseAssembler):
|
|
13 def __init__(self, target):
|
|
14 super().__init__(target)
|
|
15 self.make_parser()
|
|
16
|
|
17
|
342
|
18 class Msp430Target(Target):
|
341
|
19 def __init__(self):
|
|
20 super().__init__('msp430')
|
342
|
21
|
|
22 # Registers:
|
|
23 self.add_keyword('r10')
|
|
24 self.add_keyword('r11')
|
|
25 self.add_keyword('r12')
|
341
|
26 self.add_keyword('r13')
|
|
27 self.add_keyword('r14')
|
|
28 self.add_keyword('r15')
|
342
|
29 self.add_rule('reg', ['r10'], lambda rhs: r10)
|
|
30 self.add_rule('reg', ['r11'], lambda rhs: r11)
|
|
31 self.add_rule('reg', ['r12'], lambda rhs: r12)
|
341
|
32 self.add_rule('reg', ['r13'], lambda rhs: r13)
|
|
33 self.add_rule('reg', ['r14'], lambda rhs: r14)
|
|
34 self.add_rule('reg', ['r15'], lambda rhs: r15)
|
342
|
35
|
|
36 # Instructions rules:
|
|
37 self.add_keyword('mov')
|
341
|
38 self.add_instruction(['mov', 'reg', ',', 'reg'],
|
|
39 lambda rhs: Mov(rhs[1], rhs[3]))
|
342
|
40 self.add_instruction(['mov', 'imm16', ',', 'reg'],
|
|
41 lambda rhs: Mov(rhs[1], rhs[3]))
|
|
42
|
|
43 self.add_keyword('add')
|
|
44 self.add_instruction(['add', 'reg', ',', 'reg'],
|
|
45 lambda rhs: Add(rhs[1], rhs[3]))
|
|
46
|
341
|
47 self.add_keyword('reti')
|
342
|
48 self.add_instruction(['reti'], lambda rhs: Reti())
|
201
|
49
|
381
|
50 self.assembler = Msp430Assembler(self)
|
342
|
51
|
398
|
52 self.registers.append(r10)
|
|
53 self.registers.append(r11)
|
|
54 self.registers.append(r12)
|
|
55 self.registers.append(r13)
|
|
56 self.registers.append(r14)
|
|
57 self.registers.append(r15)
|
342
|
58
|
|
59
|
201
|
60
|
199
|
61 # Target description for the MSP430 processor
|
|
62
|
|
63
|
201
|
64
|