view python/ir/instruction.py @ 158:9683a4cd848f

Added some functions for code generation
author Windel Bouwman
date Fri, 08 Mar 2013 16:52:44 +0100
parents 8f3924b6076e
children 10330be89bc2
line wrap: on
line source


class Instruction:
   """ Base class for all instructions. """
   pass

# Function calling:
class CallInstruction(Instruction):
   def __init__(self, callee, arguments):
      super().__init__()
      self.callee = callee
      self.arguments = arguments
   def __repr__(self):
      return 'CALL {0}'.format(self.callee)

class RetInstruction(Instruction):
   def __repr__(self):
      return 'RET'

class BinaryOperator(Instruction):
   def __init__(self, name, operation, value1, value2):
      assert value1
      assert value2
      #print('operation is in binops:', operation in BinOps)
      # Check types of the two operands:
      self.name = name
      self.value1 = value1
      self.value2 = value2
      self.operation = operation
   def __repr__(self):
      return '{0} = {1} {2}, {3}'.format(self.name, self.operation, self.value1, self.value2)

class LoadInstruction(Instruction):
   def __init__(self, name, value):
      self.value = value
      self.name = name
   def __repr__(self):
      return 'load {0} = {1}'.format(self.name, self.value)

class BranchInstruction(Instruction):
   def __init__(self, t1, t2):
      self.t1 = t1
      self.t2 = t2
   def __repr__(self):
      return 'BRANCH {0}'.format(self.t1)