def parse_assembly(llvmir, context=None): """ Create Module from a LLVM IR string """ if context is None: context = get_global_context() llvmir = _encode_string(llvmir) strbuf = c_char_p(llvmir) with ffi.OutputString() as errmsg: mod = ModuleRef(ffi.lib.LLVMPY_ParseAssembly(context, strbuf, errmsg), context) if errmsg: mod.close() raise RuntimeError("LLVM IR parsing error\n{0}".format(errmsg)) return mod
def parse_bitcode(bitcode, context=None): """ Create Module from a LLVM *bitcode* (a bytes object). """ if context is None: context = get_global_context() buf = c_char_p(bitcode) bufsize = len(bitcode) with ffi.OutputString() as errmsg: mod = ModuleRef(ffi.lib.LLVMPY_ParseBitcode( context, buf, bufsize, errmsg), context) if errmsg: mod.close() raise RuntimeError( "LLVM bitcode parsing error\n{0}".format(errmsg)) return mod