annotate python/ppci/core/instruction.py @ 110:9e552d34bd60

Work on compiler
author Windel Bouwman
date Fri, 04 Jan 2013 15:25:58 +0100
parents ed230e947dc6
children
rev   line source
99
windel
parents: 95
diff changeset
1
71
5351594349b0 Moved error to core
windel
parents: 70
diff changeset
2 from .value import Value
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
3
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
4 def Enum(**enums):
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
5 return type('Enum', (), enums)
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
6
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
7 class Instruction(Value):
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
8 """ Base class for all instructions. """
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
9 pass
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
10
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
11 class CallInstruction(Instruction):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
12 def __init__(self, callee, arguments):
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
13 super().__init__()
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
14 self.callee = callee
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
15 self.arguments = arguments
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
16
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
diff changeset
17 BinOps = Enum(Add=1, Sub=2, Mul=3)
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
18
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
19 class BinaryOperator(Instruction):
104
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
20 def __init__(self, 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
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 104
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:
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
25 self.value1 = value1
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
26 self.value2 = value2
ed230e947dc6 Added hexviewer
windel
parents: 99
diff changeset
27 self.operation = operation
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
28
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
29 class LoadInstruction(Instruction):
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
30 def __init__(self, ptr, name, insertBefore):
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
31 self.setName(name)
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
32