test_optimize_advanced.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import unittest
  2. from src.optimize.advanced import eliminate_common_subexpressions, \
  3. copy_propagation
  4. from src.statement import Statement as S, Block as B
  5. class TestOptimizeAdvanced(unittest.TestCase):
  6. def setUp(self):
  7. self.foo = S('command', 'foo')
  8. self.bar = S('command', 'bar')
  9. def test_eliminate_common_subexpressions(self):
  10. pass
  11. def test_copy_propagation_true(self):
  12. print "testing true"
  13. block = B([self.foo,
  14. S('command', 'move', '$1', '$2'),
  15. self.foo,
  16. S('command', 'addu', '$3', '$1', '$4'),
  17. self.bar])
  18. copy_propagation(block)
  19. self.assertEqual(block.statements, [self.foo,
  20. S('command', 'move', '$1', '$2'),
  21. self.foo,
  22. S('command', 'addu', '$3', '$2', '$4'),
  23. self.bar])
  24. print "Test true succesfull"
  25. # def test_copy_propagation_false(self):
  26. # print "Testing false"
  27. # arguments = [self.foo,
  28. # S('command', 'move', '$1', '$2'),
  29. # S('command', 'move', '$10', '$20'),
  30. # S('command', 'addu', '$1', '$5', 1),
  31. # S('command', 'addu', '$3', '$1', '$4'),
  32. # self.bar]
  33. # block = B(arguments)
  34. #
  35. # copy_propagation(block)
  36. # self.assertEqual(block.statements, arguments)