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