annotate python/ir/instruction.py @ 163:8104fc8b5e90

Added visitor to c3
author Windel Bouwman
date Mon, 18 Mar 2013 20:13:57 +0100
parents 10330be89bc2
children 4348da5ca307
rev   line source
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
1
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
2 class Instruction:
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
3 """ Base class for all instructions. """
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
4 pass
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
5
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
6 # Function calling:
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
7 class CallInstruction(Instruction):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
8 def __init__(self, callee, arguments):
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
9 super().__init__()
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
10 self.callee = callee
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
11 self.arguments = arguments
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
12 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
13 return 'CALL {0}'.format(self.callee)
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
14
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
15 class RetInstruction(Instruction):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
16 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
17 return 'RET'
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
18
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
19 class BinaryOperator(Instruction):
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
20 def __init__(self, name, operation, value1, value2):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
21 assert value1
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
22 assert value2
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
23 #print('operation is in binops:', operation in BinOps)
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
24 # Check types of the two operands:
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
25 self.name = name
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
26 self.value1 = value1
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
27 self.value2 = value2
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
28 self.operation = operation
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
29 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
30 return '{0} = {1} {2}, {3}'.format(self.name, self.operation, self.value1, self.value2)
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
31
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
32 class LoadInstruction(Instruction):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
33 def __init__(self, name, value):
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
34 self.value = value
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
35 self.name = name
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
36 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
37 return 'load {0} = {1}'.format(self.name, self.value)
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
38
160
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
39 class StoreInstruction(Instruction):
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
40 def __init__(self, name, value):
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
41 self.name = name
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
42 self.value = value
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
43 def __repr__(self):
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
44 return 'store {0}'.format(self.name)
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
45
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
46 class BranchInstruction(Instruction):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
47 def __init__(self, t1, t2):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
48 self.t1 = t1
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
49 self.t2 = t2
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
50 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
51 return 'BRANCH {0}'.format(self.t1)