#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
-#include "llvm/System/Path.h"
+#include "llvm/Support/Path.h"
#include <map>
#include <set>
-#include <fstream>
namespace llvm {
class MemoryBuffer;
// Forward declare classes
-class ModuleProvider; // From VMCore
class Module; // From VMCore
class Archive; // Declared below
class ArchiveMemberHeader; // Internal implementation class
/// characteristics of the member. The various "is" methods below provide
/// access to the flags. The flags are not user settable.
enum Flags {
- CompressedFlag = 1, ///< Member is a normal compressed file
- SVR4SymbolTableFlag = 2, ///< Member is a SVR4 symbol table
- BSD4SymbolTableFlag = 4, ///< Member is a BSD4 symbol table
- LLVMSymbolTableFlag = 8, ///< Member is an LLVM symbol table
- BitcodeFlag = 16, ///< Member is bitcode
- HasPathFlag = 64, ///< Member has a full or partial path
- HasLongFilenameFlag = 128, ///< Member uses the long filename syntax
- StringTableFlag = 256 ///< Member is an ar(1) format string table
+ SVR4SymbolTableFlag = 1, ///< Member is a SVR4 symbol table
+ BSD4SymbolTableFlag = 2, ///< Member is a BSD4 symbol table
+ LLVMSymbolTableFlag = 4, ///< Member is an LLVM symbol table
+ BitcodeFlag = 8, ///< Member is bitcode
+ HasPathFlag = 16, ///< Member has a full or partial path
+ HasLongFilenameFlag = 32, ///< Member uses the long filename syntax
+ StringTableFlag = 64 ///< Member is an ar(1) format string table
};
/// @}
unsigned getGroup() const { return info.getGroup(); }
/// The "mode" specifies the access permissions for the file per Unix
- /// security. This may not have any applicabiity on non-Unix systems but is
+ /// security. This may not have any applicability on non-Unix systems but is
/// a required component of the "ar" file format.
/// @brief Get the permission mode associated with this archive member.
unsigned getMode() const { return info.getMode(); }
/// into memory, the return value will be null.
/// @returns a pointer to the member's data.
/// @brief Get the data content of the archive member
- const void* getData() const { return data; }
-
- /// This method determines if the member is a regular compressed file.
- /// @returns true iff the archive member is a compressed regular file.
- /// @brief Determine if the member is a compressed regular file.
- bool isCompressed() const { return flags&CompressedFlag; }
+ const char* getData() const { return data; }
/// @returns true iff the member is a SVR4 (non-LLVM) symbol table
/// @brief Determine if this member is a SVR4 symbol table.
/// allowed that doesn't have this restriction. This method determines if
/// that "long format" is used for this member.
/// @returns true iff the file name uses the long form
- /// @brief Determin if the member has a long file name
+ /// @brief Determine if the member has a long file name
bool hasLongFilename() const { return flags&HasLongFilenameFlag; }
/// This method returns the status info (like Unix stat(2)) for the archive
sys::PathWithStatus path; ///< Path of file containing the member
sys::FileStatus info; ///< Status info (size,mode,date)
unsigned flags; ///< Flags about the archive member
- const void* data; ///< Data for the member
+ const char* data; ///< Data for the member
/// @}
/// @name Constructors
/// @brief Create an empty Archive.
static Archive* CreateEmpty(
const sys::Path& Filename,///< Name of the archive to (eventually) create.
- LLVMContext* C ///< Context to use for global information
+ LLVMContext& C ///< Context to use for global information
);
/// Open an existing archive and load its contents in preparation for
/// @brief Open and load an archive file
static Archive* OpenAndLoad(
const sys::Path& filePath, ///< The file path to open and load
- LLVMContext* C, ///< The context to use for global information
+ LLVMContext& C, ///< The context to use for global information
std::string* ErrorMessage ///< An optional error string
);
/// its symbol table without reading in any of the archive's members. This
/// reduces both I/O and cpu time in opening the archive if it is to be used
/// solely for symbol lookup (e.g. during linking). The \p Filename must
- /// exist and be an archive file or an exception will be thrown. This form
+ /// exist and be an archive file or an error will be returned. This form
/// of opening the archive is intended for read-only operations that need to
/// locate members via the symbol table for link editing. Since the archve
/// members are not read by this method, the archive will appear empty upon
/// if this form of opening the archive is used that only the symbol table
/// lookup methods (getSymbolTable, findModuleDefiningSymbol, and
/// findModulesDefiningSymbols) be used.
- /// @throws std::string if an error occurs opening the file
- /// @returns an Archive* that represents the archive file.
+ /// @returns an Archive* that represents the archive file, or null on error.
/// @brief Open an existing archive and load its symbols.
static Archive* OpenAndLoadSymbols(
const sys::Path& Filename, ///< Name of the archive file to open
- LLVMContext* C, ///< The context to use for global info
+ LLVMContext& C, ///< The context to use for global info
std::string* ErrorMessage=0 ///< An optional error string
);
/// closes files. It does nothing with the archive file on disk. If you
/// haven't used the writeToDisk method by the time the destructor is
/// called, all changes to the archive will be lost.
- /// @throws std::string if an error occurs
/// @brief Destruct in-memory archive
~Archive();
/// returns the associated module that defines that symbol. This method can
/// be called as many times as necessary. This is handy for linking the
/// archive into another module based on unresolved symbols. Note that the
- /// ModuleProvider returned by this accessor should not be deleted by the
- /// caller. It is managed internally by the Archive class. It is possible
- /// that multiple calls to this accessor will return the same ModuleProvider
- /// instance because the associated module defines multiple symbols.
- /// @returns The ModuleProvider* found or null if the archive does not
- /// contain a module that defines the \p symbol.
+ /// Module returned by this accessor should not be deleted by the caller. It
+ /// is managed internally by the Archive class. It is possible that multiple
+ /// calls to this accessor will return the same Module instance because the
+ /// associated module defines multiple symbols.
+ /// @returns The Module* found or null if the archive does not contain a
+ /// module that defines the \p symbol.
/// @brief Look up a module by symbol name.
- ModuleProvider* findModuleDefiningSymbol(
+ Module* findModuleDefiningSymbol(
const std::string& symbol, ///< Symbol to be sought
std::string* ErrMessage ///< Error message storage, if non-zero
);
/// @brief Look up multiple symbols in the archive.
bool findModulesDefiningSymbols(
std::set<std::string>& symbols, ///< Symbols to be sought
- std::set<ModuleProvider*>& modules, ///< The modules matching \p symbols
+ SmallVectorImpl<Module*>& modules, ///< The modules matching \p symbols
std::string* ErrMessage ///< Error msg storage, if non-zero
);
/// bitcode 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 bitcode modules of the archive. Finally,
- /// it returns whether it was successfull.
+ /// it returns whether it was successful.
/// @returns true if the archive is a proper llvm bitcode archive
/// @brief Determine whether the archive is a proper llvm bitcode archive.
bool isBitcodeArchive();
/// name will be truncated at 15 characters. If \p Compress is specified,
/// all archive members will be compressed before being written. If
/// \p PrintSymTab is true, the symbol table will be printed to std::cout.
- /// @returns true if an error occurred, \p error set to error message
- /// @returns false if the writing succeeded.
+ /// @returns true if an error occurred, \p error set to error message;
+ /// returns false if the writing succeeded.
/// @brief Write (possibly modified) archive contents to disk
bool writeToDisk(
bool CreateSymbolTable=false, ///< Create Symbol table
bool TruncateNames=false, ///< Truncate the filename to 15 chars
- bool Compress=false, ///< Compress files
std::string* ErrMessage=0 ///< If non-null, where error msg is set
);
/// to determine just enough information to create an ArchiveMember object
/// which is then inserted into the Archive object's ilist at the location
/// given by \p where.
- /// @returns true if an error occured, false otherwise
+ /// @returns true if an error occurred, false otherwise
/// @brief Add a file to the archive.
bool addFileBefore(
const sys::Path& filename, ///< The file to be added
protected:
/// @brief Construct an Archive for \p filename and optionally map it
/// into memory.
- explicit Archive(const sys::Path& filename, LLVMContext* C);
+ explicit Archive(const sys::Path& filename, LLVMContext& C);
/// @param data The symbol table data to be parsed
/// @param len The length of the symbol table data
/// Writes one ArchiveMember to an ofstream. If an error occurs, returns
/// false, otherwise true. If an error occurs and error is non-null then
/// it will be set to an error message.
- /// @returns false Writing member succeeded
- /// @returns true Writing member failed, \p error set to error message
+ /// @returns false if writing member succeeded,
+ /// returns true if writing member failed, \p error set to error message.
bool writeMember(
const ArchiveMember& member, ///< The member to be written
std::ofstream& ARFile, ///< The file to write member onto
bool CreateSymbolTable, ///< Should symbol table be created?
bool TruncateNames, ///< Should names be truncated to 11 chars?
- bool ShouldCompress, ///< Should the member be compressed?
std::string* ErrMessage ///< If non-null, place were error msg is set
);
/// This type is used to keep track of bitcode modules loaded from the
/// symbol table. It maps the file offset to a pair that consists of the
- /// associated ArchiveMember and the ModuleProvider.
+ /// associated ArchiveMember and the Module.
/// @brief Module mapping type
- typedef std::map<unsigned,std::pair<ModuleProvider*,ArchiveMember*> >
+ typedef std::map<unsigned,std::pair<Module*,ArchiveMember*> >
ModuleMap;
unsigned firstFileOffset; ///< Offset to first normal file.
ModuleMap modules; ///< The modules loaded via symbol lookup.
ArchiveMember* foreignST; ///< This holds the foreign symbol table.
- LLVMContext* Context; ///< This holds global data.
+ LLVMContext& Context; ///< This holds global data.
/// @}
/// @name Hidden
/// @{
private:
- Archive(); ///< Do not implement
- Archive(const Archive&); ///< Do not implement
- Archive& operator=(const Archive&); ///< Do not implement
+ Archive() LLVM_DELETED_FUNCTION;
+ Archive(const Archive&) LLVM_DELETED_FUNCTION;
+ Archive& operator=(const Archive&) LLVM_DELETED_FUNCTION;
/// @}
};