Przeglądaj źródła

Added docstings for Constant Folding.

Taddeus Kroes 14 lat temu
rodzic
commit
fff63a67a7
1 zmienionych plików z 12 dodań i 1 usunięć
  1. 12 1
      src/optimize/advanced.py

+ 12 - 1
src/optimize/advanced.py

@@ -65,8 +65,19 @@ def to_hex(value):
 def fold_constants(block):
     """
     Constant folding:
+    - Integer variable definition is of the following form:
+        li $reg, XX
+        sw $reg, VAR
+      save this as:
+        reg[$reg] = XX
+        constants[VAR] = XX
+    - When a variable is used, the following happens:
+        lw $reg, VAR
+      save this as:
+        reg[$reg] = constants[VAR]
     """
     constants = {}
+    reg = {}
 
     while not block.end():
         s = block.read()
@@ -91,7 +102,7 @@ def fold_constants(block):
             #else:
 
     return False
-    
+
 def copy_propagtion(block):
     """
     Rename values that were copied to there original, so the copy statement