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
|
201
|
7
|
|
8 # Create the target class (singleton):
|
341
|
9
|
342
|
10 class Msp430Target(Target):
|
341
|
11 def __init__(self):
|
|
12 super().__init__('msp430')
|
342
|
13
|
|
14 # Registers:
|
|
15 self.add_keyword('r10')
|
|
16 self.add_keyword('r11')
|
|
17 self.add_keyword('r12')
|
341
|
18 self.add_keyword('r13')
|
|
19 self.add_keyword('r14')
|
|
20 self.add_keyword('r15')
|
342
|
21 self.add_rule('reg', ['r10'], lambda rhs: r10)
|
|
22 self.add_rule('reg', ['r11'], lambda rhs: r11)
|
|
23 self.add_rule('reg', ['r12'], lambda rhs: r12)
|
341
|
24 self.add_rule('reg', ['r13'], lambda rhs: r13)
|
|
25 self.add_rule('reg', ['r14'], lambda rhs: r14)
|
|
26 self.add_rule('reg', ['r15'], lambda rhs: r15)
|
342
|
27
|
|
28 # Instructions rules:
|
|
29 self.add_keyword('mov')
|
341
|
30 self.add_instruction(['mov', 'reg', ',', 'reg'],
|
|
31 lambda rhs: Mov(rhs[1], rhs[3]))
|
342
|
32 self.add_instruction(['mov', 'imm16', ',', 'reg'],
|
|
33 lambda rhs: Mov(rhs[1], rhs[3]))
|
|
34
|
|
35 self.add_keyword('add')
|
|
36 self.add_instruction(['add', 'reg', ',', 'reg'],
|
|
37 lambda rhs: Add(rhs[1], rhs[3]))
|
|
38
|
341
|
39 self.add_keyword('reti')
|
342
|
40 self.add_instruction(['reti'], lambda rhs: Reti())
|
201
|
41
|
342
|
42
|
|
43
|
|
44 msp430target = Msp430Target()
|
|
45
|
201
|
46
|
199
|
47 # Target description for the MSP430 processor
|
|
48
|
|
49
|
342
|
50 msp430target.registers.append(r10)
|
201
|
51 msp430target.registers.append(r11)
|
|
52 msp430target.registers.append(r12)
|
|
53 msp430target.registers.append(r13)
|
|
54 msp430target.registers.append(r14)
|
|
55 msp430target.registers.append(r15)
|
|
56
|