comparison python/ir/instruction.py @ 219:1fa3e0050b49

Expanded ad hoc code generator
author Windel Bouwman
date Sat, 06 Jul 2013 12:38:09 +0200
parents 07bfea4c1ed7
children 848c4b15fd0b
comparison
equal deleted inserted replaced
218:494828a7adf1 219:1fa3e0050b49
154 def __repr__(self): 154 def __repr__(self):
155 return '[{0}] = {1}'.format(self.location, self.value) 155 return '[{0}] = {1}'.format(self.location, self.value)
156 156
157 # Branching: 157 # Branching:
158 class Branch(Terminator): 158 class Branch(Terminator):
159 def __init__(self, target): 159 def __init__(self, target):
160 super().__init__() 160 super().__init__()
161 assert type(target) is BasicBlock 161 assert type(target) is BasicBlock
162 self.target = target 162 self.target = target
163 def __repr__(self): 163 def __repr__(self):
164 return 'BRANCH {0}'.format(self.target) 164 return 'BRANCH {0}'.format(self.target)
165 def getTargets(self): 165 def getTargets(self):
166 return [self.target] 166 return [self.target]
167 def changeTarget(self, tfrom, tto): 167 def changeTarget(self, tfrom, tto):
168 if tfrom is self.target: 168 assert tfrom is self.target
169 self.target = tto 169 self.target = tto
170 170
171 class ConditionalBranch(Terminator): 171 class ConditionalBranch(Terminator):
172 def __init__(self, a, cond, b, lab1, lab2): 172 def __init__(self, a, cond, b, lab1, lab2):
173 super().__init__() 173 super().__init__()
174 self.a = a 174 self.a = a
185 def __repr__(self): 185 def __repr__(self):
186 return 'IF {0} {1} {2} THEN {3} ELSE {4}'.format(self.a, self.cond, self.b, self.lab1, self.lab2) 186 return 'IF {0} {1} {2} THEN {3} ELSE {4}'.format(self.a, self.cond, self.b, self.lab1, self.lab2)
187 def getTargets(self): 187 def getTargets(self):
188 return [self.lab1, self.lab2] 188 return [self.lab1, self.lab2]
189 def changeTarget(self, tfrom, tto): 189 def changeTarget(self, tfrom, tto):
190 assert tfrom is self.lab1 or tfrom is self.lab2
190 if tfrom is self.lab1: 191 if tfrom is self.lab1:
191 self.lab1 = tto 192 self.lab1 = tto
192 if tfrom is self.lab2: 193 elif tfrom is self.lab2:
193 self.lab2 = tto 194 self.lab2 = tto
194 195
195 class PhiNode(Instruction): 196 class PhiNode(Instruction):
196 def __init__(self): 197 def __init__(self):
197 super().__init__() 198 super().__init__()