268
|
1 from .basicblock import Block
|
172
|
2
|
|
3 class Function:
|
230
|
4 def __init__(self, name):
|
269
|
5 self.name = name
|
|
6 self.entry = Block('{}_entry'.format(name))
|
|
7 self.epiloog = Block('{}_epilog'.format(name))
|
205
|
8
|
230
|
9 def __repr__(self):
|
|
10 return 'Function {0}'.format(self.name)
|
205
|
11
|
230
|
12 def addBB(self, bb):
|
|
13 self.bbs.append(bb)
|
|
14 bb.parent = self
|
|
15 addBasicBlock = addBB
|
205
|
16
|
230
|
17 def removeBasicBlock(self, bb):
|
|
18 self.bbs.remove(bb)
|
|
19 bb.parent = None
|
|
20
|
|
21 def getBBs(self):
|
268
|
22 bbs = [self.entry]
|
|
23 worklist = [self.entry]
|
|
24 while worklist:
|
|
25 b = worklist.pop()
|
|
26 for sb in b.Successors:
|
|
27 if sb not in bbs:
|
|
28 bbs.append(sb)
|
|
29 worklist.append(sb)
|
269
|
30 bbs.remove(self.entry)
|
|
31 bbs.remove(self.epiloog)
|
|
32 bbs.insert(0, self.entry)
|
|
33 bbs.append(self.epiloog)
|
268
|
34 return bbs
|
205
|
35
|
230
|
36 def findBasicBlock(self, name):
|
|
37 for bb in self.bbs:
|
|
38 if bb.name == name:
|
|
39 return bb
|
|
40 raise KeyError(name)
|
|
41
|
|
42 BasicBlocks = property(getBBs)
|
172
|
43
|
253
|
44 @property
|
|
45 def Entry(self):
|
269
|
46 return self.entry
|
253
|
47
|
239
|
48 def check(self):
|
|
49 for bb in self.BasicBlocks:
|
|
50 bb.check()
|
253
|
51
|
|
52 def call(self, *args):
|
|
53 varmap = {}
|
|
54 bb = self.Entry
|
|
55 ip = 0
|
|
56 while True:
|
|
57 i = bb.Instructions[ip]
|
|
58 ip += 1
|
|
59 return
|
|
60
|
|
61
|