Example #1
0
    def compile_methods(self):
        """
        Compile all methods, reuse function environments from type inference
        stage.

        ∀ methods M sets M.lfunc, M.lfunc_pointer and M.wrapper_func
        """
        for i, method in enumerate(self.methods):
            func_env = self.func_envs[method]
            pipeline.run_env(self.env, func_env, pipeline_name='compile')
            method.update_from_env(func_env)
Example #2
0
    def compile_methods(self):
        """
        Compile all methods, reuse function environments from type inference
        stage.

        ∀ methods M sets M.lfunc, M.lfunc_pointer and M.wrapper_func
        """
        for i, method in enumerate(self.methods):
            func_env = self.func_envs[method]
            pipeline.run_env(self.env, func_env, pipeline_name='compile')
            method.update_from_env(func_env)
Example #3
0
def print_(env, node):
    from numba import pipeline

    global printing

    if printing:
        return

    printing = True

    node = inject_print(env.context, env.crnt.llvm_module, node)
    func_env = env.crnt.inherit(ast=node)
    pipeline.run_env(env, func_env, pipeline_name='lower')
    env.crnt.translator.visit(func_env.ast)

    printing = False
Example #4
0
def print_(env, node):
    from numba import pipeline

    global printing

    if printing:
        return

    printing = True

    node = inject_print(env.context, env.crnt.llvm_module, node)
    func_env = env.crnt.inherit(ast=node)
    pipeline.run_env(env, func_env, pipeline_name='lower')
    env.crnt.translator.visit(func_env.ast)

    printing = False
Example #5
0
def build_wrapper_translation(env, llvm_module=None):
    """
    Generate a wrapper function in the given llvm module.
    """
    from numba import pipeline

    if llvm_module:
        wrapper_module = llvm_module
    else:
        wrapper_module = env.llvm_context.module

    # Create wrapper code generator and wrapper AST
    func_name = '__numba_wrapper_%s' % env.crnt.func_name
    signature = object_(void.pointer(), object_)
    symtab = dict(self=Variable(object_, is_local=True),
                  args=Variable(object_, is_local=True))

    func_env = env.crnt.inherit(
            func=fake_pyfunc,
            name=func_name,
            mangled_name=None, # Force FunctionEnvironment.init()
                               # to generate a new mangled name.
            func_signature=signature,
            locals={},
            symtab=symtab,
            refcount_args=False,
            llvm_module=wrapper_module)

    # Create wrapper LLVM function
    func_env.lfunc = pipeline.get_lfunc(env, func_env)

    # Build wrapper ast
    wrapper_node = build_wrapper_function_ast(env,
                                              wrapper_lfunc=func_env.lfunc,
                                              llvm_module=wrapper_module)
    func_env.ast = wrapper_node

    # Specialize and compile wrapper
    pipeline.run_env(env, func_env, pipeline_name='late_translate')
    keep_alive(fake_pyfunc, func_env.lfunc)

    return func_env.translator # TODO: Amend callers to eat func_env