1import os
2from scripts.test import shared
3from . import utils
4
5
6class StackIRTest(utils.BinaryenTestCase):
7    # test that stack IR opts make a difference.
8    def test_stack_ir_opts(self):
9        path = self.input_path('stack_ir.wat')
10        opt = shared.run_process(shared.WASM_OPT + [path, '-O', '--generate-stack-ir', '--optimize-stack-ir', '--print-stack-ir', '-o', 'a.wasm'], capture_output=True).stdout
11        nonopt = shared.run_process(shared.WASM_OPT + [path, '-O', '--generate-stack-ir', '--print-stack-ir', '-o', 'b.wasm'], capture_output=True).stdout
12        # see a difference in the printed stack IR (the optimizations let us
13        # remove a pair of local.set/get)
14        self.assertNotEqual(opt, nonopt)
15        self.assertLess(len(opt), len(nonopt))
16        # see a difference in the actual emitted wasm binary.
17        opt_size = os.path.getsize('a.wasm')
18        nonopt_size = os.path.getsize('b.wasm')
19        self.assertLess(opt_size, nonopt_size)
20