annotate python/asmnodes.py @ 208:4cb47d80fd1f

Added zcc test
author Windel Bouwman
date Sat, 29 Jun 2013 10:06:58 +0200
parents 6c6bf8890d8a
children 1c7364bd74c7
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):
203
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 201
diff changeset
15 def __init__(self, mnemonic, operands):
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 201
diff changeset
16 self.mnemonic = mnemonic
200
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))
203
ca1ea402f6a1 Added some arm instructions
Windel Bouwman
parents: 201
diff changeset
20 return '{0} {1}'.format(self.mnemonic, ops)
200
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):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
39 def __init__(self, operation, arg):
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
40 self.operation = operation
200
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):
206
6c6bf8890d8a Added push and pop encodings
Windel Bouwman
parents: 203
diff changeset
43 return '{0} {1}'.format(self.operation, self.arg)
200
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