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 result = lib.LLVMParseBitcode2(mem_buffer, byref(module)) 20 if result: 21 raise RuntimeError('LLVM Error') 22 m = Module(module) 23 m.take_ownership(mem_buffer) 24 return m 25 26def register_library(library): 27 library.LLVMParseBitcode2.argtypes = [MemoryBuffer, POINTER(c_object_p)] 28 library.LLVMParseBitcode2.restype = bool 29 30register_library(lib) 31