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

Added unittest of move-instr optimization.

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