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
|
|
24 self.instructions.remove(i)
|
205
|
25
|
219
|
26 def getInstructions(self):
|
205
|
27 return self.instructions
|
243
|
28 Instructions = property(getInstructions)
|
205
|
29
|
219
|
30 def getLastIns(self):
|
239
|
31 return self.instructions[-1]
|
219
|
32 LastInstruction = property(getLastIns)
|
239
|
33
|
219
|
34 @property
|
|
35 def Empty(self):
|
239
|
36 return len(self.instructions) == 0
|
|
37
|
219
|
38 @property
|
|
39 def FirstInstruction(self):
|
239
|
40 return self.instructions[0]
|
219
|
41
|
|
42 def getSuccessors(self):
|
243
|
43 if not self.Empty:
|
|
44 i = self.LastInstruction
|
|
45 return i.Targets
|
|
46 return []
|
219
|
47 Successors = property(getSuccessors)
|
|
48
|
|
49 def getPredecessors(self):
|
239
|
50 preds = []
|
|
51 for bb in self.parent.BasicBlocks:
|
|
52 if self in bb.Successors:
|
|
53 preds.append(bb)
|
|
54 return preds
|
219
|
55 Predecessors = property(getPredecessors)
|
171
|
56
|
239
|
57 def check(self):
|
|
58 for ins in self.Instructions:
|
|
59 ins.check()
|
|
60
|