171
|
1
|
|
2 class BasicBlock:
|
219
|
3 """ Uninterrupted sequence of instructions. """
|
|
4 def __init__(self, name):
|
239
|
5 self.name = name
|
|
6 self.instructions = []
|
|
7
|
219
|
8 def __repr__(self):
|
239
|
9 return 'BasicBlock {0}'.format(self.name)
|
|
10
|
219
|
11 def addInstruction(self, i):
|
239
|
12 i.parent = self
|
|
13 self.instructions.append(i)
|
205
|
14
|
219
|
15 def replaceInstruction(self, i1, i2):
|
239
|
16 idx = self.instructions.index(i1)
|
|
17 i1.parent = None
|
|
18 i1.delete()
|
|
19 i2.parent = self
|
|
20 self.instructions[idx] = i2
|
205
|
21
|
219
|
22 def removeInstruction(self, i):
|
239
|
23 i.parent = None
|
252
|
24 i.delete()
|
239
|
25 self.instructions.remove(i)
|
205
|
26
|
219
|
27 def getInstructions(self):
|
205
|
28 return self.instructions
|
243
|
29 Instructions = property(getInstructions)
|
205
|
30
|
219
|
31 def getLastIns(self):
|
239
|
32 return self.instructions[-1]
|
219
|
33 LastInstruction = property(getLastIns)
|
239
|
34
|
219
|
35 @property
|
|
36 def Empty(self):
|
239
|
37 return len(self.instructions) == 0
|
|
38
|
219
|
39 @property
|
|
40 def FirstInstruction(self):
|
239
|
41 return self.instructions[0]
|
219
|
42
|
|
43 def getSuccessors(self):
|
243
|
44 if not self.Empty:
|
|
45 i = self.LastInstruction
|
|
46 return i.Targets
|
|
47 return []
|
219
|
48 Successors = property(getSuccessors)
|
|
49
|
|
50 def getPredecessors(self):
|
239
|
51 preds = []
|
|
52 for bb in self.parent.BasicBlocks:
|
|
53 if self in bb.Successors:
|
|
54 preds.append(bb)
|
|
55 return preds
|
219
|
56 Predecessors = property(getPredecessors)
|
171
|
57
|
239
|
58 def check(self):
|
|
59 for ins in self.Instructions:
|
|
60 ins.check()
|
|
61
|