test_optimize_advanced.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import unittest
  2. from src.optimize.advanced import eliminate_common_subexpressions, \
  3. fold_constants, 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_fold_constants(self):
  12. pass
  13. def test_copy_propagation_true(self):
  14. print "testing true"
  15. block = B([self.foo,
  16. S('command', 'move', '$1', '$2'),
  17. self.foo,
  18. S('command', 'addu', '$3', '$1', '$4'),
  19. self.bar])
  20. copy_propagation(block)
  21. self.assertEqual(block.statements, [self.foo,
  22. S('command', 'move', '$1', '$2'),
  23. self.foo,
  24. S('command', 'addu', '$3', '$2', '$4'),
  25. self.bar])
  26. print "Test true succesfull"
  27. # def test_copy_propagation_false(self):
  28. # print "Testing false"
  29. # arguments = [self.foo,
  30. # S('command', 'move', '$1', '$2'),
  31. # S('command', 'move', '$10', '$20'),
  32. # S('command', 'addu', '$1', '$5', 1),
  33. # S('command', 'addu', '$3', '$1', '$4'),
  34. # self.bar]
  35. # block = B(arguments)
  36. # copy_propagation(block)
  37. # self.assertEqual(block.statements, arguments)