diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-11-14 22:00:48 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-11-14 22:00:48 +0000 |
commit | 0ce0d938b1ace7e3a84f07f923b43758062b5b4f (patch) | |
tree | ff5423a3ba4ac1db857db737431122f99e813d55 /llvm/lib/Bytecode | |
parent | f01fc688badab4c01f0c947887d4ddfa4dccfa81 (diff) | |
download | bcm5719-llvm-0ce0d938b1ace7e3a84f07f923b43758062b5b4f.tar.gz bcm5719-llvm-0ce0d938b1ace7e3a84f07f923b43758062b5b4f.zip |
Add wrappers to get defined symbols from bytecode
llvm-svn: 17770
Diffstat (limited to 'llvm/lib/Bytecode')
-rw-r--r-- | llvm/lib/Bytecode/Reader/ReaderWrappers.cpp | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp b/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp index b70c3ef4a33..de2fd030e8b 100644 --- a/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp +++ b/llvm/lib/Bytecode/Reader/ReaderWrappers.cpp @@ -346,6 +346,30 @@ bool llvm::GetBytecodeDependentLibraries(const std::string &fname, } } +namespace { +void getSymbols(Module*M, std::vector<std::string>& symbols) { + // Loop over global variables + for (Module::giterator GI = M->gbegin(), GE=M->gend(); GI != GE; ++GI) { + if (GI->hasInitializer()) { + std::string name ( GI->getName() ); + if (!name.empty()) { + symbols.push_back(name); + } + } + } + + //Loop over functions + for (Module::iterator FI = M->begin(), FE=M->end(); FI != FE; ++FI) { + if (!FI->isExternal()) { + std::string name ( FI->getName() ); + if (!name.empty()) { + symbols.push_back(name); + } + } + } +} +} + // Get just the externally visible defined symbols from the bytecode bool llvm::GetBytecodeSymbols(const sys::Path& fName, std::vector<std::string>& symbols) { @@ -355,25 +379,8 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName, // Get the module from the provider Module* M = AMP->releaseModule(); - // Loop over global variables - for (Module::giterator GI = M->gbegin(), GE=M->gend(); GI != GE; ++GI) { - if (GI->hasInitializer()) { - std::string name ( GI->getName() ); - if (!name.empty()) { - symbols.push_back(name); - } - } - } - - //Loop over functions - for (Module::iterator FI = M->begin(), FE=M->end(); FI != FE; ++FI) { - if (!FI->isExternal()) { - std::string name ( FI->getName() ); - if (!name.empty()) { - symbols.push_back(name); - } - } - } + // Get the symbols + getSymbols(M, symbols); // Done with the module delete M; @@ -384,4 +391,26 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName, } } +bool llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length, + const std::string& ModuleID, + std::vector<std::string>& symbols) { + + try { + std::auto_ptr<ModuleProvider> + AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID)); + + // Get the module from the provider + Module* M = AMP->releaseModule(); + + // Get the symbols + getSymbols(M, symbols); + + // Done with the module + delete M; + return true; + + } catch (...) { + return false; + } +} // vim: sw=2 ai |