Taddeus Kroes před 14 roky
rodič
revize
7343f43c1a
2 změnil soubory, kde provedl 19 přidání a 6 odebrání
  1. 4 3
      src/optimize/__init__.py
  2. 15 3
      src/optimize/advanced.py

+ 4 - 3
src/optimize/__init__.py

@@ -1,9 +1,10 @@
-from src.dataflow import find_basic_blocks
+from dataflow import find_basic_blocks
 
 
 from standard import redundant_move_1, redundant_move_2, \
 from standard import redundant_move_1, redundant_move_2, \
         redundant_move_3, redundant_move_4, redundant_load, \
         redundant_move_3, redundant_move_4, redundant_load, \
         redundant_shift, redundant_add
         redundant_shift, redundant_add
-from advanced import eliminate_common_subexpressions, fold_constants
+from advanced import eliminate_common_subexpressions, fold_constants, \
+    copy_propagation
 
 
 
 
 def optimize_global(statements):
 def optimize_global(statements):
@@ -57,7 +58,7 @@ def optimize_block(block):
     #              or fold_constants(block)
     #              or fold_constants(block)
 
 
     while eliminate_common_subexpressions(block) \
     while eliminate_common_subexpressions(block) \
-            | fold_constants(block):
+            | fold_constants(block) | copy_propagation(block):
         pass
         pass
 
 
 def optimize(statements, verbose=0):
 def optimize(statements, verbose=0):

+ 15 - 3
src/optimize/advanced.py

@@ -1,4 +1,4 @@
-from src.statement import Statement as S
+from statement import Statement as S
 
 
 
 
 def create_variable():
 def create_variable():
@@ -103,9 +103,21 @@ def fold_constants(block):
 
 
     return False
     return False
 
 
-def copy_propagtion(block):
+
+def copy_propagation(block):
     """
     """
     Rename values that were copied to there original, so the copy statement
     Rename values that were copied to there original, so the copy statement
     might be useless, allowing it to be removed by dead code elimination.
     might be useless, allowing it to be removed by dead code elimination.
     """
     """
-    return false
+    moves = []
+    count = 0
+
+    while not block.end():
+        s = block.read()
+
+        if s.is_command('move'):
+            moves.append((s[0], s[1]))
+            count += 1
+
+    print "count", count
+    return False