110
|
1
|
155
|
2 class Instruction:
|
104
|
3 """ Base class for all instructions. """
|
70
|
4 pass
|
|
5
|
158
|
6 # Function calling:
|
70
|
7 class CallInstruction(Instruction):
|
110
|
8 def __init__(self, callee, arguments):
|
|
9 super().__init__()
|
|
10 self.callee = callee
|
|
11 self.arguments = arguments
|
158
|
12 def __repr__(self):
|
|
13 return 'CALL {0}'.format(self.callee)
|
110
|
14
|
158
|
15 class RetInstruction(Instruction):
|
|
16 def __repr__(self):
|
|
17 return 'RET'
|
70
|
18
|
|
19 class BinaryOperator(Instruction):
|
158
|
20 def __init__(self, name, operation, value1, value2):
|
110
|
21 assert value1
|
|
22 assert value2
|
157
|
23 #print('operation is in binops:', operation in BinOps)
|
104
|
24 # Check types of the two operands:
|
158
|
25 self.name = name
|
104
|
26 self.value1 = value1
|
|
27 self.value2 = value2
|
|
28 self.operation = operation
|
158
|
29 def __repr__(self):
|
|
30 return '{0} = {1} {2}, {3}'.format(self.name, self.operation, self.value1, self.value2)
|
70
|
31
|
158
|
32 class LoadInstruction(Instruction):
|
|
33 def __init__(self, name, value):
|
157
|
34 self.value = value
|
158
|
35 self.name = name
|
|
36 def __repr__(self):
|
|
37 return 'load {0} = {1}'.format(self.name, self.value)
|
157
|
38
|
160
|
39 class StoreInstruction(Instruction):
|
|
40 def __init__(self, name, value):
|
|
41 self.name = name
|
|
42 self.value = value
|
|
43 def __repr__(self):
|
|
44 return 'store {0}'.format(self.name)
|
|
45
|
158
|
46 class BranchInstruction(Instruction):
|
|
47 def __init__(self, t1, t2):
|
|
48 self.t1 = t1
|
|
49 self.t2 = t2
|
|
50 def __repr__(self):
|
|
51 return 'BRANCH {0}'.format(self.t1)
|