annotate 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
rev   line source
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
1 import struct
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
2 import types
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
3 from ..basetarget import Register, Instruction, Target
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 292
diff changeset
4 from ppci.asmnodes import ASymbol, ANumber
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
5 from ppci import CompilerError
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
6 from .registers import r10, r11, r12, r13, r14, r15
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
7 from .instructions import Reti, Mov, Add
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
8
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
9 # Create the target class (singleton):
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
10
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
11 class Msp430Target(Target):
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
12 def __init__(self):
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
13 super().__init__('msp430')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
14
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
15 # Registers:
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
16 self.add_keyword('r10')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
17 self.add_keyword('r11')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
18 self.add_keyword('r12')
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
19 self.add_keyword('r13')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
20 self.add_keyword('r14')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
21 self.add_keyword('r15')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
22 self.add_rule('reg', ['r10'], lambda rhs: r10)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
23 self.add_rule('reg', ['r11'], lambda rhs: r11)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
24 self.add_rule('reg', ['r12'], lambda rhs: r12)
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
25 self.add_rule('reg', ['r13'], lambda rhs: r13)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
26 self.add_rule('reg', ['r14'], lambda rhs: r14)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
27 self.add_rule('reg', ['r15'], lambda rhs: r15)
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
28
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
29 # Instructions rules:
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
30 self.add_keyword('mov')
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
31 self.add_instruction(['mov', 'reg', ',', 'reg'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
32 lambda rhs: Mov(rhs[1], rhs[3]))
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
33 self.add_instruction(['mov', 'imm16', ',', 'reg'],
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
34 lambda rhs: Mov(rhs[1], rhs[3]))
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
35
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
36 self.add_keyword('add')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
37 self.add_instruction(['add', 'reg', ',', 'reg'],
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
38 lambda rhs: Add(rhs[1], rhs[3]))
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
39
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
40 self.add_keyword('reti')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
41 self.add_instruction(['reti'], lambda rhs: Reti())
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
42
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
43 # Constants:
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
44 self.add_rule('imm32', ['val32'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
45 self.add_rule('imm32', ['imm16'], lambda x: x[0])
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
46 self.add_rule('imm16', ['val16'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
47 self.add_rule('imm16', ['imm8'], lambda x: x[0])
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
48 self.add_rule('imm8', ['val8'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
49 self.add_rule('imm8', ['imm5'], lambda x: x[0])
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
50 self.add_rule('imm5', ['val5'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
51 self.add_rule('imm5', ['imm3'], lambda x: x[0])
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
52 self.add_rule('imm3', ['val3'], lambda x: x[0].val)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
53
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
54
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
55 msp430target = Msp430Target()
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
56
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
57
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents:
diff changeset
58 # Target description for the MSP430 processor
a690473b79e2 Added msp430 target
Windel Bouwman
parents:
diff changeset
59
a690473b79e2 Added msp430 target
Windel Bouwman
parents:
diff changeset
60
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
61 msp430target.registers.append(r10)
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
62 msp430target.registers.append(r11)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
63 msp430target.registers.append(r12)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
64 msp430target.registers.append(r13)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
65 msp430target.registers.append(r14)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
66 msp430target.registers.append(r15)
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
67