diff python/ir/instruction.py @ 175:a51b3c956386

Added function call in expressions
author Windel Bouwman
date Fri, 19 Apr 2013 22:15:54 +0200
parents 3eb06f5fb987
children 5fd02aa38b42
line wrap: on
line diff
--- a/python/ir/instruction.py	Fri Apr 19 19:22:52 2013 +0200
+++ b/python/ir/instruction.py	Fri Apr 19 22:15:54 2013 +0200
@@ -1,4 +1,5 @@
 from .basicblock import BasicBlock
+from .function import Function
 
 class Value:
    """ Temporary SSA value (value that is assigned only once! """
@@ -54,12 +55,25 @@
 
 # Function calling:
 class Call(Instruction):
-   def __init__(self, callee, arguments):
+   def __init__(self, callee, arguments, result=None):
       super().__init__()
       self.callee = callee
+      assert type(callee) is Function
       self.arguments = arguments
+      for arg in arguments:
+         assert type(arg) is Value
+         self.addUse(arg)
+      self.result = result
+      if result:
+         assert type(result) is Value
+         self.addDef(result)
    def __repr__(self):
-      return 'CALL {0}'.format(self.callee)
+      if self.result:
+         pfx = '{0} = '.format(self.result)
+      else:
+         pfx = ''
+      args = ','.join([str(arg) for arg in self.arguments])
+      return pfx + '{0}({1})'.format(self.callee.name, args)
 
 class Return(Instruction):
    def __init__(self, value=None):
@@ -130,6 +144,7 @@
       self.location = location
       self.value = value
       self.addUse(value)
+      self.addUse(location)
    def __repr__(self):
       return '[{0}] = {1}'.format(self.location, self.value)