Exemple #1
0
def _compile(expr, args):
    ir_gen = IRGenerator(expr, args, "mathics")
    llvm_ir, ret_type = ir_gen.generate_ir()
    mod = compile_ir(engine, llvm_ir)

    # lookup function pointer
    func_ptr = engine.get_function_address("mathics")

    # run function via ctypes
    cfunc = CFUNCTYPE(llvm_to_ctype(ret_type), *(llvm_to_ctype(arg.type) for arg in args))(func_ptr)
    return cfunc
Exemple #2
0
def _compile(expr, args):
    ir_gen = IRGenerator(expr, args, "mathics")
    llvm_ir, ret_type = ir_gen.generate_ir()
    mod = compile_ir(engine, llvm_ir)

    # lookup function pointer
    func_ptr = engine.get_function_address("mathics")

    # run function via ctypes
    cfunc = CFUNCTYPE(llvm_to_ctype(ret_type),
                      *(llvm_to_ctype(arg.type) for arg in args))(func_ptr)
    return cfunc
Exemple #3
0
    def add_caller(self, py_f, ret_type, args):
        '''
        Inserts a caller to a python function
        '''
        # see http://eli.thegreenplace.net/2015/calling-back-into-python-from-llvmlite-jited-code/

        c_func_type = ctypes.CFUNCTYPE(llvm_to_ctype(ret_type), *(llvm_to_ctype(arg.type) for arg in args))
        c_func = c_func_type(py_f)
        c_func_addr = ctypes.cast(c_func, ctypes.c_void_p).value

        addrcaller_func_type = ir.FunctionType(ret_type, [arg.type for arg in args])
        cb_func_ptr_type = addrcaller_func_type.as_pointer()

        f = self.builder.inttoptr(int_type(c_func_addr), cb_func_ptr_type, name='f')
        call = self.builder.call(f, args)
        if call.type == void_type:
            return self.builder.ret_void()
        return call
Exemple #4
0
    def add_caller(self, py_f, ret_type, args):
        '''
        Inserts a caller to a python function
        '''
        # see http://eli.thegreenplace.net/2015/calling-back-into-python-from-llvmlite-jited-code/

        c_func_type = ctypes.CFUNCTYPE(
            llvm_to_ctype(ret_type),
            *(llvm_to_ctype(arg.type) for arg in args))
        c_func = c_func_type(py_f)
        c_func_addr = ctypes.cast(c_func, ctypes.c_void_p).value

        addrcaller_func_type = ir.FunctionType(ret_type,
                                               [arg.type for arg in args])
        cb_func_ptr_type = addrcaller_func_type.as_pointer()

        f = self.builder.inttoptr(int_type(c_func_addr),
                                  cb_func_ptr_type,
                                  name='f')
        call = self.builder.call(f, args)
        if call.type == void_type:
            return self.builder.ret_void()
        return call