70
|
1
|
110
|
2 def Enum(**enums):
|
|
3 return type('Enum', (), enums)
|
|
4
|
155
|
5 class Instruction:
|
104
|
6 """ Base class for all instructions. """
|
70
|
7 pass
|
|
8
|
|
9 class CallInstruction(Instruction):
|
110
|
10 def __init__(self, callee, arguments):
|
|
11 super().__init__()
|
|
12 self.callee = callee
|
|
13 self.arguments = arguments
|
|
14
|
|
15 BinOps = Enum(Add=1, Sub=2, Mul=3)
|
70
|
16
|
|
17 class BinaryOperator(Instruction):
|
104
|
18 def __init__(self, operation, value1, value2):
|
110
|
19 assert value1
|
|
20 assert value2
|
|
21 print('operation is in binops:', operation in BinOps)
|
104
|
22 # Check types of the two operands:
|
|
23 self.value1 = value1
|
|
24 self.value2 = value2
|
|
25 self.operation = operation
|
70
|
26
|
|
27 class LoadInstruction(Instruction):
|
|
28 def __init__(self, ptr, name, insertBefore):
|
|
29 self.setName(name)
|
|
30
|