Commit 4a51527e authored by Jayke Meijer's avatar Jayke Meijer

Added unittest of move-instr optimization.

parent 5b0796b7
......@@ -13,7 +13,6 @@ def optimize_global(statements):
# mov $regA, $regA -> --- remove it
if s.is_command('move') and s[0] == s[1]:
print "Let me fix that", s
statements.replace(1, [])
continue
......
......@@ -11,8 +11,8 @@ class TestOptimize(unittest.TestCase):
def test_optimize_global_movaa(self):
foo = S('command', 'foo')
bar = S('command', 'baz')
block = B([foo, \
bar = S('command', 'bar')
block = B([foo,
S('command', 'move', '$regA', '$regA'),
bar])
optimize_global(block)
......@@ -21,11 +21,36 @@ class TestOptimize(unittest.TestCase):
def test_optimize_global_movab(self):
foo = S('command', 'foo')
move = S('command', 'move', '$regA', '$regB')
bar = S('command', 'baz')
block = B([foo, \
bar = S('command', 'bar')
block = B([foo,
move,
bar])
optimize_global(block)
self.assertEquals(block.statements, [foo, move, bar])
def
def test_optimize_global_movinst(self):
foo = S('command', 'foo')
bar = S('command', 'bar')
block = B([foo,
S('command', 'move', '$regA', '$regB'),
S('command', 'addu', '$regA', '$regA', 2),
bar])
optimize_global(block)
self.assertEquals(block.statements, [foo,
S('command', 'addu', '$regA', '$regB', 2),
bar])
def test_optimize_global_movinst(self):
foo = S('command', 'foo')
bar = S('command', 'bar')
block = B([foo,
S('command', 'move', '$regA', '$regB'),
S('command', 'addu', '$regA', '$regC', 2),
bar])
optimize_global(block)
self.assertEquals(block.statements, [foo,
S('command', 'move', '$regA', '$regB'),
S('command', 'addu', '$regA', '$regC', 2),
bar])
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