comparison python/ir/instruction.py @ 204:de3a68f677a5

Added long comment to c3 parser
author Windel Bouwman
date Fri, 21 Jun 2013 15:01:08 +0200
parents 460db5669efa
children d77cb5962cc5
comparison
equal deleted inserted replaced
203:ca1ea402f6a1 204:de3a68f677a5
14 return len(self.used_by) > 0 14 return len(self.used_by) > 0
15 15
16 class Use: 16 class Use:
17 def __init__(self, user, val): 17 def __init__(self, user, val):
18 self.user = user 18 self.user = user
19 assert type(val) is Value
19 self.val = val 20 self.val = val
20 self.val.used_by.append(self.user) 21 self.val.used_by.append(self.user)
21 def delete(self): 22 def delete(self):
22 self.val.used_by.remove(self.user) 23 self.val.used_by.remove(self.user)
23 24
97 return '{0} = alloc'.format(self.value) 98 return '{0} = alloc'.format(self.value)
98 99
99 class ImmLoad(Instruction): 100 class ImmLoad(Instruction):
100 def __init__(self, target, value): 101 def __init__(self, target, value):
101 super().__init__() 102 super().__init__()
103 assert type(target) is Value
102 self.target = target 104 self.target = target
103 self.value = value 105 self.value = value
104 self.addDef(target) 106 self.addDef(target)
105 def __repr__(self): 107 def __repr__(self):
106 return '{0} = {1}'.format(self.target, self.value) 108 return '{0} = {1}'.format(self.target, self.value)
109 class BinaryOperator(Instruction): 111 class BinaryOperator(Instruction):
110 def __init__(self, result, operation, value1, value2): 112 def __init__(self, result, operation, value1, value2):
111 super().__init__() 113 super().__init__()
112 #print('operation is in binops:', operation in BinOps) 114 #print('operation is in binops:', operation in BinOps)
113 # Check types of the two operands: 115 # Check types of the two operands:
116 assert type(value1) is Value
117 assert type(value2) is Value
114 self.result = result 118 self.result = result
115 self.addDef(result) 119 self.addDef(result)
116 self.value1 = value1 120 self.value1 = value1
117 self.value2 = value2 121 self.value2 = value2
118 self.addUse(value1) 122 self.addUse(value1)