Mercurial > lcfOS
view python/asmnodes.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 | ca1ea402f6a1 |
line wrap: on
line source
""" Assembler AST nodes """ class ANode: def __eq__(self, other): return self.__repr__() == other.__repr__() class ALabel(ANode): def __init__(self, name): self.name = name def __repr__(self): return '{0}:'.format(self.name) class AInstruction(ANode): def __init__(self, opcode, operands): self.opcode = opcode self.operands = operands def __repr__(self): ops = ', '.join(map(str, self.operands)) return '{0} {1}'.format(self.opcode, ops) class AExpression(ANode): def __add__(self, other): assert isinstance(other, AExpression) return ABinop('+', self, other) def __mul__(self, other): assert isinstance(other, AExpression) return ABinop('*', self, other) class ABinop(AExpression): def __init__(self, op, arg1, arg2): self.op = op self.arg1 = arg1 self.arg2 = arg2 def __repr__(self): return '{0} {1} {2}'.format(self.op, self.arg1, self.arg2) class AUnop(AExpression): def __init__(self, op, arg): self.op = op self.arg = arg def __repr__(self): return '{0} {1}'.format(self.op, self.arg) class ASymbol(AExpression): def __init__(self, name): self.name = name def __repr__(self): return self.name class ANumber(AExpression): def __init__(self, n): assert type(n) is int self.n = n self.number = n def __repr__(self): return '{0}'.format(self.n)