annotate python/asmnodes.py @ 228:7f18ed9b6b7e

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