annotate python/ir/instruction.py @ 155:b28a11c01dbe

Simplified IR classes
author Windel Bouwman
date Sun, 03 Mar 2013 13:20:03 +0100
parents 4e79484a9d47
children 8f3924b6076e
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
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
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
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
27 class LoadInstruction(Instruction):
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
28 def __init__(self, ptr, name, insertBefore):
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
29 self.setName(name)
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
30