diff python/ir/function.py @ 230:88a1e0baef65

Added some tests for IR-code
author Windel Bouwman
date Sat, 13 Jul 2013 19:53:44 +0200
parents d77cb5962cc5
children 63bb40758066
line wrap: on
line diff
--- a/python/ir/function.py	Sat Jul 13 11:13:01 2013 +0200
+++ b/python/ir/function.py	Sat Jul 13 19:53:44 2013 +0200
@@ -1,25 +1,32 @@
 from .basicblock import BasicBlock
 
 class Function:
-   def __init__(self, name):
+    def __init__(self, name):
       self.name = name
       self.bbs = []
       self.entry = None
 
-   def __repr__(self):
-      return 'Function {0}'.format(self.name)
+    def __repr__(self):
+        return 'Function {0}'.format(self.name)
 
-   def addBB(self, bb):
-      self.bbs.append(bb)
-      bb.parent = self
-   addBasicBlock = addBB
+    def addBB(self, bb):
+        self.bbs.append(bb)
+        bb.parent = self
+    addBasicBlock = addBB
 
-   def removeBasicBlock(self, bb):
-      self.bbs.remove(bb)
-      bb.parent = None
+    def removeBasicBlock(self, bb):
+        self.bbs.remove(bb)
+        bb.parent = None
+
+    def getBBs(self):
+        return self.bbs
 
-   def getBBs(self):
-      return self.bbs
-   BasicBlocks = property(getBBs)
+    def findBasicBlock(self, name):
+        for bb in self.bbs:
+            if bb.name == name:
+                return bb
+        raise KeyError(name)
+
+    BasicBlocks = property(getBBs)