1 //===-- BitReader.cpp -----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm-c/BitReader.h"
11 #include "llvm/Bitcode/ReaderWriter.h"
12 #include "llvm/IR/LLVMContext.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/MemoryBuffer.h"
20 /* Builds a module from the bitcode in the specified memory buffer, returning a
21 reference to the module via the OutModule parameter. Returns 0 on success.
22 Optionally returns a human-readable error message via OutMessage. */
23 LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
24 LLVMModuleRef *OutModule, char **OutMessage) {
25 return LLVMParseBitcodeInContext(wrap(&getGlobalContext()), MemBuf, OutModule,
29 LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
30 LLVMMemoryBufferRef MemBuf,
31 LLVMModuleRef *OutModule,
35 *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), *unwrap(ContextRef),
39 *OutMessage = strdup(Message.c_str());
46 /* Reads a module from the specified path, returning via the OutModule parameter
47 a module provider which performs lazy deserialization. Returns 0 on success.
48 Optionally returns a human-readable error message via OutMessage. */
49 LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
50 LLVMMemoryBufferRef MemBuf,
55 *OutM = wrap(getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef),
59 *OutMessage = strdup(Message.c_str());
67 LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
69 return LLVMGetBitcodeModuleInContext(LLVMGetGlobalContext(), MemBuf, OutM,
73 /* Deprecated: Use LLVMGetBitcodeModuleInContext instead. */
74 LLVMBool LLVMGetBitcodeModuleProviderInContext(LLVMContextRef ContextRef,
75 LLVMMemoryBufferRef MemBuf,
76 LLVMModuleProviderRef *OutMP,
78 return LLVMGetBitcodeModuleInContext(ContextRef, MemBuf,
79 reinterpret_cast<LLVMModuleRef*>(OutMP),
83 /* Deprecated: Use LLVMGetBitcodeModule instead. */
84 LLVMBool LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
85 LLVMModuleProviderRef *OutMP,
87 return LLVMGetBitcodeModuleProviderInContext(LLVMGetGlobalContext(), MemBuf,