annotate python/ir/instruction.py @ 170:4348da5ca307

Cleanup of ir dir
author Windel Bouwman
date Fri, 29 Mar 2013 17:33:17 +0100
parents 10330be89bc2
children 3eb9b9e2958d
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
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
6 # Label:
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
7 class LabelInstruction(Instruction):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
8 def __init__(self, labid):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
9 self.labid = labid
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
10 def __repr__(self):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
11 return '{0}:'.format(self.labid)
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
12
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
13 # Function calling:
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
14 class CallInstruction(Instruction):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
15 def __init__(self, callee, arguments):
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
16 super().__init__()
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
17 self.callee = callee
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
18 self.arguments = arguments
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
19 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
20 return 'CALL {0}'.format(self.callee)
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
21
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
22 class RetInstruction(Instruction):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
23 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
24 return 'RET'
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
25
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
26 class MoveInstruction(Instruction):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
27 def __init__(self, name, value):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
28 self.name = name
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
29 self.value = value
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
30 def __repr__(self):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
31 return '{0} = {1}'.format(self.name, self.value)
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
32
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
33 class BinaryOperator(Instruction):
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
34 def __init__(self, name, operation, value1, value2):
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
35 #print('operation is in binops:', operation in BinOps)
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
36 # Check types of the two operands:
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
37 self.name = name
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
38 self.value1 = value1
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
39 self.value2 = value2
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
40 self.operation = operation
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
41 def __repr__(self):
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
42 return '{0} = {2} {1} {3}'.format(self.name, self.operation, self.value1, self.value2)
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
43
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
44 # Memory functions:
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
45 class LoadInstruction(Instruction):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
46 def __init__(self, name, value):
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
47 self.value = value
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
48 self.name = name
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
49 def __repr__(self):
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
50 return '{1} = [{0}]'.format(self.name, self.value)
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
51
160
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
52 class StoreInstruction(Instruction):
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
53 def __init__(self, name, value):
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
54 self.name = name
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
55 self.value = value
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
56 def __repr__(self):
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
57 return '[{0}] = {1}'.format(self.name, self.value)
160
10330be89bc2 Started from scratch with code edit
Windel Bouwman
parents: 158
diff changeset
58
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
59 class BranchInstruction(Instruction):
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
60 def __init__(self, target):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
61 self.t1 = target
158
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
62 def __repr__(self):
9683a4cd848f Added some functions for code generation
Windel Bouwman
parents: 157
diff changeset
63 return 'BRANCH {0}'.format(self.t1)
170
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
64
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
65 class IfInstruction(Instruction):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
66 def __init__(self, cond, lab1, lab2):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
67 self.cond = cond
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
68 self.lab1 = lab1
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
69 self.lab2 = lab2
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
70 def __repr__(self):
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
71 return 'IF {0} THEN {1} ELSE {2}'.format(self.cond, self.lab1, self.lab2)
4348da5ca307 Cleanup of ir dir
Windel Bouwman
parents: 160
diff changeset
72