Commit b5507160 authored by Jayke Meijer's avatar Jayke Meijer

Working on copyprop.

parent 53ac258b
......@@ -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]
......@@ -149,4 +151,5 @@ def copy_propagation(block):
s[2] = moves_from[i]
print "Propagated"
print ""
return False
......@@ -15,16 +15,30 @@ class TestOptimizeAdvanced(unittest.TestCase):
pass
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'),
# 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)
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