diff python/ir/basicblock.py @ 173:c1d2b6b9f9a7

Rework into passes
author Windel Bouwman
date Fri, 19 Apr 2013 12:42:21 +0200
parents 3eb9b9e2958d
children 3eb06f5fb987
line wrap: on
line diff
--- a/python/ir/basicblock.py	Thu Apr 04 17:58:37 2013 +0200
+++ b/python/ir/basicblock.py	Fri Apr 19 12:42:21 2013 +0200
@@ -5,9 +5,19 @@
       self.name = name
       self.instructions = []
    def __repr__(self):
-      return 'BB {0}'.format(self.name)
-   def addIns(self, i):
+      return 'BasicBlock {0}'.format(self.name)
+   def addInstruction(self, i):
+      i.parent = self
       self.instructions.append(i)
+   addIns = addInstruction
+   def replaceInstruction(self, i1, i2):
+      idx = self.instructions.index(i1)
+      i1.parent = None
+      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)
@@ -18,6 +28,13 @@
    def Empty(self):
       return len(self.instructions) == 0
    @property
-   def FirstIns(self):
+   def FirstInstruction(self):
       return self.instructions[0]
+   FirstIns = FirstInstruction
+   def getSuccessors(self):
+      if not self.Empty:
+         i = self.LastIns
+         return i.Targets
+      return []
+   Successors = property(getSuccessors)