1 2from .common import LLVMObject 3from .common import c_object_p 4from .common import get_library 5from . import enumerations 6from .core import MemoryBuffer 7from .core import Module 8from .core import OpCode 9from ctypes import POINTER 10from ctypes import byref 11from ctypes import c_char_p 12from ctypes import cast 13__all__ = ['parse_bitcode'] 14lib = get_library() 15 16def parse_bitcode(mem_buffer): 17 """Input is .core.MemoryBuffer""" 18 module = c_object_p() 19 out = c_char_p(None) 20 result = lib.LLVMParseBitcode(mem_buffer, byref(module), byref(out)) 21 if result: 22 raise RuntimeError('LLVM Error: %s' % out.value) 23 m = Module(module) 24 m.take_ownership(mem_buffer) 25 return m 26 27def register_library(library): 28 library.LLVMParseBitcode.argtypes = [MemoryBuffer, POINTER(c_object_p), POINTER(c_char_p)] 29 library.LLVMParseBitcode.restype = bool 30 31register_library(lib) 32