Mercurial > lcfOS
diff python/target.py @ 201:d5debbfc0200
Added all 27 core instructions of msp430
author | Windel Bouwman |
---|---|
date | Thu, 13 Jun 2013 00:07:28 +0200 |
parents | 5e391d9a3381 |
children | f22b431f4113 |
line wrap: on
line diff
--- a/python/target.py Sun Jun 09 16:06:49 2013 +0200 +++ b/python/target.py Thu Jun 13 00:07:28 2013 +0200 @@ -15,14 +15,21 @@ self.name = name class Instruction: - def __init__(self, opcode): - self.opcode = opcode + def encode(self): + raise NotImplementedError('TODO') class Target: - def __init__(self): + def __init__(self, name, desc=''): + self.name = name + self.desc = desc self.registers = [] self.instructions = [] + def instruction(self, cls): + """ Decorator function that registers an instruction to this target """ + self.instructions.append(cls) + return cls + def mapOperand(self, operand): """ Try to map an operand to a target type """ if type(operand) is ASymbol: @@ -32,8 +39,7 @@ regs[r.name] = r if operand.name in regs: return regs[operand.name] - else: - return + raise CompilerError('Cannot map {0}'.format(operand)) def mapInstruction(self, vi): """ Map ast tree to real instruction for this target """ @@ -47,5 +53,5 @@ if ic.mnemonic == vi.opcode and ic.operands == optypes: ri = ic(*rops) return ri - raise CompilerError('No suitable instruction found') + raise CompilerError('No suitable instruction found for "{0}"'.format(vi))