Exemplo n.º 1
0
def test_not_calling_end_explodes():
    F1 = lltype.FuncType([lltype.Signed], lltype.Signed)
    rgenop = RGenOp()
    sigtoken = rgenop.sigToken(F1)
    builder, gv_adder, [gv_x] = rgenop.newgraph(sigtoken, "adder")
    builder.start_writing()
    gv_result = builder.genop2("int_add", gv_x, rgenop.genconst(5))
    builder.finish_and_return(sigtoken, gv_result)
    #builder.end() <--- the point
    ptr = gv_adder.revealconst(lltype.Ptr(F1))
    py.test.raises(AssertionError, "testgengraph(ptr._obj.graph, [1])")
Exemplo n.º 2
0
def test_not_calling_end_explodes():
    F1 = lltype.FuncType([lltype.Signed], lltype.Signed)
    rgenop = RGenOp()
    sigtoken = rgenop.sigToken(F1)
    builder, gv_adder, [gv_x] = rgenop.newgraph(sigtoken, "adder")
    builder.start_writing()
    gv_result = builder.genop2("int_add", gv_x, rgenop.genconst(5))
    builder.finish_and_return(sigtoken, gv_result)
    #builder.end() <--- the point
    ptr = gv_adder.revealconst(lltype.Ptr(F1))
    py.test.raises(AssertionError, "testgengraph(ptr._obj.graph, [1])")
Exemplo n.º 3
0
def rundemo(entrypoint, *args):
    view = conftest.option.view
    seed = demo_conftest.option.randomseed
    benchmark = bench_conftest.option.benchmark

    logfile = str(udir.join('%s.log' % (entrypoint.__name__,)))
    try:
        os.unlink(logfile)
    except OSError:
        pass
    os.environ['PYPYJITLOG'] = logfile

    if benchmark:
        py.test.skip("benchmarking: working in progress")
        arglist = ', '.join(['a%d' % i for i in range(len(args))])
        miniglobals = {'Benchmark': bench_conftest.Benchmark,
                       'original_entrypoint': entrypoint}
        exec py.code.Source("""
            def benchmark_runner(%s):
                bench = Benchmark()
                while 1:
                    res = original_entrypoint(%s)
                    if bench.stop():
                        break
                return res
        """ % (arglist, arglist)).compile() in miniglobals
        entrypoint = miniglobals['benchmark_runner']

    nb_args = len(args)      # XXX ints only for now
    if machine_code_dumper:
        machine_code_dumper._freeze_() # clean up state
    rgenop = RGenOp()
    gv_entrypoint = rcompile(rgenop, entrypoint, [int]*nb_args,
                             random_seed=seed)
    if machine_code_dumper:
        machine_code_dumper._freeze_()    # clean up state

    print
    print 'Random seed value: %d' % (seed,)
    print

    print 'Running %s(%s)...' % (entrypoint.__name__,
                                 ', '.join(map(repr, args)))
    expected = entrypoint(*args)
    print 'Python ===>', expected
    F1 = lltype.FuncType([lltype.Signed] * nb_args, lltype.Signed)
    fp = RGenOp.get_python_callable(lltype.Ptr(F1), gv_entrypoint)
    res = runfp(fp, *args)
    print '%-6s ===>' % RGenOp.__name__, res
    print
    if res != expected:
        raise AssertionError(
            "expected return value is %s, got %s\nseed = %s" % (
                expected, res, seed))

    if view and machine_code_dumper:
        from pypy.jit.codegen.i386.viewcode import World
        world = World()
        world.parse(open(logfile))
        world.show()
Exemplo n.º 4
0
def rundemo(entrypoint, *args):
    view = conftest.option.view
    seed = demo_conftest.option.randomseed
    benchmark = bench_conftest.option.benchmark

    logfile = str(udir.join('%s.log' % (entrypoint.__name__, )))
    try:
        os.unlink(logfile)
    except OSError:
        pass
    os.environ['PYPYJITLOG'] = logfile

    if benchmark:
        py.test.skip("benchmarking: working in progress")
        arglist = ', '.join(['a%d' % i for i in range(len(args))])
        miniglobals = {
            'Benchmark': bench_conftest.Benchmark,
            'original_entrypoint': entrypoint
        }
        exec py.code.Source("""
            def benchmark_runner(%s):
                bench = Benchmark()
                while 1:
                    res = original_entrypoint(%s)
                    if bench.stop():
                        break
                return res
        """ % (arglist, arglist)).compile() in miniglobals
        entrypoint = miniglobals['benchmark_runner']

    nb_args = len(args)  # XXX ints only for now
    if machine_code_dumper:
        machine_code_dumper._freeze_()  # clean up state
    rgenop = RGenOp()
    gv_entrypoint = rcompile(rgenop,
                             entrypoint, [int] * nb_args,
                             random_seed=seed)
    if machine_code_dumper:
        machine_code_dumper._freeze_()  # clean up state

    print
    print 'Random seed value: %d' % (seed, )
    print

    print 'Running %s(%s)...' % (entrypoint.__name__, ', '.join(map(
        repr, args)))
    expected = entrypoint(*args)
    print 'Python ===>', expected
    F1 = lltype.FuncType([lltype.Signed] * nb_args, lltype.Signed)
    fp = RGenOp.get_python_callable(lltype.Ptr(F1), gv_entrypoint)
    res = runfp(fp, *args)
    print '%-6s ===>' % RGenOp.__name__, res
    print
    if res != expected:
        raise AssertionError("expected return value is %s, got %s\nseed = %s" %
                             (expected, res, seed))

    if view and machine_code_dumper:
        from pypy.jit.codegen.i386.viewcode import World
        world = World()
        world.parse(open(logfile))
        world.show()