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)
|
219
|
14 addIns = addInstruction
|
205
|
15
|
219
|
16 def replaceInstruction(self, i1, i2):
|
239
|
17 idx = self.instructions.index(i1)
|
|
18 i1.parent = None
|
|
19 i1.delete()
|
|
20 i2.parent = self
|
|
21 self.instructions[idx] = i2
|
205
|
22
|
219
|
23 def removeInstruction(self, i):
|
239
|
24 i.parent = None
|
|
25 self.instructions.remove(i)
|
205
|
26
|
219
|
27 def getInstructions(self):
|
205
|
28 return self.instructions
|
|
29
|
219
|
30 def setInstructions(self, ins):
|
174
|
31 for i in self.instructions:
|
|
32 i.parent = None
|
|
33 self.instructions = ins
|
|
34 for i in self.instructions:
|
|
35 i.parent = self
|
219
|
36 Instructions = property(getInstructions, setInstructions)
|
205
|
37
|
219
|
38 def getLastIns(self):
|
239
|
39 return self.instructions[-1]
|
219
|
40 LastInstruction = property(getLastIns)
|
239
|
41
|
219
|
42 @property
|
|
43 def Empty(self):
|
239
|
44 return len(self.instructions) == 0
|
|
45
|
219
|
46 @property
|
|
47 def FirstInstruction(self):
|
239
|
48 return self.instructions[0]
|
219
|
49 FirstIns = FirstInstruction
|
|
50
|
|
51 def getSuccessors(self):
|
173
|
52 if not self.Empty:
|
174
|
53 i = self.LastInstruction
|
173
|
54 return i.Targets
|
|
55 return []
|
219
|
56 Successors = property(getSuccessors)
|
|
57
|
|
58 def getPredecessors(self):
|
239
|
59 preds = []
|
|
60 for bb in self.parent.BasicBlocks:
|
|
61 if self in bb.Successors:
|
|
62 preds.append(bb)
|
|
63 return preds
|
219
|
64 Predecessors = property(getPredecessors)
|
171
|
65
|
239
|
66 def check(self):
|
|
67 for ins in self.Instructions:
|
|
68 ins.check()
|
|
69
|