예제 #1
0
def test_load_undef(ctx, func, bld):
    zero = ctx.reg_a.type.create(0)
    bld.build_rload(ctx.reg_a)
    bld.build_rstore(ctx.reg_a, zero)
    bld.build_ret()

    regs = {}
    interpreter.run(func, regs)
    assert regs == {ctx.reg_a: LiveValue.from_value(zero)}
예제 #2
0
def test_store_undef(ctx, func, bld):
    undef_value = bld.build_rload(ctx.reg_a)
    bld.build_rstore(ctx.reg_b, undef_value)
    bld.build_ret()

    regs = {}
    interpreter.run(func, regs)
    print(regs)
    assert regs == {ctx.reg_b: LiveValue(ctx.reg_a.type)}
예제 #3
0
def run_before_and_after_optimization(func, optimization, regs, expected_regs):
    for run_opt in (False, True):
        if run_opt:
            optimization.process_function(func)
        import decompil.utils
        print(decompil.utils.format_to_str(func))

        regs_copy = dict(regs)
        interpreter.run(func, regs_copy)
        for reg, value in expected_regs.items():
            assert regs_copy[reg] == value
예제 #4
0
파일: utils.py 프로젝트: mewbak/decompil
def run_before_and_after_optimization(func, optimization, regs, expected_regs):
    for run_opt in (False, True):
        if run_opt:
            optimization.process_function(func)
        import decompil.utils
        print(decompil.utils.format_to_str(func))

        regs_copy = dict(regs)
        interpreter.run(func, regs_copy)
        for reg, value in expected_regs.items():
            assert regs_copy[reg] == value
예제 #5
0
def test_use_undef(ctx, func, bld):
    undef_value = bld.build_rload(ctx.reg_a)
    error_value = bld.build_add(undef_value, undef_value)
    bld.build_rstore(ctx.reg_b, error_value)
    bld.build_ret()
    try:
        interpreter.run(func, {})
    except AssertionError:
        pass
    else:
        assert False
예제 #6
0
def test_basic(ctx, func, bld):
    """Test that ALLOCA + STORE + LOAD in a raw works properly."""
    var_addr = bld.build_alloca(ctx.reg_a.type)
    bld.build_store(var_addr, ctx.reg_a.type.create(0))
    bld.build_rstore(ctx.reg_b, bld.build_load(var_addr))
    bld.build_ret()

    regs = {ctx.reg_a: LiveValue(ctx.reg_a.type, 0)}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 0),
        ctx.reg_b: LiveValue(ctx.reg_a.type, 0),
    }
예제 #7
0
def test_same_alloca_twice(ctx, func, bld):
    """
    Test that one ALLOCA executed multiple times yields different pointers.
    """
    bb_loop_start = bld.create_basic_block()
    bb_loop_store_1 = bld.create_basic_block()
    bb_loop_store_2 = bld.create_basic_block()
    bb_loop_end = bld.create_basic_block()
    bb_end = bld.create_basic_block()
    i_reg = ctx.reg_a
    reg_1 = ctx.reg_b
    reg_2 = ctx.reg_c

    bld.build_rstore(i_reg, i_reg.type.create(2))
    bld.build_jump(bb_loop_start)

    bld.position_at_end(bb_loop_start)
    var_addr = bld.build_alloca(ctx.double_type)
    var_int = bld.build_bitcast(reg_1.type, var_addr)
    bld.build_rstore(
        i_reg, bld.build_sub(bld.build_rload(i_reg), i_reg.type.create(1)))
    bld.build_branch(
        bld.build_eq(bld.build_rload(i_reg), i_reg.type.create(0)),
        bb_loop_store_1, bb_loop_store_2)

    bld.position_at_end(bb_loop_store_1)
    bld.build_rstore(reg_1, var_int)
    bld.build_jump(bb_loop_end)

    bld.position_at_end(bb_loop_store_2)
    bld.build_rstore(reg_2, var_int)
    bld.build_jump(bb_loop_end)

    bld.position_at_end(bb_loop_end)
    bld.build_branch(
        bld.build_ugt(bld.build_rload(i_reg), i_reg.type.create(0)),
        bb_loop_start, bb_end)

    bld.position_at_end(bb_end)
    bld.build_ret()

    regs = {}
    interpreter.run(func, regs)
    assert set(regs) == {ctx.reg_a, ctx.reg_b, ctx.reg_c}
    assert regs[ctx.reg_a] == LiveValue(ctx.reg_a.type, 0)
    assert regs[ctx.reg_b] != regs[ctx.reg_c]
예제 #8
0
def test_asymetric_phi(ctx, func):
    zero = LiveValue(ctx.reg_a.type, 0)
    one = LiveValue(ctx.reg_a.type, 1)
    two = LiveValue(ctx.reg_a.type, 2)

    regs = {ctx.reg_a: zero, ctx.reg_b: one}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: zero,
        ctx.reg_b: one,
        ctx.reg_c: one,
    }

    regs = {ctx.reg_a: two, ctx.reg_b: one}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: two,
        ctx.reg_b: one,
        ctx.reg_c: two,
    }
예제 #9
0
파일: material.py 프로젝트: mewbak/decompil
def test_asymetric_phi(ctx, func):
    zero = LiveValue(ctx.reg_a.type, 0)
    one = LiveValue(ctx.reg_a.type, 1)
    two = LiveValue(ctx.reg_a.type, 2)

    regs = {ctx.reg_a: zero, ctx.reg_b: one}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: zero,
        ctx.reg_b: one,
        ctx.reg_c: one,
    }

    regs = {ctx.reg_a: two, ctx.reg_b: one}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: two,
        ctx.reg_b: one,
        ctx.reg_c: two,
    }
예제 #10
0
파일: material.py 프로젝트: mewbak/decompil
def test_simple_phi(ctx, func):
    base_regs = {
        ctx.reg_b: LiveValue(ctx.reg_b.type, 1),
        ctx.reg_c: LiveValue(ctx.reg_c.type, 2),
    }
    regs = dict(base_regs)
    regs[ctx.reg_a] = LiveValue(ctx.reg_b.type, 1)
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 1),
        ctx.reg_b: base_regs[ctx.reg_b],
        ctx.reg_c: base_regs[ctx.reg_c],
        ctx.reg_d: base_regs[ctx.reg_b],
    }

    regs = dict(base_regs)
    regs[ctx.reg_a] = LiveValue(ctx.reg_b.type, 0)
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 0),
        ctx.reg_b: base_regs[ctx.reg_b],
        ctx.reg_c: base_regs[ctx.reg_c],
        ctx.reg_d: base_regs[ctx.reg_c],
    }
예제 #11
0
def test_simple_phi(ctx, func):
    base_regs = {
        ctx.reg_b: LiveValue(ctx.reg_b.type, 1),
        ctx.reg_c: LiveValue(ctx.reg_c.type, 2),
    }
    regs = dict(base_regs)
    regs[ctx.reg_a] = LiveValue(ctx.reg_b.type, 1)
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 1),
        ctx.reg_b: base_regs[ctx.reg_b],
        ctx.reg_c: base_regs[ctx.reg_c],
        ctx.reg_d: base_regs[ctx.reg_b],
    }

    regs = dict(base_regs)
    regs[ctx.reg_a] = LiveValue(ctx.reg_b.type, 0)
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 0),
        ctx.reg_b: base_regs[ctx.reg_b],
        ctx.reg_c: base_regs[ctx.reg_c],
        ctx.reg_d: base_regs[ctx.reg_c],
    }
예제 #12
0
파일: material.py 프로젝트: mewbak/decompil
def test_simple_loop(ctx, func):
    regs = {ctx.reg_a: LiveValue(ctx.reg_a.type, 0)}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 0),
        ctx.reg_b: LiveValue(ctx.reg_b.type, 1),
    }

    regs = {ctx.reg_a: LiveValue(ctx.reg_a.type, 1)}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 1),
        ctx.reg_b: LiveValue(ctx.reg_b.type, 2),
    }

    regs = {ctx.reg_a: LiveValue(ctx.reg_a.type, 2)}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 2),
        ctx.reg_b: LiveValue(ctx.reg_b.type, 4),
    }
예제 #13
0
def test_simple_loop(ctx, func):
    regs = {ctx.reg_a: LiveValue(ctx.reg_a.type, 0)}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 0),
        ctx.reg_b: LiveValue(ctx.reg_b.type, 1),
    }

    regs = {ctx.reg_a: LiveValue(ctx.reg_a.type, 1)}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 1),
        ctx.reg_b: LiveValue(ctx.reg_b.type, 2),
    }

    regs = {ctx.reg_a: LiveValue(ctx.reg_a.type, 2)}
    interpreter.run(func, regs)
    assert regs == {
        ctx.reg_a: LiveValue(ctx.reg_a.type, 2),
        ctx.reg_b: LiveValue(ctx.reg_b.type, 4),
    }
예제 #14
0
def test_simple_rstore(ctx, func, i):
    regs = {}
    interpreter.run(func, regs)
    assert regs == {ctx.reg_a: LiveValue(ctx.reg_a.type, i)}
예제 #15
0
파일: material.py 프로젝트: mewbak/decompil
def test_simple_rstore(ctx, func, i):
    regs = {}
    interpreter.run(func, regs)
    assert regs == {ctx.reg_a: LiveValue(ctx.reg_a.type, i)}
예제 #16
0
def test_empty(ctx, func):
    regs = {}
    assert interpreter.run(func, regs) is None
    assert not regs
예제 #17
0
파일: material.py 프로젝트: mewbak/decompil
def test_empty(ctx, func):
    regs = {}
    assert interpreter.run(func, regs) is None
    assert not regs