diff python/testgraph.py @ 280:02385f62f250

Rework from str interface to Instruction interface
author Windel Bouwman
date Sat, 02 Nov 2013 10:03:26 +0100
parents 2ccd57b1d78c
children
line wrap: on
line diff
--- a/python/testgraph.py	Sat Oct 12 09:56:23 2013 +0200
+++ b/python/testgraph.py	Sat Nov 02 10:03:26 2013 +0100
@@ -5,11 +5,11 @@
 import interferencegraph
 import flowgraph
 import ir
-import irmach
+from irmach import AbstractInstruction as AI
+from target import Nop
 
 
 class GraphTestCase(unittest.TestCase):
-
     def testEdge(self):
         g = graph.Graph()
         n1 = graph.Node(g)
@@ -51,9 +51,9 @@
         t5 = ir.Temp('t5')
         t6 = ir.Temp('t6')
         instrs = []
-        instrs.append(irmach.makeIns('ld %d', dst=[t1]))
-        instrs.append(irmach.makeIns('ld %d', dst=[t2]))
-        instrs.append(irmach.makeIns('ld %d', dst=[t3]))
+        instrs.append(AI(Nop, dst=[t1]))
+        instrs.append(AI(Nop, dst=[t2]))
+        instrs.append(AI(Nop, dst=[t3]))
         cfg = flowgraph.FlowGraph(instrs)
         ig = interferencegraph.InterferenceGraph(cfg)
 
@@ -63,20 +63,17 @@
         t3 = ir.Temp('t3')
         t4 = ir.Temp('t4')
         instrs = []
-        instrs.append(irmach.makeIns('ld %d0', dst=[t1]))
-        instrs.append(irmach.makeIns('ld %d0', dst=[t2]))
-        instrs.append(irmach.makeIns('ld %d0', dst=[t3]))
-        instrs.append(irmach.makeIns('mov %d0, %s0', dst=[t4], src=[t3]))
-        instrs.append(irmach.makeIns('st %s0', src=[t4]))
-        instrs.append(irmach.makeIns('st %s0', src=[t1]))
-        instrs.append(irmach.makeIns('st %s0', src=[t2]))
+        instrs.append(AI(Nop, dst=[t1]))
+        instrs.append(AI(Nop, dst=[t2]))
+        instrs.append(AI(Nop, dst=[t3]))
+        instrs.append(AI(Nop, dst=[t4], src=[t3]))
+        instrs.append(AI(Nop, src=[t4]))
+        instrs.append(AI(Nop, src=[t1]))
+        instrs.append(AI(Nop, src=[t2]))
         cfg = flowgraph.FlowGraph(instrs)
         ig = interferencegraph.InterferenceGraph(cfg)
-        ig.to_txt()
         ig.Combine(ig.getNode(t4), ig.getNode(t3))
         self.assertIs(ig.getNode(t4), ig.getNode(t3))
-        print('after')
-        ig.to_txt()
 
 
 if __name__ == '__main__':