From 62de4e7b460f8ffbe0ee71a5a09503790102943f Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Wed, 27 Jan 2010 20:34:15 +0000 Subject: Kill ModuleProvider and ghost linkage by inverting the relationship between Modules and ModuleProviders. Because the "ModuleProvider" simply materializes GlobalValues now, and doesn't provide modules, it's renamed to "GVMaterializer". Code that used to need a ModuleProvider to materialize Functions can now materialize the Functions directly. Functions no longer use a magic linkage to record that they're materializable; they simply ask the GVMaterializer. Because the C ABI must never change, we can't remove LLVMModuleProviderRef or the functions that refer to it. Instead, because Module now exposes the same functionality ModuleProvider used to, we store a Module* in any LLVMModuleProviderRef and translate in the wrapper methods. The bindings to other languages still use the ModuleProvider concept. It would probably be worth some time to update them to follow the C++ more closely, but I don't intend to do it. Fixes http://llvm.org/PR5737 and http://llvm.org/PR5735. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94686 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/IRReader.h | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'include/llvm/Support') diff --git a/include/llvm/Support/IRReader.h b/include/llvm/Support/IRReader.h index e7780b0..50de738 100644 --- a/include/llvm/Support/IRReader.h +++ b/include/llvm/Support/IRReader.h @@ -23,44 +23,39 @@ #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/ModuleProvider.h" namespace llvm { - /// If the given MemoryBuffer holds a bitcode image, return a ModuleProvider - /// for it which does lazy deserialization of function bodies. Otherwise, - /// attempt to parse it as LLVM Assembly and return a fully populated - /// ModuleProvider. This function *always* takes ownership of the given - /// MemoryBuffer. - inline ModuleProvider *getIRModuleProvider(MemoryBuffer *Buffer, - SMDiagnostic &Err, - LLVMContext &Context) { + /// If the given MemoryBuffer holds a bitcode image, return a Module for it + /// which does lazy deserialization of function bodies. Otherwise, attempt to + /// parse it as LLVM Assembly and return a fully populated Module. This + /// function *always* takes ownership of the given MemoryBuffer. + inline Module *getIRModule(MemoryBuffer *Buffer, + SMDiagnostic &Err, + LLVMContext &Context) { if (isBitcode((const unsigned char *)Buffer->getBufferStart(), (const unsigned char *)Buffer->getBufferEnd())) { std::string ErrMsg; - ModuleProvider *MP = getBitcodeModuleProvider(Buffer, Context, &ErrMsg); - if (MP == 0) { + Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg); + if (M == 0) { Err = SMDiagnostic(Buffer->getBufferIdentifier(), -1, -1, ErrMsg, ""); // ParseBitcodeFile does not take ownership of the Buffer in the // case of an error. delete Buffer; } - return MP; + return M; } - Module *M = ParseAssembly(Buffer, 0, Err, Context); - if (M == 0) - return 0; - return new ExistingModuleProvider(M); + return ParseAssembly(Buffer, 0, Err, Context); } - /// If the given file holds a bitcode image, return a ModuleProvider + /// If the given file holds a bitcode image, return a Module /// for it which does lazy deserialization of function bodies. Otherwise, /// attempt to parse it as LLVM Assembly and return a fully populated - /// ModuleProvider. - inline ModuleProvider *getIRFileModuleProvider(const std::string &Filename, - SMDiagnostic &Err, - LLVMContext &Context) { + /// Module. + inline Module *getIRFileModule(const std::string &Filename, + SMDiagnostic &Err, + LLVMContext &Context) { std::string ErrMsg; MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), &ErrMsg); if (F == 0) { @@ -69,7 +64,7 @@ namespace llvm { return 0; } - return getIRModuleProvider(F, Err, Context); + return getIRModule(F, Err, Context); } /// If the given MemoryBuffer holds a bitcode image, return a Module -- cgit v1.1