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