Commit 69a28137 authored by Taddeus Kroes's avatar Taddeus Kroes

Added block reset() call whenever 'while block.end():' is used.

parent 0de7d78b
...@@ -50,6 +50,8 @@ def eliminate_common_subexpressions(block): ...@@ -50,6 +50,8 @@ def eliminate_common_subexpressions(block):
""" """
changed = False changed = False
block.reset()
while not block.end(): while not block.end():
s = block.read() s = block.read()
...@@ -123,6 +125,8 @@ def fold_constants(block): ...@@ -123,6 +125,8 @@ def fold_constants(block):
# Current known values in register # Current known values in register
register = {} register = {}
block.reset()
while not block.end(): while not block.end():
s = block.read() s = block.read()
...@@ -147,10 +151,10 @@ def fold_constants(block): ...@@ -147,10 +151,10 @@ def fold_constants(block):
elif s.name == 'lw' and s[1] in constants: elif s.name == 'lw' and s[1] in constants:
# Usage of variable with constant value # Usage of variable with constant value
register[s[0]] = constants[s[1]] register[s[0]] = constants[s[1]]
elif s.name == 'mflo': elif s.name == 'mflo' and '$lo' in register:
# Move of `Lo' register to another register # Move of `Lo' register to another register
register[s[0]] = register['$lo'] register[s[0]] = register['$lo']
elif s.name == 'mfhi': elif s.name == 'mfhi' and '$hi' in register:
# Move of `Hi' register to another register # Move of `Hi' register to another register
register[s[0]] = register['$hi'] register[s[0]] = register['$hi']
elif s.name in ['mult', 'div'] \ elif s.name in ['mult', 'div'] \
...@@ -252,6 +256,8 @@ def copy_propagation(block): ...@@ -252,6 +256,8 @@ def copy_propagation(block):
moves_to = [] moves_to = []
changed = False changed = False
block.reset()
while not block.end(): while not block.end():
s = block.read() s = block.read()
...@@ -305,6 +311,8 @@ def algebraic_transformations(block): ...@@ -305,6 +311,8 @@ def algebraic_transformations(block):
""" """
changed = False changed = False
block.reset()
while not block.end(): while not block.end():
s = block.read() s = block.read()
......
...@@ -288,4 +288,8 @@ class Block: ...@@ -288,4 +288,8 @@ class Block:
def reverse_statements(self): def reverse_statements(self):
"""Reverse the statement list and reset the pointer.""" """Reverse the statement list and reset the pointer."""
self.statements = self.statements[::-1] self.statements = self.statements[::-1]
self.reset()
def reset(self):
"""Reset the internal pointer."""
self.pointer = 0 self.pointer = 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment