diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2005-02-26 22:00:32 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2005-02-26 22:00:32 +0000 |
commit | eaa06bb9792f14628402da55caa554965f25e49c (patch) | |
tree | f5fb03b2b289584534b959462d7167b06a347321 | |
parent | 7ffc07dcf7a0afc5e70e799f26de75750a8008d5 (diff) | |
download | llvm-eaa06bb9792f14628402da55caa554965f25e49c.tar.gz llvm-eaa06bb9792f14628402da55caa554965f25e49c.tar.bz2 llvm-eaa06bb9792f14628402da55caa554965f25e49c.tar.xz |
Implement an isBytecodeArchive method to determine if an archive contains
bytecode file members or not.
Patch Contributed By Adam Treat
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20338 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Bytecode/Archive.h | 9 | ||||
-rw-r--r-- | lib/Archive/ArchiveReader.cpp | 29 | ||||
-rw-r--r-- | lib/Bytecode/Archive/ArchiveReader.cpp | 29 |
3 files changed, 67 insertions, 0 deletions
diff --git a/include/llvm/Bytecode/Archive.h b/include/llvm/Bytecode/Archive.h index 102bb5c507..3805d0b249 100644 --- a/include/llvm/Bytecode/Archive.h +++ b/include/llvm/Bytecode/Archive.h @@ -414,6 +414,15 @@ class Archive { std::set<std::string>& symbols, ///< Symbols to be sought std::set<ModuleProvider*>& modules ///< The modules matching \p symbols ); + + /// This method determines whether the archive is a properly formed llvm + /// bytecode archive. It first makes sure the symbol table has been loaded + /// and has a non-zero size. If it does, then it is an archive. If not, + /// then it tries to load all the bytecode modules of the archive. Finally, + /// it returns whether it was successfull. + /// @returns true if the archive is a proper llvm bytecode archive + /// @brief Determine whether the archive is a proper llvm bytecode archive. + bool isBytecodeArchive(); /// @} /// @name Mutators diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp index 56b42ffdb2..7eab19d11d 100644 --- a/lib/Archive/ArchiveReader.cpp +++ b/lib/Archive/ArchiveReader.cpp @@ -503,3 +503,32 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols, } } } + +bool +Archive::isBytecodeArchive() +{ + //Make sure the symTab has been loaded... + //in most cases this should have been done + //when the archive was constructed, but still, + //this is just in case. + if ( !symTab.size() ) + loadSymbolTable(); + + //Now that we know it's been loaded, return true + //if it has a size + if ( symTab.size() ) return true; + + //We still can't be sure it isn't a bytecode archive + loadArchive(); + + std::vector<Module *> Modules; + std::string ErrorMessage; + + //If getAllModules gives an error then this isn't a proper + //bytecode archive + if ( getAllModules( Modules, &ErrorMessage ) ) return false; + + //Finally, if we find any bytecode modules then this is a proper + //bytecode archive + return Modules.size(); +} diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp index 56b42ffdb2..7eab19d11d 100644 --- a/lib/Bytecode/Archive/ArchiveReader.cpp +++ b/lib/Bytecode/Archive/ArchiveReader.cpp @@ -503,3 +503,32 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols, } } } + +bool +Archive::isBytecodeArchive() +{ + //Make sure the symTab has been loaded... + //in most cases this should have been done + //when the archive was constructed, but still, + //this is just in case. + if ( !symTab.size() ) + loadSymbolTable(); + + //Now that we know it's been loaded, return true + //if it has a size + if ( symTab.size() ) return true; + + //We still can't be sure it isn't a bytecode archive + loadArchive(); + + std::vector<Module *> Modules; + std::string ErrorMessage; + + //If getAllModules gives an error then this isn't a proper + //bytecode archive + if ( getAllModules( Modules, &ErrorMessage ) ) return false; + + //Finally, if we find any bytecode modules then this is a proper + //bytecode archive + return Modules.size(); +} |