annotate python/ir/instruction.py @ 157:8f3924b6076e

Added some code generator things
author Windel Bouwman
date Sun, 03 Mar 2013 18:14:35 +0100
parents b28a11c01dbe
children 9683a4cd848f
rev   line source
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
1
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
2 def Enum(**enums):
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
3 return type('Enum', (), enums)
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
4
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
5 class Instruction:
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
6 """ Base class for all instructions. """
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
7 pass
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
8
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
9 class CallInstruction(Instruction):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
10 def __init__(self, callee, arguments):
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
11 super().__init__()
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
12 self.callee = callee
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
13 self.arguments = arguments
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
14
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
15 BinOps = Enum(Add=1, Sub=2, Mul=3)
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
16
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
17 class BinaryOperator(Instruction):
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
18 def __init__(self, operation, value1, value2):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
19 assert value1
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
20 assert value2
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
21 #print('operation is in binops:', operation in BinOps)
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
22 # Check types of the two operands:
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
23 self.value1 = value1
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
24 self.value2 = value2
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
25 self.operation = operation
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
26
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
27 class AddInstruction(BinaryOperator):
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
28 def __init__(self, a, b):
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
29 super().__init__('add', a, b)
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
30
157
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
31 class ImmLoadInstruction(Instruction):
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
32 def __init__(self, value):
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
33 self.value = value
8f3924b6076e Added some code generator things
Windel Bouwman
parents: 155
diff changeset
34