Mercurial > lcfOS
diff python/transform.py @ 174:3eb06f5fb987
Added memory alloc for locals
author | Windel Bouwman |
---|---|
date | Fri, 19 Apr 2013 19:22:52 +0200 |
parents | c1d2b6b9f9a7 |
children | a51b3c956386 |
line wrap: on
line diff
--- a/python/transform.py Fri Apr 19 12:42:21 2013 +0200 +++ b/python/transform.py Fri Apr 19 19:22:52 2013 +0200 @@ -20,7 +20,7 @@ class InstructionPass(BasicBlockPass): def onBasicBlock(self, bb): - for ins in bb.Instructions: + for ins in iter(bb.Instructions): self.onInstruction(ins) def onInstruction(self, ins): """ Override this virtual method """ @@ -50,9 +50,15 @@ print(i2) i.Parent.replaceInstruction(i, i2) -class DeadCodeDeleter(InstructionPass): - def onInstruction(self, ins): - print(ins, ins.Users) - if not ins.defs in ins.live_out: - ins.Parent.removeInstruction(ins) +class DeadCodeDeleter(BasicBlockPass): + def onBasicBlock(self, bb): + def instructionUsed(ins): + if len(ins.defs) == 0: + # In case this instruction does not define any variables, assume it is usefull. + return True + for d in ins.defs: + if d.IsUsed: + return True + return False + bb.Instructions = list(filter(instructionUsed, bb.Instructions))