annotate python/ppci/target/msp430/msp430.py @ 398:c0d9837acde8

x86 target refactor
author Windel Bouwman
date Thu, 29 May 2014 12:13:37 +0200
parents 6df89163e114
children
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
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
4 from ppci import CompilerError
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
5 from .registers import r10, r11, r12, r13, r14, r15
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
6 from .instructions import Reti, Mov, Add
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
7 from ...assembler import BaseAssembler
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
8
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
9
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
10 # Create the target class (singleton):
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
11
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
12 class Msp430Assembler(BaseAssembler):
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
13 def __init__(self, target):
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
14 super().__init__(target)
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
15 self.make_parser()
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
16
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
17
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
18 class Msp430Target(Target):
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
19 def __init__(self):
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
20 super().__init__('msp430')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
21
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
22 # Registers:
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
23 self.add_keyword('r10')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
24 self.add_keyword('r11')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
25 self.add_keyword('r12')
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
26 self.add_keyword('r13')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
27 self.add_keyword('r14')
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
28 self.add_keyword('r15')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
29 self.add_rule('reg', ['r10'], lambda rhs: r10)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
30 self.add_rule('reg', ['r11'], lambda rhs: r11)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
31 self.add_rule('reg', ['r12'], lambda rhs: r12)
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
32 self.add_rule('reg', ['r13'], lambda rhs: r13)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
33 self.add_rule('reg', ['r14'], lambda rhs: r14)
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
34 self.add_rule('reg', ['r15'], lambda rhs: r15)
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
35
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
36 # Instructions rules:
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
37 self.add_keyword('mov')
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
38 self.add_instruction(['mov', 'reg', ',', 'reg'],
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
39 lambda rhs: Mov(rhs[1], rhs[3]))
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
40 self.add_instruction(['mov', 'imm16', ',', 'reg'],
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
41 lambda rhs: Mov(rhs[1], rhs[3]))
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
42
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
43 self.add_keyword('add')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
44 self.add_instruction(['add', 'reg', ',', 'reg'],
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
45 lambda rhs: Add(rhs[1], rhs[3]))
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
46
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 334
diff changeset
47 self.add_keyword('reti')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
48 self.add_instruction(['reti'], lambda rhs: Reti())
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
49
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 346
diff changeset
50 self.assembler = Msp430Assembler(self)
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
51
398
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 381
diff changeset
52 self.registers.append(r10)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 381
diff changeset
53 self.registers.append(r11)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 381
diff changeset
54 self.registers.append(r12)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 381
diff changeset
55 self.registers.append(r13)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 381
diff changeset
56 self.registers.append(r14)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 381
diff changeset
57 self.registers.append(r15)
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
58
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
59
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
60
199
a690473b79e2 Added msp430 target
Windel Bouwman
parents:
diff changeset
61 # Target description for the MSP430 processor
a690473b79e2 Added msp430 target
Windel Bouwman
parents:
diff changeset
62
a690473b79e2 Added msp430 target
Windel Bouwman
parents:
diff changeset
63
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
64