comparison python/ir/basicblock.py @ 268:5ec7580976d9

Op naar tree-IR
author Windel Bouwman
date Wed, 14 Aug 2013 20:12:40 +0200
parents 04c19282a5aa
children 5f8c04a8d26b
comparison
equal deleted inserted replaced
267:e7c8f7eb3f59 268:5ec7580976d9
1 1
2 class BasicBlock: 2 # from .instruction import Statement
3 """ Uninterrupted sequence of instructions. """ 3
4 class Block:
5 """
6 Uninterrupted sequence of instructions with a label at the start.
7 """
4 def __init__(self, name): 8 def __init__(self, name):
5 self.name = name 9 self.name = name
6 self.instructions = [] 10 self.instructions = []
7 11
8 def __repr__(self): 12 def __repr__(self):
9 return 'BasicBlock {0}'.format(self.name) 13 return 'Block {0}'.format(self.name)
10 14
11 def addInstruction(self, i): 15 def addInstruction(self, i):
16 #assert isinstance(i, Statement)
12 i.parent = self 17 i.parent = self
13 self.instructions.append(i) 18 self.instructions.append(i)
14 19
15 def replaceInstruction(self, i1, i2): 20 def replaceInstruction(self, i1, i2):
16 idx = self.instructions.index(i1) 21 idx = self.instructions.index(i1)
40 def FirstInstruction(self): 45 def FirstInstruction(self):
41 return self.instructions[0] 46 return self.instructions[0]
42 47
43 def getSuccessors(self): 48 def getSuccessors(self):
44 if not self.Empty: 49 if not self.Empty:
45 i = self.LastInstruction 50 return self.LastInstruction.Targets
46 return i.Targets
47 return [] 51 return []
48 Successors = property(getSuccessors) 52 Successors = property(getSuccessors)
49 53
50 def getPredecessors(self): 54 def getPredecessors(self):
51 preds = [] 55 preds = []
57 61
58 def precedes(self, other): 62 def precedes(self, other):
59 raise NotImplementedError() 63 raise NotImplementedError()
60 64
61 def check(self): 65 def check(self):
62 for ins in self.Instructions: 66 pass
63 ins.check()
64 67