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