137a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman 237a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom .common import LLVMObject 337a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom .common import c_object_p 437a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom .common import get_library 537a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom . import enumerations 637a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom .core import MemoryBuffer 737a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom .core import Module 837a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom .core import OpCode 937a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom ctypes import POINTER 1037a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom ctypes import byref 1137a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom ctypes import c_char_p 1237a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanfrom ctypes import cast 1337a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman__all__ = ['parse_bitcode'] 1437a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanlib = get_library() 1537a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman 1637a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmandef parse_bitcode(mem_buffer): 1737a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman """Input is .core.MemoryBuffer""" 1837a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman module = c_object_p() 19f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar result = lib.LLVMParseBitcode2(mem_buffer, byref(module)) 2037a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman if result: 21f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar raise RuntimeError('LLVM Error') 2237a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman m = Module(module) 2337a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman m.take_ownership(mem_buffer) 2437a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman return m 2537a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman 2637a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmandef register_library(library): 27f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar library.LLVMParseBitcode2.argtypes = [MemoryBuffer, POINTER(c_object_p)] 28f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar library.LLVMParseBitcode2.restype = bool 2937a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesman 3037a8807323672ab0bb366272e5a798b8e63752a4Michael Gottesmanregister_library(lib) 31