Mercurial > lcfOS
comparison python/ppci/target/msp430/msp430.py @ 342:86b02c98a717 devel
Moved target directory
author | Windel Bouwman |
---|---|
date | Sat, 01 Mar 2014 15:40:31 +0100 |
parents | python/target/msp430.py@4d204f6f7d4e |
children | b4882ff0ed06 |
comparison
equal
deleted
inserted
replaced
341:4d204f6f7d4e | 342:86b02c98a717 |
---|---|
1 import struct | |
2 import types | |
3 from ..basetarget import Register, Instruction, Target | |
4 from ppci.asmnodes import ASymbol, ANumber | |
5 from ppci import CompilerError | |
6 from .registers import r10, r11, r12, r13, r14, r15 | |
7 from .instructions import Reti, Mov, Add | |
8 | |
9 # Create the target class (singleton): | |
10 | |
11 class Msp430Target(Target): | |
12 def __init__(self): | |
13 super().__init__('msp430') | |
14 | |
15 # Registers: | |
16 self.add_keyword('r10') | |
17 self.add_keyword('r11') | |
18 self.add_keyword('r12') | |
19 self.add_keyword('r13') | |
20 self.add_keyword('r14') | |
21 self.add_keyword('r15') | |
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) | |
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) | |
28 | |
29 # Instructions rules: | |
30 self.add_keyword('mov') | |
31 self.add_instruction(['mov', 'reg', ',', 'reg'], | |
32 lambda rhs: Mov(rhs[1], rhs[3])) | |
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 | |
40 self.add_keyword('reti') | |
41 self.add_instruction(['reti'], lambda rhs: Reti()) | |
42 | |
43 # Constants: | |
44 self.add_rule('imm32', ['val32'], lambda x: x[0].val) | |
45 self.add_rule('imm32', ['imm16'], lambda x: x[0]) | |
46 self.add_rule('imm16', ['val16'], lambda x: x[0].val) | |
47 self.add_rule('imm16', ['imm8'], lambda x: x[0]) | |
48 self.add_rule('imm8', ['val8'], lambda x: x[0].val) | |
49 self.add_rule('imm8', ['imm5'], lambda x: x[0]) | |
50 self.add_rule('imm5', ['val5'], lambda x: x[0].val) | |
51 self.add_rule('imm5', ['imm3'], lambda x: x[0]) | |
52 self.add_rule('imm3', ['val3'], lambda x: x[0].val) | |
53 | |
54 | |
55 msp430target = Msp430Target() | |
56 | |
57 | |
58 # Target description for the MSP430 processor | |
59 | |
60 | |
61 msp430target.registers.append(r10) | |
62 msp430target.registers.append(r11) | |
63 msp430target.registers.append(r12) | |
64 msp430target.registers.append(r13) | |
65 msp430target.registers.append(r14) | |
66 msp430target.registers.append(r15) | |
67 |