comparison python/target.py @ 203:ca1ea402f6a1

Added some arm instructions
author Windel Bouwman
date Sat, 15 Jun 2013 19:13:05 +0200
parents f22b431f4113
children d77cb5962cc5
comparison
equal deleted inserted replaced
202:f22b431f4113 203:ca1ea402f6a1
1 from asmnodes import ASymbol, AInstruction 1 from asmnodes import ASymbol, AInstruction, ALabel
2 from ppci import CompilerError 2 from ppci import CompilerError
3 3
4 """ 4 """
5 Base classes for defining a target 5 Base classes for defining a target
6 """ 6 """
43 if operand.name in regs: 43 if operand.name in regs:
44 return regs[operand.name] 44 return regs[operand.name]
45 raise CompilerError('Cannot map {0}'.format(operand)) 45 raise CompilerError('Cannot map {0}'.format(operand))
46 46
47 def mapInstruction(self, vi): 47 def mapInstruction(self, vi):
48 assert type(vi) is AInstruction
48 """ Map ast tree to real instruction for this target """ 49 """ Map ast tree to real instruction for this target """
49 50
50 # map to real operands: 51 # map to real operands:
51 rops = tuple(map(self.mapOperand, vi.operands))
52 optypes = tuple(map(type, rops))
53 52
54 # look for a suitable instruction 53 # look for a suitable instruction
55 for ic in self.instructions: 54 for ic in self.instructions:
56 if ic.mnemonic == vi.opcode and ic.operands == optypes: 55 if ic.mnemonic == vi.mnemonic and len(ic.operands) == len(vi.operands):
57 ri = ic(*rops) 56 # Try to map operands to the correct operand types:
58 return ri 57 rops = [roptype.Create(vop) for roptype, vop in zip(ic.operands, vi.operands)]
58
59 # Check if we succeeded:
60 optypes = tuple(map(type, rops))
61 if ic.operands == optypes:
62 return ic(*rops)
59 raise CompilerError('No suitable instruction found for "{0}"'.format(vi)) 63 raise CompilerError('No suitable instruction found for "{0}"'.format(vi))
60 64