diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-01 16:58:40 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-01 16:58:40 +0000 |
commit | 8b477ed579794ba6d76915d56b3f448a7dd20120 (patch) | |
tree | 70d3be97f6ecf1ab7962e6cfafd113f2f7ce2579 /lib/Bitcode | |
parent | 4fb75e542539153acaf31d9221845a7d0feccbf6 (diff) | |
download | external_llvm-8b477ed579794ba6d76915d56b3f448a7dd20120.zip external_llvm-8b477ed579794ba6d76915d56b3f448a7dd20120.tar.gz external_llvm-8b477ed579794ba6d76915d56b3f448a7dd20120.tar.bz2 |
Add a pointer to the owning LLVMContext to Module. This requires threading LLVMContext through a lot
of the bitcode reader and ASM parser APIs, as well as supporting it in all of the tools.
Patches for Clang and LLVM-GCC to follow.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74614 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/Reader/BitReader.cpp | 9 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 11 | ||||
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.h | 6 |
3 files changed, 17 insertions, 9 deletions
diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp index 52851cd..2baf71b 100644 --- a/lib/Bitcode/Reader/BitReader.cpp +++ b/lib/Bitcode/Reader/BitReader.cpp @@ -18,11 +18,12 @@ using namespace llvm; /* Builds a module from the bitcode in the specified memory buffer, returning a reference to the module via the OutModule parameter. Returns 0 on success. Optionally returns a human-readable error message via OutMessage. */ -int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, +int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMContextRef ContextRef, LLVMModuleRef *OutModule, char **OutMessage) { std::string Message; - *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), &Message)); + *OutModule = wrap(ParseBitcodeFile(unwrap(MemBuf), unwrap(ContextRef), + &Message)); if (!*OutModule) { if (OutMessage) *OutMessage = strdup(Message.c_str()); @@ -36,11 +37,13 @@ int LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, a module provider which performs lazy deserialization. Returns 0 on success. Optionally returns a human-readable error message via OutMessage. */ int LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf, + LLVMContextRef ContextRef, LLVMModuleProviderRef *OutMP, char **OutMessage) { std::string Message; - *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), &Message)); + *OutMP = wrap(getBitcodeModuleProvider(unwrap(MemBuf), unwrap(ContextRef), + &Message)); if (!*OutMP) { if (OutMessage) *OutMessage = strdup(Message.c_str()); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 6b9606c..7cf0324 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1087,7 +1087,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) { return Error("Malformed block record"); // Otherwise, create the module. - TheModule = new Module(ModuleID); + TheModule = new Module(ModuleID, Context); SmallVector<uint64_t, 64> Record; std::vector<std::string> SectionTable; @@ -2090,8 +2090,9 @@ Module *BitcodeReader::releaseModule(std::string *ErrInfo) { /// getBitcodeModuleProvider - lazy function-at-a-time loading from a file. /// ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer, + LLVMContext* Context, std::string *ErrMsg) { - BitcodeReader *R = new BitcodeReader(Buffer); + BitcodeReader *R = new BitcodeReader(Buffer, Context); if (R->ParseBitcode()) { if (ErrMsg) *ErrMsg = R->getErrorString(); @@ -2106,9 +2107,11 @@ ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer, /// ParseBitcodeFile - Read the specified bitcode file, returning the module. /// If an error occurs, return null and fill in *ErrMsg if non-null. -Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg){ +Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext* Context, + std::string *ErrMsg){ BitcodeReader *R; - R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, ErrMsg)); + R = static_cast<BitcodeReader*>(getBitcodeModuleProvider(Buffer, Context, + ErrMsg)); if (!R) return 0; // Read in the entire module. diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h index 0dc470b..498a34a 100644 --- a/lib/Bitcode/Reader/BitcodeReader.h +++ b/lib/Bitcode/Reader/BitcodeReader.h @@ -26,6 +26,7 @@ namespace llvm { class MemoryBuffer; + class LLVMContext; //===----------------------------------------------------------------------===// // BitcodeReaderValueList Class @@ -85,6 +86,7 @@ public: }; class BitcodeReader : public ModuleProvider { + LLVMContext* Context; MemoryBuffer *Buffer; BitstreamReader StreamFile; BitstreamCursor Stream; @@ -123,8 +125,8 @@ class BitcodeReader : public ModuleProvider { /// stream) and what linkage the original function had. DenseMap<Function*, std::pair<uint64_t, unsigned> > DeferredFunctionInfo; public: - explicit BitcodeReader(MemoryBuffer *buffer) - : Buffer(buffer), ErrorString(0) { + explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext* C) + : Context(C), Buffer(buffer), ErrorString(0) { HasReversedFunctionsWithBodies = false; } ~BitcodeReader() { |