172
|
1 from .basicblock import BasicBlock
|
|
2
|
|
3 class Function:
|
230
|
4 def __init__(self, name):
|
172
|
5 self.name = name
|
|
6 self.bbs = []
|
|
7 self.entry = None
|
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):
|
|
22 return self.bbs
|
205
|
23
|
230
|
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)
|
172
|
31
|
253
|
32 @property
|
|
33 def Entry(self):
|
|
34 return self.BasicBlocks[0]
|
|
35
|
239
|
36 def check(self):
|
|
37 for bb in self.BasicBlocks:
|
|
38 bb.check()
|
253
|
39
|
|
40 def call(self, *args):
|
|
41 print(args)
|
|
42 varmap = {}
|
|
43 bb = self.Entry
|
|
44 ip = 0
|
|
45 while True:
|
|
46 i = bb.Instructions[ip]
|
|
47 ip += 1
|
|
48 print(i)
|
|
49 return
|
|
50
|
|
51
|