mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
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
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "ArchiveInternals.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/ModuleProvider.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/System/Process.h"
|
||||
@@ -173,8 +172,8 @@ void Archive::cleanUpMemory() {
|
||||
foreignST = 0;
|
||||
}
|
||||
|
||||
// Delete any ModuleProviders and ArchiveMember's we've allocated as a result
|
||||
// of symbol table searches.
|
||||
// Delete any Modules and ArchiveMember's we've allocated as a result of
|
||||
// symbol table searches.
|
||||
for (ModuleMap::iterator I=modules.begin(), E=modules.end(); I != E; ++I ) {
|
||||
delete I->second.first;
|
||||
delete I->second.second;
|
||||
@@ -221,51 +220,37 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
|
||||
return true;
|
||||
}
|
||||
|
||||
ModuleProvider *MP = getBitcodeModuleProvider(Buffer.get(), Context, ErrMsg);
|
||||
if (!MP)
|
||||
Module *M = ParseBitcodeFile(Buffer.get(), Context, ErrMsg);
|
||||
if (!M)
|
||||
return true;
|
||||
|
||||
// Get the module from the provider
|
||||
Module* M = MP->materializeModule();
|
||||
if (M == 0) {
|
||||
delete MP;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the symbols
|
||||
getSymbols(M, symbols);
|
||||
|
||||
// Done with the module.
|
||||
delete MP;
|
||||
delete M;
|
||||
return true;
|
||||
}
|
||||
|
||||
ModuleProvider*
|
||||
Module*
|
||||
llvm::GetBitcodeSymbols(const unsigned char *BufPtr, unsigned Length,
|
||||
const std::string& ModuleID,
|
||||
LLVMContext& Context,
|
||||
std::vector<std::string>& symbols,
|
||||
std::string* ErrMsg) {
|
||||
// Get the module provider
|
||||
MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str());
|
||||
// Get the module.
|
||||
std::auto_ptr<MemoryBuffer> Buffer(
|
||||
MemoryBuffer::getNewMemBuffer(Length, ModuleID.c_str()));
|
||||
memcpy((char*)Buffer->getBufferStart(), BufPtr, Length);
|
||||
|
||||
ModuleProvider *MP = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
|
||||
if (!MP)
|
||||
Module *M = ParseBitcodeFile(Buffer.get(), Context, ErrMsg);
|
||||
if (!M)
|
||||
return 0;
|
||||
|
||||
// Get the module from the provider
|
||||
Module* M = MP->materializeModule();
|
||||
if (M == 0) {
|
||||
delete MP;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the symbols
|
||||
getSymbols(M, symbols);
|
||||
|
||||
// Done with the module. Note that ModuleProvider will delete the
|
||||
// Module when it is deleted. Also note that its the caller's responsibility
|
||||
// to delete the ModuleProvider.
|
||||
return MP;
|
||||
// Done with the module. Note that it's the caller's responsibility to delete
|
||||
// the Module.
|
||||
return M;
|
||||
}
|
||||
|
@@ -77,11 +77,11 @@ namespace llvm {
|
||||
std::vector<std::string>& symbols,
|
||||
std::string* ErrMsg);
|
||||
|
||||
ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
|
||||
const std::string& ModuleID,
|
||||
LLVMContext& Context,
|
||||
std::vector<std::string>& symbols,
|
||||
std::string* ErrMsg);
|
||||
Module* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
|
||||
const std::string& ModuleID,
|
||||
LLVMContext& Context,
|
||||
std::vector<std::string>& symbols,
|
||||
std::string* ErrMsg);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -452,9 +452,9 @@ Archive* Archive::OpenAndLoadSymbols(const sys::Path& file,
|
||||
return result.release();
|
||||
}
|
||||
|
||||
// Look up one symbol in the symbol table and return a ModuleProvider for the
|
||||
// module that defines that symbol.
|
||||
ModuleProvider*
|
||||
// Look up one symbol in the symbol table and return the module that defines
|
||||
// that symbol.
|
||||
Module*
|
||||
Archive::findModuleDefiningSymbol(const std::string& symbol,
|
||||
std::string* ErrMsg) {
|
||||
SymTabType::iterator SI = symTab.find(symbol);
|
||||
@@ -483,27 +483,27 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
|
||||
if (!mbr)
|
||||
return 0;
|
||||
|
||||
// Now, load the bitcode module to get the ModuleProvider
|
||||
// Now, load the bitcode module to get the Module.
|
||||
std::string FullMemberName = archPath.str() + "(" +
|
||||
mbr->getPath().str() + ")";
|
||||
MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
|
||||
FullMemberName.c_str());
|
||||
memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
|
||||
|
||||
ModuleProvider *mp = getBitcodeModuleProvider(Buffer, Context, ErrMsg);
|
||||
if (!mp)
|
||||
Module *m = getLazyBitcodeModule(Buffer, Context, ErrMsg);
|
||||
if (!m)
|
||||
return 0;
|
||||
|
||||
modules.insert(std::make_pair(fileOffset, std::make_pair(mp, mbr)));
|
||||
modules.insert(std::make_pair(fileOffset, std::make_pair(m, mbr)));
|
||||
|
||||
return mp;
|
||||
return m;
|
||||
}
|
||||
|
||||
// Look up multiple symbols in the symbol table and return a set of
|
||||
// ModuleProviders that define those symbols.
|
||||
// Modules that define those symbols.
|
||||
bool
|
||||
Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
|
||||
std::set<ModuleProvider*>& result,
|
||||
std::set<Module*>& result,
|
||||
std::string* error) {
|
||||
if (!mapfile || !base) {
|
||||
if (error)
|
||||
@@ -536,19 +536,19 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
|
||||
std::vector<std::string> symbols;
|
||||
std::string FullMemberName = archPath.str() + "(" +
|
||||
mbr->getPath().str() + ")";
|
||||
ModuleProvider* MP =
|
||||
Module* M =
|
||||
GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(),
|
||||
FullMemberName, Context, symbols, error);
|
||||
|
||||
if (MP) {
|
||||
if (M) {
|
||||
// Insert the module's symbols into the symbol table
|
||||
for (std::vector<std::string>::iterator I = symbols.begin(),
|
||||
E=symbols.end(); I != E; ++I ) {
|
||||
symTab.insert(std::make_pair(*I, offset));
|
||||
}
|
||||
// Insert the ModuleProvider and the ArchiveMember into the table of
|
||||
// Insert the Module and the ArchiveMember into the table of
|
||||
// modules.
|
||||
modules.insert(std::make_pair(offset, std::make_pair(MP, mbr)));
|
||||
modules.insert(std::make_pair(offset, std::make_pair(M, mbr)));
|
||||
} else {
|
||||
if (error)
|
||||
*error = "Can't parse bitcode member: " +
|
||||
@@ -571,11 +571,11 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
|
||||
for (std::set<std::string>::iterator I=symbols.begin(),
|
||||
E=symbols.end(); I != E;) {
|
||||
// See if this symbol exists
|
||||
ModuleProvider* mp = findModuleDefiningSymbol(*I,error);
|
||||
if (mp) {
|
||||
// The symbol exists, insert the ModuleProvider into our result,
|
||||
// duplicates wil be ignored
|
||||
result.insert(mp);
|
||||
Module* m = findModuleDefiningSymbol(*I,error);
|
||||
if (m) {
|
||||
// The symbol exists, insert the Module into our result, duplicates will
|
||||
// be ignored.
|
||||
result.insert(m);
|
||||
|
||||
// Remove the symbol now that its been resolved, being careful to
|
||||
// post-increment the iterator.
|
||||
|
@@ -12,12 +12,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ArchiveInternals.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/System/Signals.h"
|
||||
#include "llvm/System/Process.h"
|
||||
#include "llvm/ModuleProvider.h"
|
||||
#include "llvm/System/Signals.h"
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
#include <iomanip>
|
||||
@@ -225,12 +225,12 @@ Archive::writeMember(
|
||||
std::vector<std::string> symbols;
|
||||
std::string FullMemberName = archPath.str() + "(" + member.getPath().str()
|
||||
+ ")";
|
||||
ModuleProvider* MP =
|
||||
Module* M =
|
||||
GetBitcodeSymbols((const unsigned char*)data,fSize,
|
||||
FullMemberName, Context, symbols, ErrMsg);
|
||||
|
||||
// If the bitcode parsed successfully
|
||||
if ( MP ) {
|
||||
if ( M ) {
|
||||
for (std::vector<std::string>::iterator SI = symbols.begin(),
|
||||
SE = symbols.end(); SI != SE; ++SI) {
|
||||
|
||||
@@ -244,7 +244,7 @@ Archive::writeMember(
|
||||
}
|
||||
}
|
||||
// We don't need this module any more.
|
||||
delete MP;
|
||||
delete M;
|
||||
} else {
|
||||
delete mFile;
|
||||
if (ErrMsg)
|
||||
|
Reference in New Issue
Block a user