diff python/ir/instruction.py @ 170:4348da5ca307

Cleanup of ir dir
author Windel Bouwman
date Fri, 29 Mar 2013 17:33:17 +0100
parents 10330be89bc2
children 3eb9b9e2958d
line wrap: on
line diff
--- a/python/ir/instruction.py	Sat Mar 23 18:34:41 2013 +0100
+++ b/python/ir/instruction.py	Fri Mar 29 17:33:17 2013 +0100
@@ -3,6 +3,13 @@
    """ Base class for all instructions. """
    pass
 
+# Label:
+class LabelInstruction(Instruction):
+   def __init__(self, labid):
+      self.labid = labid
+   def __repr__(self):
+      return '{0}:'.format(self.labid)
+
 # Function calling:
 class CallInstruction(Instruction):
    def __init__(self, callee, arguments):
@@ -16,10 +23,15 @@
    def __repr__(self):
       return 'RET'
 
+class MoveInstruction(Instruction):
+   def __init__(self, name, value):
+      self.name = name
+      self.value = value
+   def __repr__(self):
+      return '{0} = {1}'.format(self.name, self.value)
+
 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
@@ -27,25 +39,34 @@
       self.value2 = value2
       self.operation = operation
    def __repr__(self):
-      return '{0} = {1} {2}, {3}'.format(self.name, self.operation, self.value1, self.value2)
+      return '{0} = {2} {1} {3}'.format(self.name, self.operation, self.value1, self.value2)
 
+# Memory functions:
 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)
+      return '{1} = [{0}]'.format(self.name, self.value)
 
 class StoreInstruction(Instruction):
    def __init__(self, name, value):
       self.name = name
       self.value = value
    def __repr__(self):
-      return 'store {0}'.format(self.name)
+      return '[{0}] = {1}'.format(self.name, self.value)
 
 class BranchInstruction(Instruction):
-   def __init__(self, t1, t2):
-      self.t1 = t1
-      self.t2 = t2
+   def __init__(self, target):
+      self.t1 = target
    def __repr__(self):
       return 'BRANCH {0}'.format(self.t1)
+
+class IfInstruction(Instruction):
+   def __init__(self, cond, lab1, lab2):
+      self.cond = cond
+      self.lab1 = lab1
+      self.lab2 = lab2
+   def __repr__(self):
+      return 'IF {0} THEN {1} ELSE {2}'.format(self.cond, self.lab1, self.lab2)
+