comparison 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
comparison
equal deleted inserted replaced
229:51d5ed1bd503 230:88a1e0baef65
1 from .basicblock import BasicBlock 1 from .basicblock import BasicBlock
2 2
3 class Function: 3 class Function:
4 def __init__(self, name): 4 def __init__(self, name):
5 self.name = name 5 self.name = name
6 self.bbs = [] 6 self.bbs = []
7 self.entry = None 7 self.entry = None
8 8
9 def __repr__(self): 9 def __repr__(self):
10 return 'Function {0}'.format(self.name) 10 return 'Function {0}'.format(self.name)
11 11
12 def addBB(self, bb): 12 def addBB(self, bb):
13 self.bbs.append(bb) 13 self.bbs.append(bb)
14 bb.parent = self 14 bb.parent = self
15 addBasicBlock = addBB 15 addBasicBlock = addBB
16 16
17 def removeBasicBlock(self, bb): 17 def removeBasicBlock(self, bb):
18 self.bbs.remove(bb) 18 self.bbs.remove(bb)
19 bb.parent = None 19 bb.parent = None
20 20
21 def getBBs(self): 21 def getBBs(self):
22 return self.bbs 22 return self.bbs
23 BasicBlocks = property(getBBs) 23
24 def findBasicBlock(self, name):
25 for bb in self.bbs:
26 if bb.name == name:
27 return bb
28 raise KeyError(name)
29
30 BasicBlocks = property(getBBs)
24 31
25 32