def test_demangle(self): def check(flags): mangled = flags.get_mangle_string() out = flags.demangle(mangled) # Demangle result MUST match summary() self.assertEqual(out, flags.summary()) # test empty flags flags = Flags() check(flags) # test default check(DEFAULT_FLAGS) # test other flags = Flags() flags.no_cpython_wrapper = True flags.nrt = True flags.fastmath = True check(flags)
def _cull_exports(self): """Read all the exported functions/modules in the translator environment, and join them into a single LLVM module. """ self.exported_function_types = {} self.function_environments = {} self.environment_gvs = {} codegen = self.context.codegen() library = codegen.create_library(self.module_name) # Generate IR for all exported functions flags = Flags() flags.no_compile = True if not self.export_python_wrap: flags.no_cpython_wrapper = True flags.no_cfunc_wrapper = True if self.use_nrt: flags.nrt = True # Compile NRT helpers nrt_module, _ = nrtdynmod.create_nrt_module(self.context) library.add_ir_module(nrt_module) for entry in self.export_entries: cres = compile_extra(self.typing_context, self.context, entry.function, entry.signature.args, entry.signature.return_type, flags, locals={}, library=library) func_name = cres.fndesc.llvm_func_name llvm_func = cres.library.get_function(func_name) if self.export_python_wrap: llvm_func.linkage = 'internal' wrappername = cres.fndesc.llvm_cpython_wrapper_name wrapper = cres.library.get_function(wrappername) wrapper.name = self._mangle_method_symbol(entry.symbol) wrapper.linkage = 'external' fnty = cres.target_context.call_conv.get_function_type( cres.fndesc.restype, cres.fndesc.argtypes) self.exported_function_types[entry] = fnty self.function_environments[entry] = cres.environment self.environment_gvs[entry] = cres.fndesc.env_name else: llvm_func.name = entry.symbol self.dll_exports.append(entry.symbol) if self.export_python_wrap: wrapper_module = library.create_ir_module("wrapper") self._emit_python_wrapper(wrapper_module) library.add_ir_module(wrapper_module) # Hide all functions in the DLL except those explicitly exported library.finalize() for fn in library.get_defined_functions(): if fn.name not in self.dll_exports: if fn.linkage in {Linkage.private, Linkage.internal}: # Private/Internal linkage must have "default" visibility fn.visibility = "default" else: fn.visibility = 'hidden' return library