mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 00:17:01 +00:00
move archive-specific stuff out of bcreader into archive library.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34022 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -81,36 +81,6 @@ Module* ParseBytecodeBuffer(
|
|||||||
std::string *ErrMsg = 0 ///< Optional place to return an error message
|
std::string *ErrMsg = 0 ///< Optional place to return an error message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/// This function will read only the necessary parts of a bytecode file in order
|
|
||||||
/// to obtain a list of externally visible global symbols that the bytecode
|
|
||||||
/// module defines. This is used for archiving and linking when only the list
|
|
||||||
/// of symbols the module defines is needed.
|
|
||||||
/// @returns true on error, false otherwise
|
|
||||||
/// @brief Get a bytecode file's externally visibile defined global symbols.
|
|
||||||
bool GetBytecodeSymbols(
|
|
||||||
const sys::Path& fileName, ///< Filename to read bytecode from
|
|
||||||
std::vector<std::string>& syms, ///< Vector to return symbols in
|
|
||||||
BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
|
|
||||||
std::string* ErrMsg = 0 ///< Optional error message holder
|
|
||||||
);
|
|
||||||
|
|
||||||
/// This function will read only the necessary parts of a bytecode buffer in
|
|
||||||
/// order to obtain a list of externally visible global symbols that the
|
|
||||||
/// bytecode module defines. This is used for archiving and linking when only
|
|
||||||
/// the list of symbols the module defines is needed and the bytecode is
|
|
||||||
/// already in memory.
|
|
||||||
/// @returns the ModuleProvider on success, 0 if the bytecode can't be parsed
|
|
||||||
/// @brief Get a bytecode file's externally visibile defined global symbols.
|
|
||||||
ModuleProvider* GetBytecodeSymbols(
|
|
||||||
const unsigned char*Buffer, ///< The buffer to be parsed
|
|
||||||
unsigned Length, ///< The length of \p Buffer
|
|
||||||
const std::string& ModuleID, ///< An identifier for the module
|
|
||||||
std::vector<std::string>& symbols, ///< The symbols defined in the module
|
|
||||||
BCDecompressor_t *BCDC = Compressor::decompressToNewBuffer,
|
|
||||||
std::string* ErrMsg = 0 ///< Optional error message holder
|
|
||||||
);
|
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,8 +14,9 @@
|
|||||||
|
|
||||||
#include "ArchiveInternals.h"
|
#include "ArchiveInternals.h"
|
||||||
#include "llvm/ModuleProvider.h"
|
#include "llvm/ModuleProvider.h"
|
||||||
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/System/Process.h"
|
#include "llvm/System/Process.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// getMemberSize - compute the actual physical size of the file member as seen
|
// getMemberSize - compute the actual physical size of the file member as seen
|
||||||
@@ -190,3 +191,70 @@ Archive::~Archive() {
|
|||||||
cleanUpMemory();
|
cleanUpMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void getSymbols(Module*M, std::vector<std::string>& symbols) {
|
||||||
|
// Loop over global variables
|
||||||
|
for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
|
||||||
|
if (!GI->isDeclaration() && !GI->hasInternalLinkage())
|
||||||
|
if (!GI->getName().empty())
|
||||||
|
symbols.push_back(GI->getName());
|
||||||
|
|
||||||
|
// Loop over functions.
|
||||||
|
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
|
||||||
|
if (!FI->isDeclaration() && !FI->hasInternalLinkage())
|
||||||
|
if (!FI->getName().empty())
|
||||||
|
symbols.push_back(FI->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get just the externally visible defined symbols from the bytecode
|
||||||
|
bool llvm::GetBytecodeSymbols(const sys::Path& fName,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC,
|
||||||
|
std::string* ErrMsg) {
|
||||||
|
ModuleProvider *MP = getBytecodeModuleProvider(fName.toString(), BCDC,ErrMsg);
|
||||||
|
if (!MP)
|
||||||
|
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;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModuleProvider*
|
||||||
|
llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
|
||||||
|
const std::string& ModuleID,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC,
|
||||||
|
std::string* ErrMsg) {
|
||||||
|
// Get the module provider
|
||||||
|
ModuleProvider* MP =
|
||||||
|
getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, BCDC, ErrMsg, 0);
|
||||||
|
if (!MP)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,9 +65,18 @@ namespace llvm {
|
|||||||
bool checkSignature() {
|
bool checkSignature() {
|
||||||
return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
|
return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get just the externally visible defined symbols from the bytecode
|
||||||
|
bool GetBytecodeSymbols(const sys::Path& fName,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC, std::string* ErrMsg);
|
||||||
|
|
||||||
|
ModuleProvider* GetBytecodeSymbols(const unsigned char*Buffer,unsigned Length,
|
||||||
|
const std::string& ModuleID,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC,
|
||||||
|
std::string* ErrMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,8 +14,9 @@
|
|||||||
|
|
||||||
#include "ArchiveInternals.h"
|
#include "ArchiveInternals.h"
|
||||||
#include "llvm/ModuleProvider.h"
|
#include "llvm/ModuleProvider.h"
|
||||||
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/System/Process.h"
|
#include "llvm/System/Process.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// getMemberSize - compute the actual physical size of the file member as seen
|
// getMemberSize - compute the actual physical size of the file member as seen
|
||||||
@@ -190,3 +191,70 @@ Archive::~Archive() {
|
|||||||
cleanUpMemory();
|
cleanUpMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void getSymbols(Module*M, std::vector<std::string>& symbols) {
|
||||||
|
// Loop over global variables
|
||||||
|
for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
|
||||||
|
if (!GI->isDeclaration() && !GI->hasInternalLinkage())
|
||||||
|
if (!GI->getName().empty())
|
||||||
|
symbols.push_back(GI->getName());
|
||||||
|
|
||||||
|
// Loop over functions.
|
||||||
|
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
|
||||||
|
if (!FI->isDeclaration() && !FI->hasInternalLinkage())
|
||||||
|
if (!FI->getName().empty())
|
||||||
|
symbols.push_back(FI->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get just the externally visible defined symbols from the bytecode
|
||||||
|
bool llvm::GetBytecodeSymbols(const sys::Path& fName,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC,
|
||||||
|
std::string* ErrMsg) {
|
||||||
|
ModuleProvider *MP = getBytecodeModuleProvider(fName.toString(), BCDC,ErrMsg);
|
||||||
|
if (!MP)
|
||||||
|
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;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModuleProvider*
|
||||||
|
llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
|
||||||
|
const std::string& ModuleID,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC,
|
||||||
|
std::string* ErrMsg) {
|
||||||
|
// Get the module provider
|
||||||
|
ModuleProvider* MP =
|
||||||
|
getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, BCDC, ErrMsg, 0);
|
||||||
|
if (!MP)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,9 +65,18 @@ namespace llvm {
|
|||||||
bool checkSignature() {
|
bool checkSignature() {
|
||||||
return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
|
return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get just the externally visible defined symbols from the bytecode
|
||||||
|
bool GetBytecodeSymbols(const sys::Path& fName,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC, std::string* ErrMsg);
|
||||||
|
|
||||||
|
ModuleProvider* GetBytecodeSymbols(const unsigned char*Buffer,unsigned Length,
|
||||||
|
const std::string& ModuleID,
|
||||||
|
std::vector<std::string>& symbols,
|
||||||
|
BCDecompressor_t *BCDC,
|
||||||
|
std::string* ErrMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -254,70 +254,3 @@ Module *llvm::ParseBytecodeFile(const std::string &Filename,
|
|||||||
delete MP;
|
delete MP;
|
||||||
return M;
|
return M;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void getSymbols(Module*M, std::vector<std::string>& symbols) {
|
|
||||||
// Loop over global variables
|
|
||||||
for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
|
|
||||||
if (!GI->isDeclaration() && !GI->hasInternalLinkage())
|
|
||||||
if (!GI->getName().empty())
|
|
||||||
symbols.push_back(GI->getName());
|
|
||||||
|
|
||||||
// Loop over functions.
|
|
||||||
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
|
|
||||||
if (!FI->isDeclaration() && !FI->hasInternalLinkage())
|
|
||||||
if (!FI->getName().empty())
|
|
||||||
symbols.push_back(FI->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get just the externally visible defined symbols from the bytecode
|
|
||||||
bool llvm::GetBytecodeSymbols(const sys::Path& fName,
|
|
||||||
std::vector<std::string>& symbols,
|
|
||||||
BCDecompressor_t *BCDC,
|
|
||||||
std::string* ErrMsg) {
|
|
||||||
ModuleProvider *MP = getBytecodeModuleProvider(fName.toString(), BCDC,ErrMsg);
|
|
||||||
if (!MP)
|
|
||||||
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;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ModuleProvider*
|
|
||||||
llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
|
|
||||||
const std::string& ModuleID,
|
|
||||||
std::vector<std::string>& symbols,
|
|
||||||
BCDecompressor_t *BCDC,
|
|
||||||
std::string* ErrMsg) {
|
|
||||||
// Get the module provider
|
|
||||||
ModuleProvider* MP =
|
|
||||||
getBytecodeBufferModuleProvider(Buffer, Length, ModuleID, BCDC, ErrMsg, 0);
|
|
||||||
if (!MP)
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user