summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-06-19 17:49:07 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-06-19 17:49:07 +0000
commit13f4fd77b96c39b3836d1186953003ddfea3a646 (patch)
tree396bcbceb7026ab327bffc56d5abf77f2fbf72be /tools
parent80a6d6526c4ea4de90327c1404e2689a260a9fee (diff)
downloadllvm-13f4fd77b96c39b3836d1186953003ddfea3a646.tar.gz
llvm-13f4fd77b96c39b3836d1186953003ddfea3a646.tar.bz2
llvm-13f4fd77b96c39b3836d1186953003ddfea3a646.tar.xz
Remove more uses of sys::Path.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184328 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-ar/Archive.cpp9
-rw-r--r--tools/llvm-ar/Archive.h35
-rw-r--r--tools/llvm-ar/ArchiveReader.cpp19
-rw-r--r--tools/llvm-ar/ArchiveWriter.cpp23
-rw-r--r--tools/llvm-ar/llvm-ar.cpp12
5 files changed, 46 insertions, 52 deletions
diff --git a/tools/llvm-ar/Archive.cpp b/tools/llvm-ar/Archive.cpp
index 9086d4e42e..70fddcfe4d 100644
--- a/tools/llvm-ar/Archive.cpp
+++ b/tools/llvm-ar/Archive.cpp
@@ -67,7 +67,7 @@ ArchiveMember::ArchiveMember(Archive* PAR)
// This method allows an ArchiveMember to be replaced with the data for a
// different file, presumably as an update to the member. It also makes sure
// the flags are reset correctly.
-bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
+bool ArchiveMember::replaceWith(StringRef newFile, std::string* ErrMsg) {
bool Exists;
if (sys::fs::exists(newFile.str(), Exists) || !Exists) {
if (ErrMsg)
@@ -136,10 +136,9 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
// Archive constructor - this is the only constructor that gets used for the
// Archive class. Everything else (default,copy) is deprecated. This just
// initializes and maps the file into memory, if requested.
-Archive::Archive(const sys::Path& filename, LLVMContext& C)
- : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
- symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {
-}
+Archive::Archive(StringRef filename, LLVMContext &C)
+ : archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
+ symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {}
bool
Archive::mapToMemory(std::string* ErrMsg) {
diff --git a/tools/llvm-ar/Archive.h b/tools/llvm-ar/Archive.h
index 469a3b45f0..79933ef1b8 100644
--- a/tools/llvm-ar/Archive.h
+++ b/tools/llvm-ar/Archive.h
@@ -152,7 +152,7 @@ class ArchiveMember : public ilist_node<ArchiveMember> {
/// be readable on entry to this method.
/// @returns true if an error occurred, false otherwise
/// @brief Replace contents of archive member with a new file.
- bool replaceWith(const sys::Path &aFile, std::string* ErrMsg);
+ bool replaceWith(StringRef aFile, std::string* ErrMsg);
/// @}
/// @name Data
@@ -266,10 +266,10 @@ class Archive {
/// the returned Archive object has at that time.
/// @returns An Archive* that represents the new archive file.
/// @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
- );
+ static Archive *CreateEmpty(
+ StringRef Filename, ///< Name of the archive to (eventually) create.
+ LLVMContext &C ///< Context to use for global information
+ );
/// Open an existing archive and load its contents in preparation for
/// editing. After this call, the member ilist is completely populated based
@@ -277,11 +277,11 @@ class Archive {
/// you intend to modify the archive or traverse its contents (e.g. for
/// printing).
/// @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
- std::string* ErrorMessage ///< An optional error string
- );
+ static Archive *OpenAndLoad(
+ StringRef filePath, ///< The file path to open and load
+ LLVMContext &C, ///< The context to use for global information
+ std::string *ErrorMessage ///< An optional error string
+ );
/// This destructor cleans up the Archive object, releases all memory, and
/// closes files. It does nothing with the archive file on disk. If you
@@ -296,7 +296,7 @@ class Archive {
public:
/// @returns the path to the archive file.
/// @brief Get the archive path.
- const sys::Path& getPath() { return archPath; }
+ StringRef getPath() { return archPath; }
/// This method is provided so that editing methods can be invoked directly
/// on the Archive's iplist of ArchiveMember. However, it is recommended
@@ -405,11 +405,10 @@ class Archive {
/// given by \p where.
/// @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
- iterator where, ///< Insertion point
- std::string* ErrMsg ///< Optional error message location
- );
+ bool addFileBefore(StringRef filename, ///< The file to be added
+ iterator where, ///< Insertion point
+ std::string *ErrMsg ///< Optional error message location
+ );
/// @}
/// @name Implementation
@@ -417,7 +416,7 @@ class Archive {
protected:
/// @brief Construct an Archive for \p filename and optionally map it
/// into memory.
- explicit Archive(const sys::Path& filename, LLVMContext& C);
+ explicit Archive(StringRef filename, LLVMContext& C);
/// @returns A fully populated ArchiveMember or 0 if an error occurred.
/// @brief Parse the header of a member starting at \p At
@@ -477,7 +476,7 @@ class Archive {
/// @name Data
/// @{
protected:
- sys::Path archPath; ///< Path to the archive file we read/write
+ std::string archPath; ///< Path to the archive file we read/write
MembersList members; ///< The ilist of ArchiveMember
MemoryBuffer *mapfile; ///< Raw Archive contents mapped into memory
const char* base; ///< Base of the memory mapped file data
diff --git a/tools/llvm-ar/ArchiveReader.cpp b/tools/llvm-ar/ArchiveReader.cpp
index 75a6880433..25f3c2fe7f 100644
--- a/tools/llvm-ar/ArchiveReader.cpp
+++ b/tools/llvm-ar/ArchiveReader.cpp
@@ -265,9 +265,9 @@ Archive::loadArchive(std::string* error) {
// Open and completely load the archive file.
Archive*
-Archive::OpenAndLoad(const sys::Path& File, LLVMContext& C,
+Archive::OpenAndLoad(StringRef File, LLVMContext& C,
std::string* ErrorMessage) {
- OwningPtr<Archive> result ( new Archive(File, C));
+ OwningPtr<Archive> result(new Archive(File, C));
if (result->mapToMemory(ErrorMessage))
return NULL;
if (!result->loadArchive(ErrorMessage))
@@ -282,8 +282,7 @@ Archive::getAllModules(std::vector<Module*>& Modules,
for (iterator I=begin(), E=end(); I != E; ++I) {
if (I->isBitcode()) {
- std::string FullMemberName = archPath.str() +
- "(" + I->getPath().str() + ")";
+ std::string FullMemberName = archPath + "(" + I->getPath().str() + ")";
MemoryBuffer *Buffer =
MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()),
FullMemberName.c_str());
@@ -395,8 +394,7 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
return 0;
// Now, load the bitcode module to get the Module.
- std::string FullMemberName = archPath.str() + "(" +
- mbr->getPath().str() + ")";
+ std::string FullMemberName = archPath + "(" + mbr->getPath().str() + ")";
MemoryBuffer *Buffer =
MemoryBuffer::getMemBufferCopy(StringRef(mbr->getData(), mbr->getSize()),
FullMemberName.c_str());
@@ -445,8 +443,8 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
if (mbr->isBitcode()) {
// Get the symbols
std::vector<std::string> symbols;
- std::string FullMemberName = archPath.str() + "(" +
- mbr->getPath().str() + ")";
+ std::string FullMemberName =
+ archPath + "(" + mbr->getPath().str() + ")";
Module* M =
GetBitcodeSymbols(At, mbr->getSize(), FullMemberName, Context,
symbols, error);
@@ -526,9 +524,8 @@ bool Archive::isBitcodeArchive() {
for (iterator I = begin(), E = end(); I != E; ++I) {
if (!I->isBitcode())
continue;
-
- std::string FullMemberName =
- archPath.str() + "(" + I->getPath().str() + ")";
+
+ std::string FullMemberName = archPath + "(" + I->getPath().str() + ")";
MemoryBuffer *Buffer =
MemoryBuffer::getMemBufferCopy(StringRef(I->getData(), I->getSize()),
diff --git a/tools/llvm-ar/ArchiveWriter.cpp b/tools/llvm-ar/ArchiveWriter.cpp
index 16e748469f..7b5574e0a2 100644
--- a/tools/llvm-ar/ArchiveWriter.cpp
+++ b/tools/llvm-ar/ArchiveWriter.cpp
@@ -67,7 +67,7 @@ static inline unsigned numVbrBytes(unsigned num) {
}
// Create an empty archive.
-Archive* Archive::CreateEmpty(const sys::Path& FilePath, LLVMContext& C) {
+Archive* Archive::CreateEmpty(StringRef FilePath, LLVMContext& C) {
Archive* result = new Archive(FilePath, C);
return result;
}
@@ -153,9 +153,8 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
// Insert a file into the archive before some other member. This also takes care
// of extracting the necessary flags and information from the file.
-bool
-Archive::addFileBefore(const sys::Path& filePath, iterator where,
- std::string* ErrMsg) {
+bool Archive::addFileBefore(StringRef filePath, iterator where,
+ std::string *ErrMsg) {
bool Exists;
if (sys::fs::exists(filePath.str(), Exists) || !Exists) {
if (ErrMsg)
@@ -231,8 +230,8 @@ Archive::writeMember(
// symbol table if it's a bitcode file.
if (CreateSymbolTable && member.isBitcode()) {
std::vector<std::string> symbols;
- std::string FullMemberName = archPath.str() + "(" + member.getPath().str()
- + ")";
+ std::string FullMemberName =
+ (archPath + "(" + member.getPath() + ")").str();
Module* M =
GetBitcodeSymbols(data, fSize, FullMemberName, Context, symbols, ErrMsg);
@@ -305,7 +304,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
}
// Create a temporary file to store the archive in
- sys::Path TmpArchive = archPath;
+ sys::Path TmpArchive(archPath);
if (TmpArchive.createTemporaryFileOnDisk(ErrMsg))
return true;
@@ -321,7 +320,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
if (!ArchiveFile.is_open() || ArchiveFile.bad()) {
TmpArchive.eraseFromDisk();
if (ErrMsg)
- *ErrMsg = "Error opening archive file: " + archPath.str();
+ *ErrMsg = "Error opening archive file: " + archPath;
return true;
}
@@ -355,7 +354,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
// ensure compatibility with other archivers we need to put the symbol
// table first in the file. Unfortunately, this means mapping the file
// we just wrote back in and copying it to the destination file.
- sys::Path FinalFilePath = archPath;
+ sys::Path FinalFilePath(archPath);
// Map in the archive we just wrote.
{
@@ -416,14 +415,14 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
// this because we cannot replace an open file on Windows.
cleanUpMemory();
- if (TmpArchive.renamePathOnDisk(archPath, ErrMsg))
+ if (TmpArchive.renamePathOnDisk(sys::Path(archPath), ErrMsg))
return true;
// Set correct read and write permissions after temporary file is moved
// to final destination path.
- if (archPath.makeReadableOnDisk(ErrMsg))
+ if (sys::Path(archPath).makeReadableOnDisk(ErrMsg))
return true;
- if (archPath.makeWriteableOnDisk(ErrMsg))
+ if (sys::Path(archPath).makeWriteableOnDisk(ErrMsg))
return true;
return false;
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index 27df8d8355..4061551411 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -552,7 +552,7 @@ doQuickAppend(std::string* ErrMsg) {
// Append them quickly.
for (std::set<std::string>::iterator PI = Paths.begin(), PE = Paths.end();
PI != PE; ++PI) {
- if (TheArchive->addFileBefore(sys::Path(*PI),TheArchive->end(),ErrMsg))
+ if (TheArchive->addFileBefore(*PI, TheArchive->end(), ErrMsg))
return true;
}
@@ -620,11 +620,11 @@ doReplaceOrInsert(std::string* ErrMsg) {
if (OnlyUpdate) {
// Replace the item only if it is newer.
if (si->modTime > I->getModTime())
- if (I->replaceWith(sys::Path(*found), ErrMsg))
+ if (I->replaceWith(*found, ErrMsg))
return true;
} else {
// Replace the item regardless of time stamp
- if (I->replaceWith(sys::Path(*found), ErrMsg))
+ if (I->replaceWith(*found, ErrMsg))
return true;
}
} else {
@@ -649,7 +649,7 @@ doReplaceOrInsert(std::string* ErrMsg) {
if (!remaining.empty()) {
for (std::set<std::string>::iterator PI = remaining.begin(),
PE = remaining.end(); PI != PE; ++PI) {
- if (TheArchive->addFileBefore(sys::Path(*PI),insert_spot, ErrMsg))
+ if (TheArchive->addFileBefore(*PI, insert_spot, ErrMsg))
return true;
}
}
@@ -697,11 +697,11 @@ int main(int argc, char **argv) {
// Produce a warning if we should and we're creating the archive
if (!Create)
errs() << argv[0] << ": creating " << ArchivePath.str() << "\n";
- TheArchive = Archive::CreateEmpty(ArchivePath, Context);
+ TheArchive = Archive::CreateEmpty(ArchivePath.str(), Context);
TheArchive->writeToDisk();
} else {
std::string Error;
- TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error);
+ TheArchive = Archive::OpenAndLoad(ArchivePath.str(), Context, &Error);
if (TheArchive == 0) {
errs() << argv[0] << ": error loading '" << ArchivePath.str() << "': "
<< Error << "!\n";