Mercurial > lcfOS
comparison python/ir/instruction.py @ 265:9e235f15372b
Test
author | Windel Bouwman |
---|---|
date | Fri, 09 Aug 2013 16:37:19 +0200 |
parents | f8b5da5784b8 |
children | 649884d9dc61 |
comparison
equal
deleted
inserted
replaced
264:f8b5da5784b8 | 265:9e235f15372b |
---|---|
283 assert tfrom is self.target | 283 assert tfrom is self.target |
284 self.target = tto | 284 self.target = tto |
285 | 285 |
286 | 286 |
287 class ConditionalBranch(Terminator): | 287 class ConditionalBranch(Terminator): |
288 def __init__(self, a, cond, b, lab1, lab2): | 288 def __init__(self, a, cond, b, lab1, lab2): |
289 super().__init__() | 289 super().__init__() |
290 self.a = a | 290 self.a = a |
291 assert type(a) is Value | 291 assert type(a) is Value |
292 self.cond = cond | 292 self.cond = cond |
293 assert cond in ['==', '<', '>'] | 293 assert cond in ['==', '<', '>'] |
298 assert type(lab1) is BasicBlock | 298 assert type(lab1) is BasicBlock |
299 self.lab1 = lab1 | 299 self.lab1 = lab1 |
300 assert type(lab2) is BasicBlock | 300 assert type(lab2) is BasicBlock |
301 self.lab2 = lab2 | 301 self.lab2 = lab2 |
302 | 302 |
303 def __repr__(self): | 303 def __repr__(self): |
304 return 'IF {0} {1} {2} THEN {3} ELSE {4}'.format(self.a, self.cond, self.b, self.lab1, self.lab2) | 304 return 'IF {0} {1} {2} THEN {3} ELSE {4}'.format(self.a, self.cond, self.b, self.lab1, self.lab2) |
305 def getTargets(self): | 305 |
306 return [self.lab1, self.lab2] | 306 def getTargets(self): |
307 | 307 return [self.lab1, self.lab2] |
308 def changeTarget(self, tfrom, tto): | 308 |
309 def changeTarget(self, tfrom, tto): | |
309 assert tfrom is self.lab1 or tfrom is self.lab2 | 310 assert tfrom is self.lab1 or tfrom is self.lab2 |
310 if tfrom is self.lab1: | 311 if tfrom is self.lab1: |
311 self.lab1 = tto | 312 self.lab1 = tto |
312 elif tfrom is self.lab2: | 313 elif tfrom is self.lab2: |
313 self.lab2 = tto | 314 self.lab2 = tto |