diff python/irmach.py @ 277:046017431c6a

Started register allocator
author Windel Bouwman
date Thu, 26 Sep 2013 21:14:25 +0200
parents 6f2423df0675
children 02385f62f250
line wrap: on
line diff
--- a/python/irmach.py	Mon Sep 16 21:51:17 2013 +0200
+++ b/python/irmach.py	Thu Sep 26 21:14:25 2013 +0200
@@ -7,6 +7,8 @@
   Instructions are selected and scheduled at this stage.
 """
 
+import ir
+
 class Frame:
     """ 
         Activation record abstraction. This class contains a flattened 
@@ -29,24 +31,23 @@
         Abstract machine instruction class. This is a very simple
         abstraction of machine instructions.
     """
-    def __init__(self, assem, src=(), dst=(), jumps=()):
-        self.assem = assem
+    def __init__(self, cls, ops=(), src=(), dst=(), jumps=()):
+        self.assem = cls
+        self.ops = ops
         self.src = tuple(src)
         self.dst = tuple(dst)
         self.jumps = tuple(jumps)
+        c = lambda s: tuple(map(type, s)) == (ir.Temp, )
+        self.ismove = c(src) and c(dst) and cls.lower().startswith('mov')
 
     def __repr__(self):
-        s = str(self.src) if self.src else ''
-        d = str(self.dst) if self.dst else ''
-        l = str(self.jumps) if self.jumps else ''
-        #return self.assem + s + d + l
         return self.render()
 
     def render(self):
         """
             Substitutes source, dst and labels in the string
         """
-        x = self.assem
+        x = str(self.assem)
         for i, s in enumerate(self.src):
             p = '%s{}'.format(i)
             x = x.replace(p, str(s))
@@ -56,7 +57,6 @@
         for i, j in enumerate(self.jumps):
             p = '%l{}'.format(i)
             x = x.replace(p, str(j))
-        
         return x