Ejemplo n.º 1
0
Archivo: util.py Proyecto: qinsoon/zebu
def fncptr_from_rpy_func(rpy_fnc,
                         llargtypes,
                         llrestype,
                         mode=ctypes.RTLD_GLOBAL,
                         **kwargs):
    # NOTE: requires mu-client-pypy
    from rpython.rtyper.lltypesystem import rffi
    from rpython.translator.interactive import Translation
    from rpython.config.translationoption import set_opt_level

    preload_libmu()
    emit_dir = os.environ.get('MU_EMIT_DIR', str(bin_dir))
    kwargs.setdefault('backend', 'mu')
    kwargs.setdefault('impl', 'zebu')
    kwargs.setdefault('codegen', 'api')
    kwargs.setdefault('testjit', True)
    kwargs.setdefault('vmargs', "--aot-emit-dir=" + emit_dir)
    kwargs.setdefault('suplibdir', str(bin_dir))
    kwargs.setdefault('no_ovf', True)

    t = Translation(rpy_fnc, llargtypes, **kwargs)
    set_opt_level(t.config, '3')
    if kwargs['backend'] == 'mu':
        db, bdlgen, fnc_name = t.compile_mu()
        emit_dir = py.path.local(emit_dir)
        libpath = emit_dir.join('lib%(fnc_name)s' % locals() + libext)
        bdlgen.mu.compile_to_sharedlib(libpath.strpath, [])
        extras = (db, bdlgen)
    else:
        libpath = t.compile_c()
        fnc_name = 'pypy_g_' + rpy_fnc.__name__
        extras = None
    return rffi_fncptr_from_lib(libpath, fnc_name, llargtypes, llrestype,
                                mode), extras
Ejemplo n.º 2
0
def test_run_translation():
    from rpython.rtyper.test.test_llinterp import get_interpreter
    from rpython.translator.goal import unixcheckpoint
    from rpython.config.translationoption import get_combined_translation_config
    from rpython.config.translationoption import set_opt_level

    config = get_combined_translation_config(translating=True)
    config.translation.gc = 'boehm'
    set_opt_level(config, level='jit')
    config.translation.backendopt.inline_threshold = 0.1

    try:
        interp, graph = get_interpreter(run, [], backendopt=False,
                                        config=config)
    except Exception, e:
        print '%s: %s' % (e.__class__, e)
        pdb.post_mortem(sys.exc_info()[2])
        raise
Ejemplo n.º 3
0
def test_run_translation():
    from rpython.rtyper.test.test_llinterp import get_interpreter
    from rpython.translator.goal import unixcheckpoint
    from rpython.config.translationoption import get_combined_translation_config
    from rpython.config.translationoption import set_opt_level

    config = get_combined_translation_config(translating=True)
    config.translation.gc = 'boehm'
    set_opt_level(config, level='jit')
    config.translation.backendopt.inline_threshold = 0.1

    try:
        interp, graph = get_interpreter(run, [],
                                        backendopt=False,
                                        config=config)
    except Exception, e:
        print '%s: %s' % (e.__class__, e)
        pdb.post_mortem(sys.exc_info()[2])
        raise
Ejemplo n.º 4
0
def test_set_opt_level():
    conf = get_pypy_config()
    set_opt_level(conf, '0')
    assert conf.translation.gc == 'boehm'
    assert conf.translation.backendopt.none == True
    conf = get_pypy_config()
    set_opt_level(conf, '2')
    assert conf.translation.gc != 'boehm'
    assert not conf.translation.backendopt.none
    conf = get_pypy_config()
    set_opt_level(conf, 'mem')
    assert conf.translation.gcremovetypeptr
    assert not conf.translation.backendopt.none
Ejemplo n.º 5
0
def test_set_opt_level():
    conf = get_pypy_config()
    set_opt_level(conf, '0')
    assert conf.translation.gc == 'boehm'
    assert conf.translation.backendopt.none == True
    conf = get_pypy_config()
    set_opt_level(conf, '2')
    assert conf.translation.gc != 'boehm'
    assert not conf.translation.backendopt.none
    conf = get_pypy_config()
    set_opt_level(conf, 'mem')
    assert conf.translation.gcremovetypeptr
    assert not conf.translation.backendopt.none
Ejemplo n.º 6
0
from pypy.objspace.std import Space
from rpython.config.translationoption import set_opt_level
from pypy.config.pypyoption import get_pypy_config, set_pypy_opt_level
from pypy.objspace.std import multimethod
from rpython.rtyper.annlowlevel import llhelper, llstr, hlstr
from rpython.rtyper.lltypesystem.rstr import STR
from rpython.rtyper.lltypesystem import lltype
from pypy.interpreter.pycode import PyCode
from rpython.translator.goal import unixcheckpoint

config = get_pypy_config(translating=True)
config.translation.backendopt.inline_threshold = 0.1
config.translation.gc = "boehm"
config.translating = True
config.translation.rweakref = False
set_opt_level(config, level="jit")
config.objspace.allworkingmodules = False
config.objspace.usemodules.pypyjit = True
config.objspace.usemodules.array = False
config.objspace.usemodules._weakref = False
config.objspace.usemodules._sre = False
config.objspace.usemodules._lsprof = False
#
config.objspace.usemodules._rawffi = False
config.objspace.usemodules.micronumpy = False
#
set_pypy_opt_level(config, level="jit")

config.objspace.std.multimethods = "mrd"
multimethod.Installer = multimethod.InstallerVersion2
print config
Ejemplo n.º 7
0
from pypy.objspace.std import Space
from rpython.config.translationoption import set_opt_level
from pypy.config.pypyoption import get_pypy_config, set_pypy_opt_level
from rpython.rtyper.annlowlevel import llhelper, llstr, hlstr
from rpython.rtyper.lltypesystem.rstr import STR
from rpython.rtyper.lltypesystem import lltype
from pypy.interpreter.pycode import PyCode
from rpython.translator.goal import unixcheckpoint
import pypy.module.pypyjit.interp_jit

config = get_pypy_config(translating=True)
config.translation.backendopt.inline_threshold = 0.1
config.translation.gc = 'boehm'
config.translating = True
config.translation.rweakref = False
set_opt_level(config, level='jit')
config.objspace.allworkingmodules = False
config.objspace.usemodules.pypyjit = True
config.objspace.usemodules.array = False
config.objspace.usemodules._weakref = False
config.objspace.usemodules.struct = True
config.objspace.usemodules.time = True
config.objspace.usemodules._sre = False
config.objspace.usemodules._lsprof = False
#
config.objspace.usemodules._rawffi = False
config.objspace.usemodules.micronumpy = False
#
set_pypy_opt_level(config, level='jit')

print config
Ejemplo n.º 8
0
def parse_options_and_load_target():
    opt_parser = optparse.OptionParser(usage="%prog [options] [target] [target-specific-options]",
                                       prog="translate",
                                       formatter=OptHelpFormatter(),
                                       add_help_option=False)

    opt_parser.disable_interspersed_args()

    config = get_combined_translation_config(translating=True)
    to_optparse(config, parser=opt_parser, useoptions=['translation.*'])
    translateconfig = Config(translate_optiondescr)
    to_optparse(translateconfig, parser=opt_parser)

    options, args = opt_parser.parse_args()

    # set goals and skipped_goals
    reset = False
    for name, _, _, _ in GOALS:
        if name.startswith('?'):
            continue
        if getattr(translateconfig.goal_options, name):
            if name not in translateconfig.goals:
                translateconfig.goals.append(name)
        if getattr(translateconfig.goal_options, 'no_' + name):
            if name not in translateconfig.skipped_goals:
                if not reset:
                    translateconfig.skipped_goals[:] = []
                    reset = True
                translateconfig.skipped_goals.append(name)

    if args:
        arg = args[0]
        args = args[1:]
        if os.path.isfile(arg + '.py'):
            assert not os.path.isfile(arg), (
                "ambiguous file naming, please rename %s" % arg)
            translateconfig.targetspec = arg
        elif os.path.isfile(arg) and arg.endswith('.py'):
            translateconfig.targetspec = arg[:-3]
        else:
            log.ERROR("Could not find target %r" % (arg, ))
            sys.exit(1)
    else:
        show_help(translateconfig, opt_parser, None, config)

    # print the version of the host
    # (if it's PyPy, it includes the hg checksum)
    log.info(sys.version)

    # apply the platform settings
    set_platform(config)

    targetspec = translateconfig.targetspec
    targetspec_dic = load_target(targetspec)

    if args and not targetspec_dic.get('take_options', False):
        log.WARNING("target specific arguments supplied but will be ignored: %s" % ' '.join(args))

    # give the target the possibility to get its own configuration options
    # into the config
    if 'get_additional_config_options' in targetspec_dic:
        optiondescr = targetspec_dic['get_additional_config_options']()
        config = get_combined_translation_config(
                optiondescr,
                existing_config=config,
                translating=True)

    # show the target-specific help if --help was given
    show_help(translateconfig, opt_parser, targetspec_dic, config)

    # apply the optimization level settings
    set_opt_level(config, translateconfig.opt)

    # let the target modify or prepare itself
    # based on the config
    if 'handle_config' in targetspec_dic:
        targetspec_dic['handle_config'](config, translateconfig)

    return targetspec_dic, translateconfig, config, args
Ejemplo n.º 9
0
from pypy.objspace.std import Space
from rpython.config.translationoption import set_opt_level
from pypy.config.pypyoption import get_pypy_config, set_pypy_opt_level
from rpython.rtyper.annlowlevel import llhelper, llstr, hlstr
from rpython.rtyper.lltypesystem.rstr import STR
from rpython.rtyper.lltypesystem import lltype
from pypy.interpreter.pycode import PyCode
from rpython.translator.goal import unixcheckpoint
import pypy.module.pypyjit.interp_jit

config = get_pypy_config(translating=True)
config.translation.backendopt.inline_threshold = 0.1
config.translation.gc = 'boehm'
config.translating = True
config.translation.rweakref = False
set_opt_level(config, level='jit')
config.objspace.allworkingmodules = False
config.objspace.usemodules.pypyjit = True
config.objspace.usemodules.array = False
config.objspace.usemodules._weakref = False
config.objspace.usemodules.struct = True
config.objspace.usemodules.time = True
config.objspace.usemodules._sre = False
config.objspace.usemodules._lsprof = False
#
config.objspace.usemodules._rawffi = False
config.objspace.usemodules.micronumpy = False
#
set_pypy_opt_level(config, level='jit')

print config
Ejemplo n.º 10
0
def parse_options_and_load_target():
    opt_parser = optparse.OptionParser(
        usage="%prog [options] [target] [target-specific-options]",
        prog="translate",
        formatter=OptHelpFormatter(),
        add_help_option=False)

    opt_parser.disable_interspersed_args()

    config = get_combined_translation_config(translating=True)
    to_optparse(config, parser=opt_parser, useoptions=['translation.*'])
    translateconfig = Config(translate_optiondescr)
    to_optparse(translateconfig, parser=opt_parser)

    options, args = opt_parser.parse_args()

    # set goals and skipped_goals
    reset = False
    for name, _, _, _ in GOALS:
        if name.startswith('?'):
            continue
        if getattr(translateconfig.goal_options, name):
            if name not in translateconfig.goals:
                translateconfig.goals.append(name)
        if getattr(translateconfig.goal_options, 'no_' + name):
            if name not in translateconfig.skipped_goals:
                if not reset:
                    translateconfig.skipped_goals[:] = []
                    reset = True
                translateconfig.skipped_goals.append(name)

    if args:
        arg = args[0]
        args = args[1:]
        if os.path.isfile(arg + '.py'):
            assert not os.path.isfile(arg), (
                "ambiguous file naming, please rename %s" % arg)
            translateconfig.targetspec = arg
        elif os.path.isfile(arg) and arg.endswith('.py'):
            translateconfig.targetspec = arg[:-3]
        else:
            log.ERROR("Could not find target %r" % (arg, ))
            sys.exit(1)
    else:
        show_help(translateconfig, opt_parser, None, config)

    # print the version of the host
    # (if it's PyPy, it includes the hg checksum)
    log.info(sys.version)

    # apply the platform settings
    set_platform(config)

    targetspec = translateconfig.targetspec
    targetspec_dic = load_target(targetspec)

    if args and not targetspec_dic.get('take_options', False):
        log.WARNING(
            "target specific arguments supplied but will be ignored: %s" %
            ' '.join(args))

    # give the target the possibility to get its own configuration options
    # into the config
    if 'get_additional_config_options' in targetspec_dic:
        optiondescr = targetspec_dic['get_additional_config_options']()
        config = get_combined_translation_config(optiondescr,
                                                 existing_config=config,
                                                 translating=True)

    # show the target-specific help if --help was given
    show_help(translateconfig, opt_parser, targetspec_dic, config)

    # apply the optimization level settings
    set_opt_level(config, translateconfig.opt)

    # let the target modify or prepare itself
    # based on the config
    if 'handle_config' in targetspec_dic:
        targetspec_dic['handle_config'](config, translateconfig)

    return targetspec_dic, translateconfig, config, args