Mercurial > lcfOS
view python/ir/basicblock.py @ 251:6ed3d3a82a63
Added another c3 example. First import attempt
author | Windel Bouwman |
---|---|
date | Mon, 29 Jul 2013 20:23:13 +0200 |
parents | ef683881c64e |
children | c4370696ccc7 |
line wrap: on
line source
class BasicBlock: """ Uninterrupted sequence of instructions. """ def __init__(self, name): self.name = name self.instructions = [] def __repr__(self): return 'BasicBlock {0}'.format(self.name) def addInstruction(self, i): i.parent = self self.instructions.append(i) def replaceInstruction(self, i1, i2): idx = self.instructions.index(i1) i1.parent = None i1.delete() i2.parent = self self.instructions[idx] = i2 def removeInstruction(self, i): i.parent = None self.instructions.remove(i) def getInstructions(self): return self.instructions Instructions = property(getInstructions) def getLastIns(self): return self.instructions[-1] LastInstruction = property(getLastIns) @property def Empty(self): return len(self.instructions) == 0 @property def FirstInstruction(self): return self.instructions[0] def getSuccessors(self): if not self.Empty: i = self.LastInstruction return i.Targets return [] Successors = property(getSuccessors) def getPredecessors(self): preds = [] for bb in self.parent.BasicBlocks: if self in bb.Successors: preds.append(bb) return preds Predecessors = property(getPredecessors) def check(self): for ins in self.Instructions: ins.check()