Mercurial > lcfOS
comparison python/ir/instruction.py @ 259:ac603eb66b63
Added function call
author | Windel Bouwman |
---|---|
date | Mon, 05 Aug 2013 20:41:25 +0200 |
parents | 04c19282a5aa |
children | 444b9df2ed99 |
comparison
equal
deleted
inserted
replaced
258:04c19282a5aa | 259:ac603eb66b63 |
---|---|
24 return len(self.used_by) > 0 | 24 return len(self.used_by) > 0 |
25 | 25 |
26 Used = IsUsed | 26 Used = IsUsed |
27 | 27 |
28 def onlyUsedInBlock(self, bb): | 28 def onlyUsedInBlock(self, bb): |
29 for use in self.used_by: | 29 return all(use.Block is bb for use in self.used_by) |
30 ins = use | |
31 if ins.parent != bb: | |
32 return False | |
33 return True | |
34 | 30 |
35 def lastUse(self, ins): | 31 def lastUse(self, ins): |
36 assert ins in self.used_by | 32 assert ins in self.used_by |
37 return all(not ins.precedes(ub) for ub in self.used_by) | 33 return all(not ins.precedes(ub) for ub in self.used_by) |
38 | 34 |
58 self.live_in = set() | 54 self.live_in = set() |
59 self.live_out = set() | 55 self.live_out = set() |
60 # What variables this instruction uses and defines: | 56 # What variables this instruction uses and defines: |
61 self.defs = [] | 57 self.defs = [] |
62 self.uses = [] | 58 self.uses = [] |
59 | |
63 def delete(self): | 60 def delete(self): |
64 while self.uses: | 61 while self.uses: |
65 use = self.uses.pop() | 62 use = self.uses.pop() |
66 use.delete() | 63 use.delete() |
67 while self.defs: | 64 while self.defs: |
104 | 101 |
105 def precedes(self, other): | 102 def precedes(self, other): |
106 assert isinstance(other, Instruction) | 103 assert isinstance(other, Instruction) |
107 if self.Block is other.Block: | 104 if self.Block is other.Block: |
108 return other.Position > self.Position | 105 return other.Position > self.Position |
109 return self.Block.precedes(other.Block) | 106 else: |
107 return self.Block.precedes(other.Block) | |
108 | |
109 def follows(self, other): | |
110 pass | |
110 | 111 |
111 @property | 112 @property |
112 def Function(self): | 113 def Function(self): |
113 return self.Block.parent | 114 return self.Block.parent |
114 | 115 |
243 def __repr__(self): | 244 def __repr__(self): |
244 return '{} = [{}]'.format(self.value, self.location) | 245 return '{} = [{}]'.format(self.value, self.location) |
245 | 246 |
246 class Store(Instruction): | 247 class Store(Instruction): |
247 def __init__(self, location, value): | 248 def __init__(self, location, value): |
248 super().__init__() | 249 super().__init__() |
249 assert type(value) is Value, value | 250 assert type(value) is Value, value |
250 assert isinstance(location, Value), "Location must be a value" | 251 assert isinstance(location, Value), "Location must be a value" |
251 self.location = location | 252 self.location = location |
252 self.value = value | 253 self.value = value |
253 self.addUse(value) | 254 self.addUse(value) |
254 self.addUse(location) | 255 self.addUse(location) |
255 | 256 |
256 def __repr__(self): | 257 def __repr__(self): |
257 return '[{}] = {}'.format(self.location, self.value) | 258 return '[{}] = {}'.format(self.location, self.value) |
258 | 259 |
259 def replaceValue(self, old, new): | 260 def replaceValue(self, old, new): |
260 if old is self.value: | 261 if old is self.value: |