comparison python/ir/basicblock.py @ 173:c1d2b6b9f9a7

Rework into passes
author Windel Bouwman
date Fri, 19 Apr 2013 12:42:21 +0200
parents 3eb9b9e2958d
children 3eb06f5fb987
comparison
equal deleted inserted replaced
172:5a7d37d615ee 173:c1d2b6b9f9a7
3 # Uninterrupted sequence of instructions. 3 # Uninterrupted sequence of instructions.
4 def __init__(self, name): 4 def __init__(self, name):
5 self.name = name 5 self.name = name
6 self.instructions = [] 6 self.instructions = []
7 def __repr__(self): 7 def __repr__(self):
8 return 'BB {0}'.format(self.name) 8 return 'BasicBlock {0}'.format(self.name)
9 def addIns(self, i): 9 def addInstruction(self, i):
10 i.parent = self
10 self.instructions.append(i) 11 self.instructions.append(i)
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)
11 def getInstructions(self): 21 def getInstructions(self):
12 return self.instructions 22 return self.instructions
13 Instructions = property(getInstructions) 23 Instructions = property(getInstructions)
14 def getLastIns(self): 24 def getLastIns(self):
15 return self.instructions[-1] 25 return self.instructions[-1]
16 LastIns = property(getLastIns) 26 LastIns = property(getLastIns)
17 @property 27 @property
18 def Empty(self): 28 def Empty(self):
19 return len(self.instructions) == 0 29 return len(self.instructions) == 0
20 @property 30 @property
21 def FirstIns(self): 31 def FirstInstruction(self):
22 return self.instructions[0] 32 return self.instructions[0]
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)
23 40