171
|
1
|
|
2 class BasicBlock:
|
|
3 # Uninterrupted sequence of instructions.
|
|
4 def __init__(self, name):
|
|
5 self.name = name
|
|
6 self.instructions = []
|
|
7 def __repr__(self):
|
173
|
8 return 'BasicBlock {0}'.format(self.name)
|
|
9 def addInstruction(self, i):
|
|
10 i.parent = self
|
171
|
11 self.instructions.append(i)
|
173
|
12 addIns = addInstruction
|
|
13 def replaceInstruction(self, i1, i2):
|
|
14 idx = self.instructions.index(i1)
|
|
15 i1.parent = None
|
|
16 i2.parent = self
|
|
17 self.instructions[idx] = i2
|
|
18 def removeInstruction(self, i):
|
|
19 i.parent = None
|
|
20 self.instructions.remove(i)
|
171
|
21 def getInstructions(self):
|
|
22 return self.instructions
|
|
23 Instructions = property(getInstructions)
|
|
24 def getLastIns(self):
|
|
25 return self.instructions[-1]
|
|
26 LastIns = property(getLastIns)
|
|
27 @property
|
|
28 def Empty(self):
|
|
29 return len(self.instructions) == 0
|
|
30 @property
|
173
|
31 def FirstInstruction(self):
|
171
|
32 return self.instructions[0]
|
173
|
33 FirstIns = FirstInstruction
|
|
34 def getSuccessors(self):
|
|
35 if not self.Empty:
|
|
36 i = self.LastIns
|
|
37 return i.Targets
|
|
38 return []
|
|
39 Successors = property(getSuccessors)
|
171
|
40
|