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

Working on copyprop.

parent 53ac258b
No related branches found
No related tags found
No related merge requests found
...@@ -114,25 +114,27 @@ def copy_propagation(block): ...@@ -114,25 +114,27 @@ def copy_propagation(block):
while not block.end(): while not block.end():
s = block.read() s = block.read()
print "len(s)",len(s)
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 moves_from print "fr: ", moves_from
print moves_to print "to: ", moves_to
if s.is_command('move') and s[0] not in moves_from: if s.is_command('move') and s[0] not in moves_to:
moves_from.append(s[0]) moves_from.append(s[1])
moves_to.append(s[1]) moves_to.append(s[0])
print "Added move to list." print "Added move to list."
elif s.is_command('move'): elif s.is_command('move'):
for i in xrange(len(moves_to)): for i in xrange(len(moves_to)):
if moves_to[i] == s[0]: if moves_to[i] == s[0]:
moves_from[i] = s[1] moves_from[i] = s[1]
elif len(s) == 3 and s[0] in moves_to: elif len(s) == 3 and s[0] in moves_to:
print len(s)
print len(moves_to)
for i in xrange(len(moves_to)): for i in xrange(len(moves_to)):
if moves_to[i] == s[0]: if moves_to[i] == s[0]:
del moves_to[i] del moves_to[i]
...@@ -148,5 +150,6 @@ def copy_propagation(block): ...@@ -148,5 +150,6 @@ def copy_propagation(block):
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 ""
return False return False
...@@ -14,17 +14,31 @@ class TestOptimizeAdvanced(unittest.TestCase): ...@@ -14,17 +14,31 @@ class TestOptimizeAdvanced(unittest.TestCase):
def test_eliminate_common_subexpressions(self): def test_eliminate_common_subexpressions(self):
pass pass
def test_copy_propagation_true(self): def test_copy_propagation_true(self):
# block = B([self.foo, print "testing true"
block = B([self.foo,
S('command', 'move', '$1', '$2'),
self.foo,
S('command', 'addu', '$3', '$1', '$4'),
self.bar])
copy_propagation(block)
self.assertEqual(block.statements, [self.foo,
S('command', 'move', '$1', '$2'),
self.foo,
S('command', 'addu', '$3', '$2', '$4'),
self.bar])
print "Test true succesfull"
# def test_copy_propagation_false(self):
# print "Testing false"
# arguments = [self.foo,
# S('command', 'move', '$1', '$2'), # S('command', 'move', '$1', '$2'),
# self.foo, # S('command', 'move', '$10', '$20'),
# S('command', 'addu', '$1', '$5', 1),
# S('command', 'addu', '$3', '$1', '$4'), # S('command', 'addu', '$3', '$1', '$4'),
# self.bar]) # self.bar]
# block = B(arguments)
# #
# copy_propagation(block) # copy_propagation(block)
# self.assertEquals(block.statements, [self.foo, # self.assertEqual(block.statements, arguments)
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'addu', '$3', '$2', '$4'),
# self.bar])
pass
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