comparison python/ir/function.py @ 269:5f8c04a8d26b

Towards better modularity
author Windel Bouwman
date Sun, 18 Aug 2013 17:43:18 +0200
parents 5ec7580976d9
children cdc76d183bcc
comparison
equal deleted inserted replaced
268:5ec7580976d9 269:5f8c04a8d26b
1 from .basicblock import Block 1 from .basicblock import Block
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.entry = Block('entry') 6 self.entry = Block('{}_entry'.format(name))
7 self.epiloog = Block('{}_epilog'.format(name))
7 8
8 def __repr__(self): 9 def __repr__(self):
9 return 'Function {0}'.format(self.name) 10 return 'Function {0}'.format(self.name)
10 11
11 def addBB(self, bb): 12 def addBB(self, bb):
24 b = worklist.pop() 25 b = worklist.pop()
25 for sb in b.Successors: 26 for sb in b.Successors:
26 if sb not in bbs: 27 if sb not in bbs:
27 bbs.append(sb) 28 bbs.append(sb)
28 worklist.append(sb) 29 worklist.append(sb)
30 bbs.remove(self.entry)
31 bbs.remove(self.epiloog)
32 bbs.insert(0, self.entry)
33 bbs.append(self.epiloog)
29 return bbs 34 return bbs
30 35
31 def findBasicBlock(self, name): 36 def findBasicBlock(self, name):
32 for bb in self.bbs: 37 for bb in self.bbs:
33 if bb.name == name: 38 if bb.name == name:
36 41
37 BasicBlocks = property(getBBs) 42 BasicBlocks = property(getBBs)
38 43
39 @property 44 @property
40 def Entry(self): 45 def Entry(self):
41 return self.BasicBlocks[0] 46 return self.entry
42 47
43 def check(self): 48 def check(self):
44 for bb in self.BasicBlocks: 49 for bb in self.BasicBlocks:
45 bb.check() 50 bb.check()
46 51