def make_contexts(): "Create LLVM contexts (_Ctx) for the .so and .s lib" so = libs.get_mathlib_so() so_linker = linking.ExternalLibraryLinker() ctx1 = new_ctx(lib=so, linker=so_linker) contexts = [ctx1] if have_llvm_asm(): asm = libs.get_llvm_mathlib() asm_linker = linking.LLVMLinker() ctx2 = new_ctx(lib=asm, linker=asm_linker) contexts.append(ctx2) return contexts
config = build.mkconfig(build.default_config, targets=[build.build_llvm], output_dir=tempdir) build.build_targets(config=config) assert exists(asmfile) get_llvm_lib(asmfile) finally: shutil.rmtree(tempdir) print(test_build_llvm, vars(test_build_llvm)) # # ______________________________________________________________________ @skip_if(not have_llvm_asm()) def get_llvm_lib(asmfile=None): "Test getting the llvm lib from a clean environment" lctx = make_llvm_context() kwds = {'asmfile': asmfile} if asmfile else {} lmod = build.load_llvm_asm(**kwds) mod = types.ModuleType('llvmmod') llvm_support.wrap_llvm_module(lmod, lctx.engine, mod) result = mod.npy_sin(ctypes.c_double(10.0)) expect = math.sin(10.0) assert result == expect, (result, expect) test_get_llvm_lib = test(get_llvm_lib)
try: asmfile = join(tempdir, 'mathcode.s') config = build.mkconfig(build.default_config, targets=[build.build_llvm], output_dir=tempdir) build.build_targets(config=config) assert exists(asmfile) get_llvm_lib(asmfile) finally: shutil.rmtree(tempdir) print(test_build_llvm, vars(test_build_llvm)) # # ______________________________________________________________________ @skip_if(not have_llvm_asm()) def get_llvm_lib(asmfile=None): "Test getting the llvm lib from a clean environment" lctx = make_llvm_context() kwds = { 'asmfile': asmfile } if asmfile else {} lmod = build.load_llvm_asm(**kwds) mod = types.ModuleType('llvmmod') llvm_support.wrap_llvm_module(lmod, lctx.engine, mod) result = mod.npy_sin(ctypes.c_double(10.0)) expect = math.sin(10.0) assert result == expect, (result, expect) test_get_llvm_lib = test(get_llvm_lib) # ______________________________________________________________________