|
@@ -109,3 +109,110 @@ class TestOptimize(unittest.TestCase):
|
|
|
optimize_global(block)
|
|
optimize_global(block)
|
|
|
|
|
|
|
|
self.assertEquals(block.statements, arguments)
|
|
self.assertEquals(block.statements, arguments)
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_shift_true(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ block = B([foo,
|
|
|
|
|
+ S('command', 'sll', '$regA', '$regA', 0),
|
|
|
|
|
+ bar])
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, [foo,
|
|
|
|
|
+ bar])
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_shift_false(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ arguments = [foo, \
|
|
|
|
|
+ S('command', 'sll', '$regA', '$regB', 0), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block = B(arguments)
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, arguments)
|
|
|
|
|
+
|
|
|
|
|
+ arguments2 = [foo, \
|
|
|
|
|
+ S('command', 'sll', '$regA', '$regA', 1), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block2 = B(arguments2)
|
|
|
|
|
+ optimize_global(block2)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block2.statements, arguments2)
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_add_lw_true(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ block = B([foo,
|
|
|
|
|
+ S('command', 'add', '$regA', '$regA', 10),
|
|
|
|
|
+ S('command', 'lw', '$regB', '0($regA)'),
|
|
|
|
|
+ bar])
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, [foo,
|
|
|
|
|
+ S('command', 'lw', '$regB', '10($regA)'),
|
|
|
|
|
+ bar])
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_add_lw_false(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ arguments = [foo, \
|
|
|
|
|
+ S('command', 'add', '$regA', '$regA', 10), \
|
|
|
|
|
+ S('command', 'lw', '$regB', '0($regC)'), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block = B(arguments)
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ arguments2 = [foo, \
|
|
|
|
|
+ S('command', 'add', '$regA', '$regB', 10), \
|
|
|
|
|
+ S('command', 'lw', '$regB', '0($regA)'), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block2 = B(arguments2)
|
|
|
|
|
+
|
|
|
|
|
+ arguments3 = [foo, \
|
|
|
|
|
+ S('command', 'add', '$regA', '$regA', 10), \
|
|
|
|
|
+ S('command', 'lw', '$regB', '1($regA)'), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block3 = B(arguments3)
|
|
|
|
|
+ optimize_global(block3)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, arguments)
|
|
|
|
|
+ self.assertEquals(block2.statements, arguments2)
|
|
|
|
|
+ self.assertEquals(block3.statements, arguments3)
|
|
|
|
|
+
|
|
|
|
|
+ # beq ..., $Lx -> bne ..., $Ly
|
|
|
|
|
+ # j $Ly $Lx:
|
|
|
|
|
+ # $Lx:
|
|
|
|
|
+ def test_optimize_global_beq_j_true(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ block = B([foo,
|
|
|
|
|
+ S('command', 'beq', '$regA', '$regB', '$Lx'),
|
|
|
|
|
+ S('command', 'j', '$Ly'),
|
|
|
|
|
+ S('label', '$Lx'),
|
|
|
|
|
+ bar])
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, [foo,
|
|
|
|
|
+ S('command', 'bne', '$regA', '$regB', '$Ly'),
|
|
|
|
|
+ S('label', '$Lx'),
|
|
|
|
|
+ bar])
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_beq_j_false(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ arguments = [foo, \
|
|
|
|
|
+ S('command', 'beq', '$regA', '$regB', '$Lz'), \
|
|
|
|
|
+ S('command', 'j', '$Ly'), \
|
|
|
|
|
+ S('label', '$Lx'), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block = B(arguments)
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, arguments)
|