comparison python/msp430.py @ 203:ca1ea402f6a1

Added some arm instructions
author Windel Bouwman
date Sat, 15 Jun 2013 19:13:05 +0200
parents f22b431f4113
children
comparison
equal deleted inserted replaced
202:f22b431f4113 203:ca1ea402f6a1
9 REGISTER_MODE = 1 9 REGISTER_MODE = 1
10 SYMBOLIC_MODE = 3 10 SYMBOLIC_MODE = 3
11 ABSOLUTE_MODE = 4 11 ABSOLUTE_MODE = 4
12 #TODO: add more modes! 12 #TODO: add more modes!
13 IMMEDIATE_MODE = 7 13 IMMEDIATE_MODE = 7
14
15
16
17 # Add a custom operand mapping method:
18 def mapOp(self, operand):
19 if type(operand) is ASymbol:
20 # try to map to register:
21 regs = {}
22 for r in self.registers:
23 regs[r.name] = r
24 if operand.name in regs:
25 reg = regs[operand.name]
26 return MSP430Operand(REGISTER_MODE, reg.num)
27 elif type(operand) is ANumber:
28 # Immediate mode:
29 return MSP430Operand(IMMEDIATE_MODE, operand.number)
30 raise CompilerError('Cannot map {0}'.format(operand))
31
32 msp430target.mapOperand = types.MethodType(mapOp, msp430target)
33 14
34 # Target description for the MSP430 processor 15 # Target description for the MSP430 processor
35 16
36 class MSP430Reg(Register): 17 class MSP430Reg(Register):
37 def __init__(self, num, name): 18 def __init__(self, num, name):
81 raise CompilerError('Cannot use immediate mode for destination operand') 62 raise CompilerError('Cannot use immediate mode for destination operand')
82 def extraBytes(self): 63 def extraBytes(self):
83 if self.mode == IMMEDIATE_MODE: 64 if self.mode == IMMEDIATE_MODE:
84 return pack_ins(self.param) 65 return pack_ins(self.param)
85 return bytes() 66 return bytes()
86 67
68 @classmethod
69 def Create(cls, vop):
70 if type(vop) is ASymbol:
71 # try to map to register:
72 regs = {}
73 for r in msp430target.registers:
74 regs[r.name] = r
75 if vop.name in regs:
76 reg = regs[vop.name]
77 return cls(REGISTER_MODE, reg.num)
78 elif type(vop) is ANumber:
79 # Immediate mode:
80 return cls(IMMEDIATE_MODE, vop.number)
87 81
88 def pack_ins(h): 82 def pack_ins(h):
89 return struct.pack('<H', h) 83 return struct.pack('<H', h)
90 84
91 class MSP430Instruction(Instruction): 85 class MSP430Instruction(Instruction):