Mercurial > lcfOS
comparison python/ir/basicblock.py @ 174:3eb06f5fb987
Added memory alloc for locals
author | Windel Bouwman |
---|---|
date | Fri, 19 Apr 2013 19:22:52 +0200 |
parents | c1d2b6b9f9a7 |
children | 460db5669efa |
comparison
equal
deleted
inserted
replaced
173:c1d2b6b9f9a7 | 174:3eb06f5fb987 |
---|---|
1 | 1 |
2 class BasicBlock: | 2 class BasicBlock: |
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 'BasicBlock {0}'.format(self.name) | 8 return 'BasicBlock {0}'.format(self.name) |
11 self.instructions.append(i) | 11 self.instructions.append(i) |
12 addIns = addInstruction | 12 addIns = addInstruction |
13 def replaceInstruction(self, i1, i2): | 13 def replaceInstruction(self, i1, i2): |
14 idx = self.instructions.index(i1) | 14 idx = self.instructions.index(i1) |
15 i1.parent = None | 15 i1.parent = None |
16 i1.delete() | |
16 i2.parent = self | 17 i2.parent = self |
17 self.instructions[idx] = i2 | 18 self.instructions[idx] = i2 |
18 def removeInstruction(self, i): | 19 def removeInstruction(self, i): |
19 i.parent = None | 20 i.parent = None |
20 self.instructions.remove(i) | 21 self.instructions.remove(i) |
21 def getInstructions(self): | 22 def getInstructions(self): |
22 return self.instructions | 23 return self.instructions |
23 Instructions = property(getInstructions) | 24 def setInstructions(self, ins): |
25 for i in self.instructions: | |
26 i.parent = None | |
27 self.instructions = ins | |
28 for i in self.instructions: | |
29 i.parent = self | |
30 Instructions = property(getInstructions, setInstructions) | |
24 def getLastIns(self): | 31 def getLastIns(self): |
25 return self.instructions[-1] | 32 return self.instructions[-1] |
26 LastIns = property(getLastIns) | 33 LastInstruction = property(getLastIns) |
27 @property | 34 @property |
28 def Empty(self): | 35 def Empty(self): |
29 return len(self.instructions) == 0 | 36 return len(self.instructions) == 0 |
30 @property | 37 @property |
31 def FirstInstruction(self): | 38 def FirstInstruction(self): |
32 return self.instructions[0] | 39 return self.instructions[0] |
33 FirstIns = FirstInstruction | 40 FirstIns = FirstInstruction |
34 def getSuccessors(self): | 41 def getSuccessors(self): |
35 if not self.Empty: | 42 if not self.Empty: |
36 i = self.LastIns | 43 i = self.LastInstruction |
37 return i.Targets | 44 return i.Targets |
38 return [] | 45 return [] |
39 Successors = property(getSuccessors) | 46 Successors = property(getSuccessors) |
47 def getPredecessors(self): | |
48 return [] | |
49 Predecessors = property(getPredecessors) | |
40 | 50 |