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):
while not block.end():
s = block.read()
print "len(s)",len(s)
if len(s) == 3:
print "s[0] = ", s[0]
print "s[1] = ", s[1]
print "s[2] = ", s[2]
if moves_from:
print moves_from
print moves_to
print "fr: ", moves_from
print "to: ", moves_to
if s.is_command('move') and s[0] not in moves_from:
moves_from.append(s[0])
moves_to.append(s[1])
if s.is_command('move') and s[0] not in moves_to:
moves_from.append(s[1])
moves_to.append(s[0])
print "Added move to list."
elif s.is_command('move'):
for i in xrange(len(moves_to)):
if moves_to[i] == s[0]:
moves_from[i] = s[1]
elif len(s) == 3 and s[0] in moves_to:
print len(s)
print len(moves_to)
for i in xrange(len(moves_to)):
if moves_to[i] == s[0]:
del moves_to[i]
......@@ -148,5 +150,6 @@ def copy_propagation(block):
if s[2] == moves_to[i]:
s[2] = moves_from[i]
print "Propagated"
print ""
return False
......@@ -14,17 +14,31 @@ class TestOptimizeAdvanced(unittest.TestCase):
def test_eliminate_common_subexpressions(self):
pass
def test_copy_propagation_true(self):
# block = B([self.foo,
def test_copy_propagation_true(self):
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'),
# self.foo,
# S('command', 'move', '$10', '$20'),
# S('command', 'addu', '$1', '$5', 1),
# S('command', 'addu', '$3', '$1', '$4'),
# self.bar])
# self.bar]
# block = B(arguments)
#
# copy_propagation(block)
# self.assertEquals(block.statements, [self.foo,
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'addu', '$3', '$2', '$4'),
# self.bar])
pass
# self.assertEqual(block.statements, arguments)
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