annotate 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
rev   line source
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
1
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
2 """ Assembler AST nodes """
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
3
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
4 class ANode:
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
5 def __eq__(self, other):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
6 return self.__repr__() == other.__repr__()
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
7
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
8 class ALabel(ANode):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
9 def __init__(self, name):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
10 self.name = name
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
11 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
12 return '{0}:'.format(self.name)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
13
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
14 class AInstruction(ANode):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
15 def __init__(self, opcode, operands):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
16 self.opcode = opcode
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
17 self.operands = operands
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
18 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
19 ops = ', '.join(map(str, self.operands))
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
20 return '{0} {1}'.format(self.opcode, ops)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
21
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
22 class AExpression(ANode):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
23 def __add__(self, other):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
24 assert isinstance(other, AExpression)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
25 return ABinop('+', self, other)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
26 def __mul__(self, other):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
27 assert isinstance(other, AExpression)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
28 return ABinop('*', self, other)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
29
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
30 class ABinop(AExpression):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
31 def __init__(self, op, arg1, arg2):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
32 self.op = op
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
33 self.arg1 = arg1
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
34 self.arg2 = arg2
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
35 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
36 return '{0} {1} {2}'.format(self.op, self.arg1, self.arg2)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
37
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
38 class AUnop(AExpression):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
39 def __init__(self, op, arg):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
40 self.op = op
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
41 self.arg = arg
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
42 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
43 return '{0} {1}'.format(self.op, self.arg)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
44
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
45 class ASymbol(AExpression):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
46 def __init__(self, name):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
47 self.name = name
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
48 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
49 return self.name
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
50
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
51 class ANumber(AExpression):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
52 def __init__(self, n):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
53 assert type(n) is int
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
54 self.n = n
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
55 self.number = n
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
56 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
57 return '{0}'.format(self.n)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
58