Skip to content
Snippets Groups Projects
Commit 12b1dc5e authored by Jayke Meijer's avatar Jayke Meijer
Browse files

Fixed one thing in unittest, added example to docstring.

parent 8c1d9515
No related branches found
No related tags found
No related merge requests found
...@@ -166,6 +166,13 @@ def copy_propagation(block): ...@@ -166,6 +166,13 @@ def copy_propagation(block):
walking through the code, storing move operations and checking whether it walking through the code, storing move operations and checking whether it
changes or whether a variable can be replaced. This way, the move statement changes or whether a variable can be replaced. This way, the move statement
might be a target for dead code elimination. 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_from = []
moves_to = [] moves_to = []
...@@ -221,17 +228,18 @@ def algebraic_transformations(block): ...@@ -221,17 +228,18 @@ def algebraic_transformations(block):
changed = False changed = False
while not block.end(): while not block.end():
changed = True
s = block.read() s = block.read()
if (s.is_command('addu') or s.is_command('subu')) and s[2] == 0: if (s.is_command('addu') or s.is_command('subu')) and s[2] == 0:
block.replace(1, []) block.replace(1, [])
changed = True
elif s.is_command('mult') and s[2] == 1: elif s.is_command('mult') and s[2] == 1:
block.replace(1, []) block.replace(1, [])
changed = True
elif s.is_command('mult') and s[2] == 2: 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]) block.replace(1, [new_command])
else: changed = True
changed = False
return changed return changed
...@@ -76,7 +76,6 @@ class TestOptimizeAdvanced(unittest.TestCase): ...@@ -76,7 +76,6 @@ class TestOptimizeAdvanced(unittest.TestCase):
S('command', 'addu', '$1', '$2', 0), S('command', 'addu', '$1', '$2', 0),
self.bar]) self.bar])
# self.assertTrue(copy_propagation(block)) self.assertTrue(algebraic_transformations(block))
algebraic_transformations(block)
self.assertEqual(block.statements, [self.foo, self.assertEqual(block.statements, [self.foo,
self.bar]) self.bar])
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