diff options
author | Chris Lattner <sabre@nondot.org> | 2007-02-07 23:53:17 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-02-07 23:53:17 +0000 |
commit | ddfead20e8d2f68c7c736e6e1d4b6ae7ac39a3a6 (patch) | |
tree | 5b7d360fbca5970b456295e1de85f4afc03edfc3 /llvm/lib/Bytecode/Archive/Archive.cpp | |
parent | d220dc1426b8ac776ebe8ff44300660b47e24bdd (diff) | |
download | bcm5719-llvm-ddfead20e8d2f68c7c736e6e1d4b6ae7ac39a3a6.tar.gz bcm5719-llvm-ddfead20e8d2f68c7c736e6e1d4b6ae7ac39a3a6.zip |
move archive-specific stuff out of bcreader into archive library.
llvm-svn: 34022
Diffstat (limited to 'llvm/lib/Bytecode/Archive/Archive.cpp')
-rw-r--r-- | llvm/lib/Bytecode/Archive/Archive.cpp | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/llvm/lib/Bytecode/Archive/Archive.cpp b/llvm/lib/Bytecode/Archive/Archive.cpp index d299694383a..1c0b205e9e2 100644 --- a/llvm/lib/Bytecode/Archive/Archive.cpp +++ b/llvm/lib/Bytecode/Archive/Archive.cpp @@ -14,8 +14,9 @@ #include "ArchiveInternals.h" #include "llvm/ModuleProvider.h" +#include "llvm/Module.h" +#include "llvm/Bytecode/Reader.h" #include "llvm/System/Process.h" - using namespace llvm; // getMemberSize - compute the actual physical size of the file member as seen @@ -190,3 +191,70 @@ Archive::~Archive() { 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; +} |