Преглед изворни кода

Fixed one thing in unittest, added example to docstring.

Jayke Meijer пре 14 година
родитељ
комит
12b1dc5e46
2 измењених фајлова са 13 додато и 6 уклоњено
  1. 12 4
      src/optimize/advanced.py
  2. 1 2
      tests/test_optimize_advanced.py

+ 12 - 4
src/optimize/advanced.py

@@ -166,6 +166,13 @@ def copy_propagation(block):
     walking through the code, storing move operations and checking whether it
     changes or whether a variable can be replaced. This way, the move statement
     might be a target for dead code elimination.
+    
+    move $regA, $regB           move $regA, $regB
+    ...                         ...
+    Code not writing $regA, ->  ...
+    $regB                       ...
+    ...                         ...
+    addu $regC, $regA, ...      addu $regC, $regB, ...
     """
     moves_from = []
     moves_to = []
@@ -221,17 +228,18 @@ def algebraic_transformations(block):
     changed = False
     
     while not block.end():
-        changed = True
         s = block.read()
         
         if (s.is_command('addu') or s.is_command('subu')) and s[2] == 0:
             block.replace(1, [])
+            changed = True
         elif s.is_command('mult') and s[2] == 1:
             block.replace(1, [])
+            changed = True
         elif s.is_command('mult') and s[2] == 2:
-            new_command = S(['command', 'sll', s[0], s[1], 1])
+            new_command = S(['command', 'sll', 
+            s[0], s[1], 1])
             block.replace(1, [new_command])
-        else:
-            changed = False
+            changed = True
             
     return changed

+ 1 - 2
tests/test_optimize_advanced.py

@@ -76,7 +76,6 @@ class TestOptimizeAdvanced(unittest.TestCase):
                    S('command', 'addu', '$1', '$2', 0),
                    self.bar])
                    
-#        self.assertTrue(copy_propagation(block))
-        algebraic_transformations(block)
+        self.assertTrue(algebraic_transformations(block))
         self.assertEqual(block.statements, [self.foo,
                    self.bar])