Skip to content
Snippets Groups Projects
Commit 030e9754 authored by Taddeus Kroes's avatar Taddeus Kroes
Browse files

Extended docstrings.

parent 870d25ee
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,11 @@ def create_variable(): ...@@ -8,6 +8,11 @@ def create_variable():
def eliminate_common_subexpressions(block): def eliminate_common_subexpressions(block):
""" """
Common subexpression elimination: Common subexpression elimination:
x = a + b -> u = a + b
y = a + b x = u
y = u
The algorithm used is as follows:
- Traverse through the statements in reverse order. - Traverse through the statements in reverse order.
- If the statement can be possibly be eliminated, walk further collecting - If the statement can be possibly be eliminated, walk further collecting
all other occurrences of the expression until one of the arguments is all other occurrences of the expression until one of the arguments is
...@@ -65,7 +70,11 @@ def to_hex(value): ...@@ -65,7 +70,11 @@ def to_hex(value):
def fold_constants(block): def fold_constants(block):
""" """
Constant folding: Constant folding:
- An immidiate load defines a register value: x = 3 + 5 -> x = 8
y = x * 2 y = 16
To keep track of constant values, the following assumptions are made:
- An immediate load defines a register value:
li $reg, XX -> register[$reg] = XX li $reg, XX -> register[$reg] = XX
- Integer variable definition is of the following form: - Integer variable definition is of the following form:
li $reg, XX -> constants[VAR] = XX li $reg, XX -> constants[VAR] = XX
...@@ -161,12 +170,12 @@ def copy_propagation(block): ...@@ -161,12 +170,12 @@ def copy_propagation(block):
while not block.end(): while not block.end():
s = block.read() s = block.read()
if len(s) == 3: if len(s) == 3:
print "s[0] = ", s[0] print "s[0] = ", s[0]
print "s[1] = ", s[1] print "s[1] = ", s[1]
print "s[2] = ", s[2] print "s[2] = ", s[2]
if moves_from: if moves_from:
print "fr: ", moves_from print "fr: ", moves_from
print "to: ", moves_to print "to: ", moves_to
...@@ -193,10 +202,10 @@ def copy_propagation(block): ...@@ -193,10 +202,10 @@ def copy_propagation(block):
if s[1] == moves_to[i]: if s[1] == moves_to[i]:
s[1] = moves_from[i] s[1] = moves_from[i]
print "Propagated" print "Propagated"
if s[2] == moves_to[i]: if s[2] == moves_to[i]:
s[2] = moves_from[i] s[2] = moves_from[i]
print "Propagated" print "Propagated"
print "" print ""
return False return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment