LLVM API Documentation
00001 //===-- BitReader.cpp -----------------------------------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "llvm-c/BitReader.h" 00011 #include "llvm/Bitcode/ReaderWriter.h" 00012 #include "llvm/Support/MemoryBuffer.h" 00013 #include <string> 00014 #include <cstring> 00015 00016 using namespace llvm; 00017 00018 /* Builds a module from the bitcode in the specified memory buffer, returning a 00019 reference to the module via the OutModule parameter. Returns 0 on success. 00020 Optionally returns a human-readable error message via OutMessage. */ 00021 int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, 00022 LLVMModuleRef *OutModule, char **OutMessage) { 00023 std::string Message; 00024 00025 *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), &Message)); 00026 if (!*OutModule) { 00027 if (OutMessage) 00028 *OutMessage = strdup(Message.c_str()); 00029 return 1; 00030 } 00031 00032 return 0; 00033 } 00034 00035 /* Reads a module from the specified path, returning via the OutModule parameter 00036 a module provider which performs lazy deserialization. Returns 0 on success. 00037 Optionally returns a human-readable error message via OutMessage. */ 00038 int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf, 00039 LLVMModuleProviderRef *OutMP, 00040 char **OutMessage) { 00041 std::string Message; 00042 00043 *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), &Message)); 00044 if (!*OutMP) { 00045 if (OutMessage) 00046 *OutMessage = strdup(Message.c_str()); 00047 return 1; 00048 } 00049 00050 return 0; 00051 }