Exemplo n.º 1
0
    def test_subtraction(self):
        opt = Optimizer([ConstantFold])
        opt.add_operation(Types.INT, Operations.INT_SUB,
            [opt.new_constant_int(1), opt.new_constant_int(0)]
        )
        ops = opt.build_operations()

        assert len(ops) == 0
Exemplo n.º 2
0
    def test_addition(self):
        opt = Optimizer([ConstantFold])

        res = opt.add_operation(Types.INT, Operations.INT_ADD,
            [opt.new_constant_int(1), opt.new_constant_int(0)]
        )
        ops = opt.build_operations()

        assert len(ops) == 0
        assert opt.getvalue(res).getint() == 1
Exemplo n.º 3
0
    def test_gt(self):
        opt = Optimizer([IntBounds, GuardPropagation])
        i0 = opt.add_input(Types.INT)

        i1 = opt.add_operation(Operations.INT_GT,
                               [i0, opt.new_constant_int(10)])
        opt.add_operation(Operations.GUARD_TRUE, [i1])
        opt.add_operation(Operations.INT_GT, [i0, opt.new_constant_int(5)])

        ops = opt.build_operations()
        assert len(ops) == 2
Exemplo n.º 4
0
    def test_lt(self):
        opt = Optimizer([IntBounds, GuardPropagation])
        i0 = opt.add_input(Types.INT)

        i1 = opt.add_operation(Types.INT, Operations.INT_LT,
            [i0, opt.new_constant_int(10)],
        )
        opt.add_operation(Types.VOID, Operations.GUARD_TRUE, [i1])
        opt.add_operation(Types.INT, Operations.INT_LT, [i0, opt.new_constant_int(15)])

        ops = opt.build_operations()
        assert len(ops) == 2
Exemplo n.º 5
0
    def test_ge_reverse(self):
        opt = Optimizer([IntBounds, GuardPropagation])
        i0 = opt.add_input(Types.INT)

        i1 = opt.add_operation(Operations.INT_LT,
                               [i0, opt.new_constant_int(5)])
        opt.add_operation(Operations.GUARD_TRUE, [i1])
        i2 = opt.add_operation(Operations.INT_GE,
                               [i0, opt.new_constant_int(7)])
        opt.add_operation(Operations.GUARD_FALSE, [i2])

        ops = opt.build_operations()
        assert len(ops) == 2
        assert opt.getvalue(i2).getint() == 0
Exemplo n.º 6
0
    def test_lt_reverse(self):
        opt = Optimizer([IntBounds, GuardPropagation])
        i0 = opt.add_input(Types.INT)

        i1 = opt.add_operation(Types.INT, Operations.INT_GT,
            [i0, opt.new_constant_int(5)]
        )
        opt.add_operation(Types.VOID, Operations.GUARD_TRUE, [i1])
        i2 = opt.add_operation(Types.INT, Operations.INT_LT,
            [i0, opt.new_constant_int(3)]
        )
        opt.add_operation(Types.VOID, Operations.GUARD_FALSE, [i2])

        ops = opt.build_operations()
        assert len(ops) == 2
        assert opt.getvalue(i2).getint() == 0
Exemplo n.º 7
0
    def test_cant_fold(self):
        opt = Optimizer([ConstantFold])
        i0 = opt.add_input(Types.INT)

        opt.add_operation(Operations.INT_ADD, [i0, opt.new_constant_int(1)])
        ops = opt.build_operations()
        assert len(ops) == 1
Exemplo n.º 8
0
    def test_subtraction(self):
        opt = Optimizer([ConstantFold])
        opt.add_operation(Types.INT, Operations.INT_SUB,
                          [opt.new_constant_int(1),
                           opt.new_constant_int(0)])
        ops = opt.build_operations()

        assert len(ops) == 0
Exemplo n.º 9
0
    def test_cant_fold(self):
        opt = Optimizer([ConstantFold])
        i0 = opt.add_input(Types.INT)

        opt.add_operation(Types.INT, Operations.INT_ADD,
            [i0, opt.new_constant_int(1)]
        )
        ops = opt.build_operations()
        assert len(ops) == 1
Exemplo n.º 10
0
    def test_subtraction(self):
        opt = Optimizer([ConstantFold])
        res = opt.add_operation(
            Operations.INT_SUB,
            [opt.new_constant_int(1),
             opt.new_constant_int(0)])
        ops = opt.build_operations()

        assert len(ops) == 0
        assert opt.getvalue(res).getint() == 1
Exemplo n.º 11
0
    def test_guard_false(self):
        opt = Optimizer([ConstantFold, GuardPropagation])
        i0 = opt.add_input(Types.INT)

        opt.add_operation(Types.VOID, Operations.GUARD_FALSE, [i0])
        opt.add_operation(Types.INT, Operations.INT_EQ, [i0, opt.new_constant_int(1)])

        ops = opt.build_operations()
        assert len(ops) == 1

        assert opt.getvalue(i0).getint() == 0
Exemplo n.º 12
0
    def test_guard_value(self):
        opt = Optimizer([GuardPropagation])
        i0 = opt.add_input(Types.INT)

        opt.add_operation(Operations.GUARD_VALUE,
                          [i0, opt.new_constant_int(5)])

        ops = opt.build_operations()
        assert len(ops) == 1

        assert opt.getvalue(i0).getint() == 5
Exemplo n.º 13
0
    def test_guard_false(self):
        opt = Optimizer([ConstantFold, GuardPropagation])
        i0 = opt.add_input(Types.INT)

        opt.add_operation(Operations.GUARD_FALSE, [i0])
        opt.add_operation(Operations.INT_EQ, [i0, opt.new_constant_int(1)])

        ops = opt.build_operations()
        assert len(ops) == 1

        assert opt.getvalue(i0).getint() == 0