annotate python/asmnodes.py @ 272:e64bae57cda8

refactor ir
author Windel Bouwman
date Sat, 31 Aug 2013 17:58:54 +0200
parents 83781bd10fdb
children
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
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 206
diff changeset
14
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
15 class AInstruction(ANode):
203
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 201
diff changeset
16 def __init__(self, mnemonic, operands):
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 201
diff changeset
17 self.mnemonic = mnemonic
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
18 self.operands = operands
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
19 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
20 ops = ', '.join(map(str, self.operands))
203
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 201
diff changeset
21 return '{0} {1}'.format(self.mnemonic, ops)
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
22
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
23 class AExpression(ANode):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
24 def __add__(self, other):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
25 assert isinstance(other, AExpression)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
26 return ABinop('+', self, other)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
27 def __mul__(self, other):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
28 assert isinstance(other, AExpression)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
29 return ABinop('*', self, other)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
30
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
31 class ABinop(AExpression):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
32 def __init__(self, op, arg1, arg2):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
33 self.op = op
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
34 self.arg1 = arg1
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
35 self.arg2 = arg2
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
36 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
37 return '{0} {1} {2}'.format(self.op, self.arg1, self.arg2)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
38
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
39 class AUnop(AExpression):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
40 def __init__(self, operation, arg):
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
41 self.operation = operation
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
42 self.arg = arg
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
43 def __repr__(self):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
44 return '{0} {1}'.format(self.operation, self.arg)
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
45
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
46 class ASymbol(AExpression):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
47 def __init__(self, name):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
48 self.name = name
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
49 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
50 return self.name
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
51
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
52 class ANumber(AExpression):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
53 def __init__(self, n):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
54 assert type(n) is int
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
55 self.n = n
201
d5debbfc0200 Added all 27 core instructions of msp430
Windel Bouwman
parents: 200
diff changeset
56 self.number = n
200
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
57 def __repr__(self):
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
58 return '{0}'.format(self.n)
5e391d9a3381 Split off asm nodes
Windel Bouwman
parents:
diff changeset
59