diff python/ir/instruction.py @ 173:c1d2b6b9f9a7

Rework into passes
author Windel Bouwman
date Fri, 19 Apr 2013 12:42:21 +0200
parents 3eb9b9e2958d
children 3eb06f5fb987
line wrap: on
line diff
--- a/python/ir/instruction.py	Thu Apr 04 17:58:37 2013 +0200
+++ b/python/ir/instruction.py	Fri Apr 19 12:42:21 2013 +0200
@@ -17,16 +17,18 @@
 class Instruction:
    """ Base class for all instructions. """
    def __init__(self):
-      # successors:
-      self.succ = set()
-      # predecessors:
-      self.pred = set()
       # live variables at this node:
       self.live_in = set()
       self.live_out = set()
       # What variables this instruction uses and defines:
       self.defs = set()
       self.uses = set()
+   def getParent(self):
+      return self.parent
+   Parent = property(getParent)
+   @property
+   def Targets(self):
+      return self.getTargets()
 
 # Function calling:
 class Call(Instruction):
@@ -40,6 +42,8 @@
 class Return(Instruction):
    def __repr__(self):
       return 'RET'
+   def getTargets(self):
+      return []
 
 class ImmLoad(Instruction):
    def __init__(self, target, value):
@@ -93,6 +97,8 @@
       self.target = target
    def __repr__(self):
       return 'BRANCH {0}'.format(self.target)
+   def getTargets(self):
+      return [self.target]
 
 class ConditionalBranch(Instruction):
    def __init__(self, a, cond, b, lab1, lab2):
@@ -110,6 +116,8 @@
       self.lab2 = lab2
    def __repr__(self):
       return 'IF {0} {1} {2} THEN {3} ELSE {4}'.format(self.a, self.cond, self.b, self.lab1, self.lab2)
+   def getTargets(self):
+      return [self.lab1, self.lab2]
 
 class PhiNode(Instruction):
    def __init__(self):