Beispiel #1
0
class DllDef:
    def __init__(self,
                 name,
                 namespace,
                 functions=[],
                 dontmangle=True,
                 isnetmodule=False):
        self.name = name
        self.namespace = namespace
        self.functions = functions  # [(function, annotation), ...]
        self.isnetmodule = isnetmodule
        self.driver = TranslationDriver()
        if dontmangle:
            self.driver.config.translation.ootype.mangle = False
        self.driver.setup_library(self)

    def add_function(self, func, inputtypes):
        self.functions.append((func, inputtypes))

    def get_entrypoint(self, bk):
        graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
        return DllEntryPoint(self.name, graphs, self.isnetmodule)

    def compile(self):
        # add all functions to the appropriate namespace
        if self.namespace:
            for func, _ in self.functions:
                if not hasattr(func, '_namespace_'):
                    func._namespace_ = self.namespace
        self.driver.proceed(['compile_cli'])
Beispiel #2
0
class DllDef:
    def __init__(self, name, namespace, functions=[], dontmangle=True, isnetmodule=False):
        self.name = name
        self.namespace = namespace
        self.functions = functions # [(function, annotation), ...]
        self.isnetmodule = isnetmodule
        self.driver = TranslationDriver()
        if dontmangle:
            self.driver.config.translation.ootype.mangle = False
        self.driver.setup_library(self)

    def add_function(self, func, inputtypes):
        self.functions.append((func, inputtypes))

    def get_entrypoint(self, bk):
        graphs = [bk.getdesc(f).cachedgraph(None) for f, _ in self.functions]
        return DllEntryPoint(self.name, graphs, self.isnetmodule)

    def compile(self):
        # add all functions to the appropriate namespace
        if self.namespace:
            for func, _ in self.functions:
                if not hasattr(func, '_namespace_'):
                    func._namespace_ = self.namespace
        self.driver.proceed(['compile_cli'])
Beispiel #3
0
def checkmodule(modname, backend, interactive=False, basepath='pypy.module'):
    "Compile a fake PyPy module."
    from pypy.objspace.fake.objspace import FakeObjSpace, W_Object
    from pypy.translator.driver import TranslationDriver

    space = FakeObjSpace()
    space.config.translating = True
    ModuleClass = __import__(basepath + '.%s' % modname,
                             None, None, ['Module']).Module
    module = ModuleClass(space, space.wrap(modname))
    w_moduledict = module.getdict(space)

    gateways = find_gateways(modname, basepath, module)
    functions = [gw.__spacebind__(space) for gw in gateways]
    arguments = Arguments.frompacked(space, W_Object(), W_Object())
    dummy_function = copy(functions[0])

    def main(argv): # use the standalone mode not to allow SomeObject
        dummy_rpython(dummy_function)        
        for func in functions:
            func.call_args(arguments)
        return 0

    patch_pypy()
    driver = TranslationDriver()
    driver.setup(main, None)
    try:
        driver.proceed(['compile_' + backend])
    except SystemExit:
        raise
    except:
        if not interactive:
            raise
        debug(driver)
        raise SystemExit(1)
Beispiel #4
0
class DLLDef(object):
    def __init__(self, name, functions=[], policy=None, config=None):
        self.name = name
        self.functions = functions # [(function, annotation), ...]
        self.driver = TranslationDriver(config=config)
        self.driver.setup_library(self, policy=policy)

    def compile(self):
        self.driver.proceed(['compile_c'])
        return self.driver.c_entryp

    def getcbuilder(self, translator, config):
        return CLibraryBuilder(translator, None, config,
                               functions=self.functions, name=self.name)
Beispiel #5
0
 def __init__(self,
              name,
              namespace,
              functions=[],
              dontmangle=True,
              isnetmodule=False):
     self.name = name
     self.namespace = namespace
     self.functions = functions  # [(function, annotation), ...]
     self.isnetmodule = isnetmodule
     self.driver = TranslationDriver()
     if dontmangle:
         self.driver.config.translation.ootype.mangle = False
     self.driver.setup_library(self)
Beispiel #6
0
 def __init__(self, name, namespace, functions=[]):
     self.name = name
     self.namespace = namespace
     self.functions = functions # [(function, annotation), ...]
     self.driver = TranslationDriver()
     self.driver.config.translation.ootype.mangle = False
     self.driver.setup_library(self)
Beispiel #7
0
class DLLDef(object):
    def __init__(self, name, functions=[], policy=None, config=None):
        self.name = name
        self.functions = functions  # [(function, annotation), ...]
        self.driver = TranslationDriver(config=config)
        self.driver.setup_library(self, policy=policy)

    def compile(self):
        self.driver.proceed(['compile_c'])
        return self.driver.c_entryp

    def getcbuilder(self, translator, config):
        return CLibraryBuilder(translator,
                               None,
                               config,
                               functions=self.functions,
                               name=self.name)
Beispiel #8
0
 def __init__(self, name, namespace, functions=[], dontmangle=True, isnetmodule=False):
     self.name = name
     self.namespace = namespace
     self.functions = functions # [(function, annotation), ...]
     self.isnetmodule = isnetmodule
     self.driver = TranslationDriver()
     if dontmangle:
         self.driver.config.translation.ootype.mangle = False
     self.driver.setup_library(self)
Beispiel #9
0
def genllvm_compile(
        function,
        annotation,
        gcpolicy='boehm',

        # debug options
        debug=False,
        logging=False,
        isolate=True,

        # pass to compile
        exe_name=None,
        optimize=True,
        extra_opts={}):
    """ helper for genllvm """

    from pypy.translator.driver import TranslationDriver
    from pypy.config.pypyoption import get_pypy_config
    config = get_pypy_config({}, translating=True)
    options = {
        'translation.backend': 'llvm',
        'translation.llvm.debug': debug,
        'translation.llvm.logging': logging,
        'translation.llvm.isolate': isolate,
        'translation.backendopt.none': not optimize,
        'translation.gc': gcpolicy,
        'translation.llvm_via_c': not native_llvm_backend
    }

    options.update(extra_opts)
    config.set(**options)
    driver = TranslationDriver(config=config, exe_name=exe_name)
    driver.setup(function, annotation)
    driver.annotate()
    if conftest.option.view:
        driver.translator.view()
    driver.rtype()
    if conftest.option.view:
        driver.translator.view()
    driver.compile()
    if conftest.option.view:
        driver.translator.view()
    return driver
Beispiel #10
0
def checkmodule(modname, backend, interactive=False, basepath='pypy.module'):
    "Compile a fake PyPy module."
    from pypy.objspace.fake.objspace import FakeObjSpace, W_Object
    from pypy.translator.driver import TranslationDriver

    space = FakeObjSpace()
    space.config.translating = True
    ModuleClass = __import__(basepath + '.%s' % modname, None, None,
                             ['Module']).Module
    module = ModuleClass(space, space.wrap(modname))
    w_moduledict = module.getdict()

    gateways = find_gateways(modname, basepath, module)
    functions = [gw.__spacebind__(space) for gw in gateways]
    arguments = AbstractArguments.frompacked(space, W_Object(), W_Object())
    dummy_function = copy(functions[0])

    def main(argv):  # use the standalone mode not to allow SomeObject
        dummy_rpython(dummy_function)
        for func in functions:
            func.call_args(arguments)
        return 0

    patch_pypy()
    driver = TranslationDriver()
    driver.setup(main, None)
    try:
        driver.proceed(['compile_' + backend])
    except SystemExit:
        raise
    except:
        if not interactive:
            raise
        debug(driver)
        raise SystemExit(1)
Beispiel #11
0
def genllvm_compile(function,
                    annotation,
                    gcpolicy='boehm',
                    
                    # debug options
                    debug=False,
                    logging=False,
                    isolate=True,
                    
                    # pass to compile
                    exe_name=None,
                    optimize=True,
                    extra_opts={}):

    """ helper for genllvm """

    from pypy.translator.driver import TranslationDriver
    from pypy.config.pypyoption import get_pypy_config
    config = get_pypy_config({}, translating=True)
    options = {
        'translation.backend': 'llvm',
        'translation.llvm.debug': debug,
        'translation.llvm.logging': logging,
        'translation.llvm.isolate': isolate,
        'translation.backendopt.none': not optimize,
        'translation.gc': gcpolicy,
        'translation.llvm_via_c' : not native_llvm_backend 
        }

    options.update(extra_opts)
    config.set(**options)
    driver = TranslationDriver(config=config, exe_name=exe_name)
    driver.setup(function, annotation)
    driver.annotate()
    if conftest.option.view:
        driver.translator.view()
    driver.rtype()
    if conftest.option.view:
        driver.translator.view()
    driver.compile() 
    if conftest.option.view:
        driver.translator.view()
    return driver
Beispiel #12
0
def rpython2javascript(mod, function_names, jsconfig=None, use_pdb=True):
    if isinstance(function_names, str):
        function_names = [function_names]
        # avoid confusion
    if mod is None:
        # this means actual module, which is quite hairy to get in python,
        # so we cheat
        import sys
        mod = sys.modules[sys._getframe(1).f_globals['__name__']]
    
    if jsconfig is None:
        jsconfig = Config(js_optiondescr)
    if use_pdb:
        jsconfig.use_pdb = True
    module_name = mod.__name__
    if not function_names and 'main' in mod.__dict__:
        function_names.append('main')
    for func_name in function_names:
        if func_name not in mod.__dict__:
            raise FunctionNotFound("function %r was not found in module %r" % (func_name, module_name))
        func_code = mod.__dict__[func_name]
        if func_code.func_defaults:
            lgt = len(func_code.func_defaults)
        else:
            lgt = 0
        if func_code.func_code.co_argcount > 0 and func_code.func_code. \
                co_argcount != lgt:
            raise BadSignature("Function %s does not have default arguments" % func_name)
    source_ssf = get_source_ssf(mod, module_name, function_names)
    exec(source_ssf) in globals()
    # now we gonna just cut off not needed function
    # XXX: Really do that
    #options = optparse.Values(defaults=DEFAULT_OPTIONS)
    from pypy.config.pypyoption import get_pypy_config
    config = get_pypy_config(translating=True)
    driver = TranslationDriver(config=config)
    try:
        driver.setup(some_strange_function_which_will_never_be_called, [], policy = JsPolicy())
        driver.proceed(["compile_js"])
        if jsconfig.view:
            driver.translator.view()
        return driver.gen.tmpfile.open().read()
        # XXX: Add some possibility to write down selected file
    except Exception, e:
        # do something nice with it
        debug(driver, use_pdb)
Beispiel #13
0
            for key in ['__name__', '__doc__', 'RPythonError']:
                w_key = space.wrap(key)
                try:
                    w1 = space.getitem(w_old, w_key)
                except OperationError:
                    pass
                else:
                    space.setitem(w_moddict, w_key, w1)
            space.call_method(w_moddict, 'update', w_moduledict)

        except OperationError, e:
            reraise(e)

    __init__.allow_someobjects = True

    driver = TranslationDriver(extmod_name=modname)
    driver.setup(__init__, [object], policy=CPyAnnotatorPolicy(space))
    try:
        driver.proceed(['compile_c'])
    except SystemExit:
        raise
    except:
        if not interactive:
            raise
        debug(driver)
        raise SystemExit(1)
    return driver.cbuilder.c_ext_module

def main(argv):
    usage = """usage: %prog [options] MODULENAME
Beispiel #14
0
def _build(config, exe_name):
    driver = TranslationDriver.from_targetspec(targetpypystandalone.__dict__,
                                               config=config)
    driver.exe_name = exe_name
    driver.compile()
Beispiel #15
0
def _build(config, exe_name):
    driver = TranslationDriver.from_targetspec(
        targetpypystandalone.__dict__,
        config=config)
    driver.exe_name = exe_name
    driver.compile()
Beispiel #16
0
 def __init__(self, name, functions=[], policy=None, config=None):
     self.name = name
     self.functions = functions # [(function, annotation), ...]
     self.driver = TranslationDriver(config=config)
     self.driver.setup_library(self, policy=policy)
Beispiel #17
0
 def __init__(self, name, functions=[], policy=None, config=None):
     self.name = name
     self.functions = functions  # [(function, annotation), ...]
     self.driver = TranslationDriver(config=config)
     self.driver.setup_library(self, policy=policy)
Beispiel #18
0
def test_ctr():
    td = TranslationDriver()
    expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source',
                'compile', 'run', 'prehannotatebackendopt', 'hintannotate',
                'timeshift']
    assert cmpl(td.exposed, expected)

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    assert td.backend_select_goals(['compile']) == ['compile_c']
    assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    td = TranslationDriver({'backend': None, 'type_system': None})

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    py.test.raises(Exception, td.backend_select_goals, ['compile'])
    py.test.raises(Exception, td.backend_select_goals, ['rtype'])
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    py.test.raises(Exception, td.backend_select_goals, ['backendopt'])
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    expected = ['annotate', 'backendopt_lltype',
                 'backendopt_ootype',
                 'llinterpret_lltype',
                 'rtype_ootype', 'rtype_lltype', 'source_cl', 'source_js',
                 'source_squeak', 'source_cli', 'source_c', 'source_llvm',
                 'compile_cl', 'compile_cli', 'compile_c', 'compile_squeak',
                 'compile_llvm', 'compile_js', 'run_cl', 'run_squeak',
                 'run_llvm', 'run_c', 'run_js', 'run_cli',
                 'compile_jvm', 'source_jvm', 'run_jvm',
                 'prehannotatebackendopt_lltype', 'hintannotate_lltype',
                 'timeshift_lltype']
    assert cmpl(td.exposed, expected)                             

    td = TranslationDriver({'backend': None, 'type_system': 'lltype'})

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    py.test.raises(Exception, td.backend_select_goals, ['compile'])
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
    assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source_c',
                'source_llvm', 'compile_c', 'compile_llvm', 'run_llvm',
                'run_c', 'prehannotatebackendopt', 'hintannotate', 'timeshift']

    assert cmpl(td.exposed, expected)
def test_ctr():
    td = TranslationDriver()
    expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source',
                'compile', 'run', 'prejitbackendopt', 'pyjitpl']
    assert set(td.exposed) == set(expected)

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    assert td.backend_select_goals(['compile']) == ['compile_c']
    assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    td = TranslationDriver({'backend': None, 'type_system': None})

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    py.test.raises(Exception, td.backend_select_goals, ['compile'])
    py.test.raises(Exception, td.backend_select_goals, ['rtype'])
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    py.test.raises(Exception, td.backend_select_goals, ['backendopt'])
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    expected = ['annotate', 'backendopt_lltype',
                 'backendopt_ootype',
                 'llinterpret_lltype',
                 'rtype_ootype', 'rtype_lltype',
                 'source_cli', 'source_c',
                 'compile_cli', 'compile_c',
                 'run_c', 'run_cli',
                 'compile_jvm', 'source_jvm', 'run_jvm',
                 'prejitbackendopt_lltype', 'pyjitpl_lltype']
    assert set(td.exposed) == set(expected)                             

    td = TranslationDriver({'backend': None, 'type_system': 'lltype'})

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    py.test.raises(Exception, td.backend_select_goals, ['compile'])
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
    assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source_c',
                'compile_c', 'run_c', 'prejitbackendopt', 'pyjitpl']

    assert set(td.exposed) == set(expected)
Beispiel #20
0
def test_ctr():
    td = TranslationDriver()
    expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source',
                'compile', 'run', 'pyjitpl']
    assert set(td.exposed) == set(expected)

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    assert td.backend_select_goals(['compile']) == ['compile_c']
    assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    td = TranslationDriver({'backend': None, 'type_system': None})

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    py.test.raises(Exception, td.backend_select_goals, ['compile'])
    py.test.raises(Exception, td.backend_select_goals, ['rtype'])
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    py.test.raises(Exception, td.backend_select_goals, ['backendopt'])
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    expected = ['annotate', 'backendopt_lltype',
                 'backendopt_ootype',
                 'llinterpret_lltype',
                 'rtype_ootype', 'rtype_lltype',
                 'source_cli', 'source_c',
                 'compile_cli', 'compile_c',
                 'run_c', 'run_cli',
                 'compile_jvm', 'source_jvm', 'run_jvm',
                 'pyjitpl_lltype',
                 'pyjitpl_ootype']
    assert set(td.exposed) == set(expected)                             

    td = TranslationDriver({'backend': None, 'type_system': 'lltype'})

    assert td.backend_select_goals(['compile_c']) == ['compile_c']
    py.test.raises(Exception, td.backend_select_goals, ['compile'])
    assert td.backend_select_goals(['rtype_lltype']) == ['rtype_lltype']
    assert td.backend_select_goals(['rtype']) == ['rtype_lltype']
    assert td.backend_select_goals(['backendopt']) == ['backendopt_lltype']
    assert td.backend_select_goals(['backendopt_lltype']) == [
        'backendopt_lltype']

    expected = ['annotate', 'backendopt', 'llinterpret', 'rtype', 'source_c',
                'compile_c', 'run_c', 'pyjitpl']

    assert set(td.exposed) == set(expected)
Beispiel #21
0
def test_ctr():
    td = TranslationDriver()
    expected = [
        "annotate",
        "backendopt",
        "llinterpret",
        "rtype",
        "source",
        "compile",
        "run",
        "prehannotatebackendopt",
        "hintannotate",
        "timeshift",
    ]
    assert set(td.exposed) == set(expected)

    assert td.backend_select_goals(["compile_c"]) == ["compile_c"]
    assert td.backend_select_goals(["compile"]) == ["compile_c"]
    assert td.backend_select_goals(["rtype"]) == ["rtype_lltype"]
    assert td.backend_select_goals(["rtype_lltype"]) == ["rtype_lltype"]
    assert td.backend_select_goals(["backendopt"]) == ["backendopt_lltype"]
    assert td.backend_select_goals(["backendopt_lltype"]) == ["backendopt_lltype"]

    td = TranslationDriver({"backend": None, "type_system": None})

    assert td.backend_select_goals(["compile_c"]) == ["compile_c"]
    py.test.raises(Exception, td.backend_select_goals, ["compile"])
    py.test.raises(Exception, td.backend_select_goals, ["rtype"])
    assert td.backend_select_goals(["rtype_lltype"]) == ["rtype_lltype"]
    py.test.raises(Exception, td.backend_select_goals, ["backendopt"])
    assert td.backend_select_goals(["backendopt_lltype"]) == ["backendopt_lltype"]

    expected = [
        "annotate",
        "backendopt_lltype",
        "backendopt_ootype",
        "llinterpret_lltype",
        "rtype_ootype",
        "rtype_lltype",
        "source_js",
        "source_cli",
        "source_c",
        "source_llvm",
        "compile_cli",
        "compile_c",
        "compile_llvm",
        "compile_js",
        "run_llvm",
        "run_c",
        "run_js",
        "run_cli",
        "compile_jvm",
        "source_jvm",
        "run_jvm",
        "prehannotatebackendopt_lltype",
        "hintannotate_lltype",
        "timeshift_lltype",
    ]
    assert set(td.exposed) == set(expected)

    td = TranslationDriver({"backend": None, "type_system": "lltype"})

    assert td.backend_select_goals(["compile_c"]) == ["compile_c"]
    py.test.raises(Exception, td.backend_select_goals, ["compile"])
    assert td.backend_select_goals(["rtype_lltype"]) == ["rtype_lltype"]
    assert td.backend_select_goals(["rtype"]) == ["rtype_lltype"]
    assert td.backend_select_goals(["backendopt"]) == ["backendopt_lltype"]
    assert td.backend_select_goals(["backendopt_lltype"]) == ["backendopt_lltype"]

    expected = [
        "annotate",
        "backendopt",
        "llinterpret",
        "rtype",
        "source_c",
        "source_llvm",
        "compile_c",
        "compile_llvm",
        "run_llvm",
        "run_c",
        "prehannotatebackendopt",
        "hintannotate",
        "timeshift",
    ]

    assert set(td.exposed) == set(expected)