Ejemplo n.º 1
0
def test_compile_tmp_callback():
    from pypy.jit.codewriter import heaptracker
    from pypy.jit.backend.llgraph import runner
    from pypy.rpython.lltypesystem import lltype, llmemory
    from pypy.rpython.annlowlevel import llhelper
    from pypy.rpython.llinterp import LLException
    #
    cpu = runner.LLtypeCPU(None)
    FUNC = lltype.FuncType([lltype.Signed]*4, lltype.Signed)
    def ll_portal_runner(g1, g2, r3, r4):
        assert (g1, g2, r3, r4) == (12, 34, -156, -178)
        if raiseme:
            raise raiseme
        else:
            return 54321
    #
    class FakeJitDriverSD:
        portal_runner_ptr = llhelper(lltype.Ptr(FUNC), ll_portal_runner)
        portal_runner_adr = llmemory.cast_ptr_to_adr(portal_runner_ptr)
        portal_calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT)
        portal_finishtoken = compile.DoneWithThisFrameDescrInt()
        num_red_args = 2
        result_type = INT
    #
    loop_token = compile_tmp_callback(cpu, FakeJitDriverSD(),
                                      [ConstInt(12), ConstInt(34)],
                                      [BoxInt(56), ConstInt(78), BoxInt(90)])
    #
    raiseme = None
    cpu.set_future_value_int(0, -156)
    cpu.set_future_value_int(1, -178)
    cpu.set_future_value_int(2, -190)     # passed in, but dropped
    fail_descr = cpu.execute_token(loop_token)
    assert fail_descr is FakeJitDriverSD().portal_finishtoken
    #
    EXC = lltype.GcStruct('EXC')
    llexc = lltype.malloc(EXC)
    raiseme = LLException("exception class", llexc)
    cpu.set_future_value_int(0, -156)
    cpu.set_future_value_int(1, -178)
    cpu.set_future_value_int(2, -190)
    fail_descr = cpu.execute_token(loop_token)
    assert isinstance(fail_descr, compile.PropagateExceptionDescr)
    got = cpu.grab_exc_value()
    assert lltype.cast_opaque_ptr(lltype.Ptr(EXC), got) == llexc
    #
    class FakeMetaInterpSD:
        class ExitFrameWithExceptionRef(Exception):
            pass
    FakeMetaInterpSD.cpu = cpu
    cpu.set_future_value_int(0, -156)
    cpu.set_future_value_int(1, -178)
    cpu.set_future_value_int(2, -190)
    fail_descr = cpu.execute_token(loop_token)
    try:
        fail_descr.handle_fail(FakeMetaInterpSD(), None)
    except FakeMetaInterpSD.ExitFrameWithExceptionRef, e:
        assert lltype.cast_opaque_ptr(lltype.Ptr(EXC), e.args[1]) == llexc
Ejemplo n.º 2
0
def test_compile_tmp_callback():
    from pypy.jit.codewriter import heaptracker
    from pypy.jit.backend.llgraph import runner
    from pypy.rpython.lltypesystem import lltype, llmemory
    from pypy.rpython.annlowlevel import llhelper
    from pypy.rpython.llinterp import LLException
    #
    cpu = runner.LLtypeCPU(None)
    FUNC = lltype.FuncType([lltype.Signed] * 4, lltype.Signed)

    def ll_portal_runner(g1, g2, r3, r4):
        assert (g1, g2, r3, r4) == (12, 34, -156, -178)
        if raiseme:
            raise raiseme
        else:
            return 54321

    #
    class FakeJitDriverSD:
        portal_runner_ptr = llhelper(lltype.Ptr(FUNC), ll_portal_runner)
        portal_runner_adr = llmemory.cast_ptr_to_adr(portal_runner_ptr)
        portal_calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, None)
        portal_finishtoken = compile.DoneWithThisFrameDescrInt()
        num_red_args = 2
        result_type = INT

    #
    loop_token = compile_tmp_callback(
        cpu, FakeJitDriverSD(), [ConstInt(12), ConstInt(34)], "ii")
    #
    raiseme = None
    # only two arguments must be passed in
    fail_descr = cpu.execute_token(loop_token, -156, -178)
    assert fail_descr is FakeJitDriverSD().portal_finishtoken
    #
    EXC = lltype.GcStruct('EXC')
    llexc = lltype.malloc(EXC)
    raiseme = LLException("exception class", llexc)
    fail_descr = cpu.execute_token(loop_token, -156, -178)
    assert isinstance(fail_descr, compile.PropagateExceptionDescr)
    got = cpu.grab_exc_value()
    assert lltype.cast_opaque_ptr(lltype.Ptr(EXC), got) == llexc

    #
    class FakeMetaInterpSD:
        class ExitFrameWithExceptionRef(Exception):
            pass

    FakeMetaInterpSD.cpu = cpu
    fail_descr = cpu.execute_token(loop_token, -156, -178)
    try:
        fail_descr.handle_fail(FakeMetaInterpSD(), None)
    except FakeMetaInterpSD.ExitFrameWithExceptionRef, e:
        assert lltype.cast_opaque_ptr(lltype.Ptr(EXC), e.args[1]) == llexc
Ejemplo n.º 3
0
 def get_assembler_token(greenkey):
     cell = self.jit_cell_at_key(greenkey)
     procedure_token = cell.get_procedure_token()
     if procedure_token is None:
         from pypy.jit.metainterp.compile import compile_tmp_callback
         if cell.counter == -1:  # used to be a valid entry bridge,
             cell.counter = 0  # but was freed in the meantime.
         memmgr = warmrunnerdesc.memory_manager
         procedure_token = compile_tmp_callback(cpu, jd, greenkey,
                                                redargtypes, memmgr)
         cell.set_procedure_token(procedure_token)
     return procedure_token
Ejemplo n.º 4
0
 def get_assembler_token(greenkey):
     cell = self.jit_cell_at_key(greenkey)
     procedure_token = cell.get_procedure_token()
     if procedure_token is None:
         from pypy.jit.metainterp.compile import compile_tmp_callback
         if cell.counter == -1:    # used to be a valid entry bridge,
             cell.counter = 0      # but was freed in the meantime.
         memmgr = warmrunnerdesc.memory_manager
         procedure_token = compile_tmp_callback(cpu, jd, greenkey,
                                                redargtypes, memmgr)
         cell.set_procedure_token(procedure_token)
     return procedure_token
Ejemplo n.º 5
0
 def get_assembler_token(greenkey, redboxes):
     # 'redboxes' is only used to know the types of red arguments
     cell = self.jit_cell_at_key(greenkey)
     entry_loop_token = cell.get_entry_loop_token()
     if entry_loop_token is None:
         from pypy.jit.metainterp.compile import compile_tmp_callback
         if cell.counter == -1:    # used to be a valid entry bridge,
             cell.counter = 0      # but was freed in the meantime.
         memmgr = warmrunnerdesc.memory_manager
         entry_loop_token = compile_tmp_callback(cpu, jd, greenkey,
                                                 redboxes, memmgr)
         cell.set_entry_loop_token(entry_loop_token)
     return entry_loop_token