annotate python/ppci/core/instruction.py @ 118:db8aafe00d27

Added elf file read scripts
author Windel Bouwman
date Sat, 12 Jan 2013 09:39:23 +0100
parents 9e552d34bd60
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