示例#1
0
def test_transform(): #XXX This uses Module transforms, think about Function transforms too.
    llvmjit.restart()
    llvmjit.parse(lldeadcode)
    deadcode = llvmjit.getNamedFunction('deadcode')
    assert llvmjit.execute(deadcode, 10) == 10 * 2
    assert llvmjit.transform(3) #optlevel = [0123]
    assert llvmjit.execute(deadcode, 20) == 20 * 2
示例#2
0
def test_getNamedFunction():
    for i in range(3):
        llvmjit.restart()
        assert not llvmjit.getNamedFunction('square')
        assert not llvmjit.getNamedFunction('square')
        assert llvmjit.parse(llsquare)
        assert llvmjit.getNamedFunction('square')
        assert llvmjit.getNamedFunction('square')
示例#3
0
def test_execute_translation(): #put this one last because it takes the most time
    skip_unsupported_platform()
    llvmjit.restart()
    def f(x):
        return execute(llsquare, 'square', x + 5)
    fn = compile(f, [int])
    res = fn(1)
    assert res == 36
示例#4
0
def test_transform(
):  #XXX This uses Module transforms, think about Function transforms too.
    llvmjit.restart()
    llvmjit.parse(lldeadcode)
    deadcode = llvmjit.getNamedFunction('deadcode')
    assert llvmjit.execute(deadcode, 10) == 10 * 2
    assert llvmjit.transform(3)  #optlevel = [0123]
    assert llvmjit.execute(deadcode, 20) == 20 * 2
示例#5
0
def test_getNamedFunction():
    for i in range(3):
        llvmjit.restart()
        assert not llvmjit.getNamedFunction('square')
        assert not llvmjit.getNamedFunction('square')
        assert llvmjit.parse(llsquare)
        assert llvmjit.getNamedFunction('square')
        assert llvmjit.getNamedFunction('square')
示例#6
0
def test_execute_multiple():
    llvmjit.restart()
    llvmjit.parse(llsquare)
    llvmjit.parse(llmul2)
    square = llvmjit.getNamedFunction('square')
    mul2 = llvmjit.getNamedFunction('mul2')
    for i in range(5):
        assert llvmjit.execute(square, i) == i * i
        assert llvmjit.execute(mul2, i) == i * 2
示例#7
0
def test_execute_multiple():
    llvmjit.restart()
    llvmjit.parse(llsquare)
    llvmjit.parse(llmul2)
    square = llvmjit.getNamedFunction('square')
    mul2   = llvmjit.getNamedFunction('mul2')
    for i in range(5):
        assert llvmjit.execute(square, i) == i * i
        assert llvmjit.execute(mul2  , i) == i * 2
示例#8
0
def test_execute_translation(
):  #put this one last because it takes the most time
    skip_unsupported_platform()
    llvmjit.restart()

    def f(x):
        return execute(llsquare, 'square', x + 5)

    fn = compile(f, [int])
    res = fn(1)
    assert res == 36
示例#9
0
def test_call_global_function(): #used by PyPy JIT for adding case(s) to a flexswitch
    llvmjit.restart()
    gp_function = llvmjit.get_pointer_to_global_function()
    llvmjit.parse(llcall_global_function)
    p = llvmjit.getNamedFunction('my_global_function...')
    assert not p
    p = llvmjit.getNamedFunction('my_global_function')
    assert p
    llvmjit.addGlobalMapping(p, gp_function) #prior to execute()!
    call_global_function = llvmjit.getNamedFunction('call_global_function')
    assert llvmjit.execute(call_global_function, 5) == 3 + 5 + 7
示例#10
0
def test_call_global_function(
):  #used by PyPy JIT for adding case(s) to a flexswitch
    llvmjit.restart()
    gp_function = llvmjit.get_pointer_to_global_function()
    llvmjit.parse(llcall_global_function)
    p = llvmjit.getNamedFunction('my_global_function...')
    assert not p
    p = llvmjit.getNamedFunction('my_global_function')
    assert p
    llvmjit.addGlobalMapping(p, gp_function)  #prior to execute()!
    call_global_function = llvmjit.getNamedFunction('call_global_function')
    assert llvmjit.execute(call_global_function, 5) == 3 + 5 + 7
示例#11
0
def test_modify_global_data():
    llvmjit.restart()
    llvmjit.set_global_data(10)
    assert llvmjit.get_global_data() == 10
    gp_data = llvmjit.get_pointer_to_global_data()
    llvmjit.parse(llglobalmul4)
    p = llvmjit.getNamedGlobal('my_global_data...')
    assert not p
    p = llvmjit.getNamedGlobal('my_global_data')
    assert p
    llvmjit.addGlobalMapping(p, gp_data)  #note: should be prior to execute()
    globalmul4 = llvmjit.getNamedFunction('globalmul4')
    assert llvmjit.execute(globalmul4, 5) == 10 * 4 + 5
    assert llvmjit.get_global_data() == 10 * 4 + 5
示例#12
0
def test_modify_global_data():
    llvmjit.restart()
    llvmjit.set_global_data(10)
    assert llvmjit.get_global_data() == 10
    gp_data = llvmjit.get_pointer_to_global_data()
    llvmjit.parse(llglobalmul4)
    p = llvmjit.getNamedGlobal('my_global_data...')
    assert not p
    p = llvmjit.getNamedGlobal('my_global_data')
    assert p
    llvmjit.addGlobalMapping(p, gp_data) #note: should be prior to execute()
    globalmul4 = llvmjit.getNamedFunction('globalmul4')
    assert llvmjit.execute(globalmul4, 5) == 10 * 4 + 5
    assert llvmjit.get_global_data() == 10 * 4 + 5
示例#13
0
def test_recompile():
    py.test.skip("recompile new function implementation test is work in progress")

    def funcA(n):
        return n + n
    
    def funcB(n):
        return n * n
    llvmjit.restart()
    llvmjit.parse(llfuncA)
    _llfuncA = llvmjit.getNamedFunction('func')
    print '_llfuncA', _llfuncA
    for i in range(5):
        assert llvmjit.execute(_llfuncA, i) == funcA(i)
    llvmjit.freeMachineCodeForFunction(_llfuncA)
    llvmjit.parse(llfuncB)
    _llfuncB = llvmjit.getNamedFunction('func')
    print '_llfuncB', _llfuncB
    llvmjit.recompile(_llfuncB) #note: because %func has changed because of the 2nd parse
    for i in range(5):
        assert llvmjit.execute(_llfuncB, i) == funcB(i)
示例#14
0
def test_execute_across_module():
    def my_across1(n):
        return n * 3

    def my_across1to2(n):
        return my_across2(n + 5)

    def my_across2(n):
        return n * 7

    def my_across2to1(n):
        return my_across1(n + 9)

    llvmjit.restart()
    llvmjit.parse(llacross1)
    llvmjit.parse(llacross2)
    across1to2 = llvmjit.getNamedFunction('across1to2')
    across2to1 = llvmjit.getNamedFunction('across2to1')
    for i in range(5):
        assert llvmjit.execute(across1to2, i) == my_across1to2(i)
        assert llvmjit.execute(across2to1, i) == my_across2to1(i)
示例#15
0
def test_execute_across_module():
    def my_across1(n):
        return n * 3

    def my_across1to2(n):
        return my_across2(n + 5)

    def my_across2(n):
        return n * 7

    def my_across2to1(n):
        return my_across1(n + 9)

    llvmjit.restart()
    llvmjit.parse(llacross1)
    llvmjit.parse(llacross2)
    across1to2 = llvmjit.getNamedFunction('across1to2')
    across2to1 = llvmjit.getNamedFunction('across2to1')
    for i in range(5):
        assert llvmjit.execute(across1to2, i) == my_across1to2(i)
        assert llvmjit.execute(across2to1, i) == my_across2to1(i)
示例#16
0
def test_recompile():
    py.test.skip(
        "recompile new function implementation test is work in progress")

    def funcA(n):
        return n + n

    def funcB(n):
        return n * n

    llvmjit.restart()
    llvmjit.parse(llfuncA)
    _llfuncA = llvmjit.getNamedFunction('func')
    print '_llfuncA', _llfuncA
    for i in range(5):
        assert llvmjit.execute(_llfuncA, i) == funcA(i)
    llvmjit.freeMachineCodeForFunction(_llfuncA)
    llvmjit.parse(llfuncB)
    _llfuncB = llvmjit.getNamedFunction('func')
    print '_llfuncB', _llfuncB
    llvmjit.recompile(
        _llfuncB)  #note: because %func has changed because of the 2nd parse
    for i in range(5):
        assert llvmjit.execute(_llfuncB, i) == funcB(i)
示例#17
0
def test_parse():
    llvmjit.restart()
    assert llvmjit.parse(llsquare)
示例#18
0
def test_execute():
    llvmjit.restart()
    assert execute(llsquare, 'square', 4) == 4 * 4
示例#19
0
def test_execute_nothing():
    llvmjit.restart()
    assert llvmjit.execute(None, 4) == -1 #-1 == no function supplied
示例#20
0
def test_execute():
    llvmjit.restart()
    assert execute(llsquare, 'square', 4) == 4 * 4
示例#21
0
def test_parse():
    llvmjit.restart()
    assert llvmjit.parse(llsquare)
示例#22
0
def test_execute_nothing():
    llvmjit.restart()
    assert llvmjit.execute(None, 4) == -1  #-1 == no function supplied