[llvm] r312673 - Removes redundant `llvm::`, add comments and simplify a return type of a function.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 6 15:05:32 PDT 2017
Author: ruiu
Date: Wed Sep 6 15:05:32 2017
New Revision: 312673
URL: http://llvm.org/viewvc/llvm-project?rev=312673&view=rev
Log:
Removes redundant `llvm::`, add comments and simplify a return type of a function.
No functional change intended.
Modified:
llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Modified: llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp?rev=312673&r1=312672&r2=312673&view=diff
==============================================================================
--- llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp (original)
+++ llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp Wed Sep 6 15:05:32 2017
@@ -40,31 +40,31 @@ enum {
#include "Options.inc"
#undef PREFIX
-static const llvm::opt::OptTable::Info InfoTable[] = {
+static const opt::OptTable::Info InfoTable[] = {
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
- {X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \
+ {X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
#include "Options.inc"
#undef OPTION
};
-class LibOptTable : public llvm::opt::OptTable {
+class LibOptTable : public opt::OptTable {
public:
LibOptTable() : OptTable(InfoTable, true) {}
};
}
-static std::string getOutputPath(llvm::opt::InputArgList *Args,
- const llvm::NewArchiveMember &FirstMember) {
+static std::string getOutputPath(opt::InputArgList *Args,
+ const NewArchiveMember &FirstMember) {
if (auto *Arg = Args->getLastArg(OPT_out))
return Arg->getValue();
SmallString<128> Val = StringRef(FirstMember.Buf->getBufferIdentifier());
- llvm::sys::path::replace_extension(Val, ".lib");
+ sys::path::replace_extension(Val, ".lib");
return Val.str();
}
-static std::vector<StringRef> getSearchPaths(llvm::opt::InputArgList *Args,
+static std::vector<StringRef> getSearchPaths(opt::InputArgList *Args,
StringSaver &Saver) {
std::vector<StringRef> Ret;
// Add current directory as first item of the search path.
@@ -87,28 +87,29 @@ static std::vector<StringRef> getSearchP
return Ret;
}
-static Optional<std::string> findInputFile(StringRef File,
- ArrayRef<StringRef> Paths) {
- for (auto Dir : Paths) {
+static std::string findInputFile(StringRef File, ArrayRef<StringRef> Paths) {
+ for (StringRef Dir : Paths) {
SmallString<128> Path = Dir;
sys::path::append(Path, File);
if (sys::fs::exists(Path))
return Path.str().str();
}
- return Optional<std::string>();
+ return "";
}
-int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
- SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end());
+int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
BumpPtrAllocator Alloc;
StringSaver Saver(Alloc);
+
+ // Parse command line arguments.
+ SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end());
cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs);
ArgsArr = NewArgs;
LibOptTable Table;
unsigned MissingIndex;
unsigned MissingCount;
- llvm::opt::InputArgList Args =
+ opt::InputArgList Args =
Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount);
if (MissingCount) {
llvm::errs() << "missing arg value for \""
@@ -120,32 +121,33 @@ int llvm::libDriverMain(llvm::ArrayRef<c
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";
- if (!Args.hasArgNoClaim(OPT_INPUT)) {
- // No input files. To match lib.exe, silently do nothing.
+ // If no input files, silently do nothing to match lib.exe.
+ if (!Args.hasArgNoClaim(OPT_INPUT))
return 0;
- }
std::vector<StringRef> SearchPaths = getSearchPaths(&Args, Saver);
- std::vector<llvm::NewArchiveMember> Members;
+ // Create a NewArchiveMember for each input file.
+ std::vector<NewArchiveMember> Members;
for (auto *Arg : Args.filtered(OPT_INPUT)) {
- Optional<std::string> Path = findInputFile(Arg->getValue(), SearchPaths);
- if (!Path.hasValue()) {
+ std::string Path = findInputFile(Arg->getValue(), SearchPaths);
+ if (Path.empty()) {
llvm::errs() << Arg->getValue() << ": no such file or directory\n";
return 1;
}
+
Expected<NewArchiveMember> MOrErr =
- NewArchiveMember::getFile(Saver.save(*Path), /*Deterministic=*/true);
+ NewArchiveMember::getFile(Saver.save(Path), /*Deterministic=*/true);
if (!MOrErr) {
- handleAllErrors(MOrErr.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
+ handleAllErrors(MOrErr.takeError(), [&](const ErrorInfoBase &EIB) {
llvm::errs() << Arg->getValue() << ": " << EIB.message() << "\n";
});
return 1;
}
- llvm::file_magic Magic = llvm::identify_magic(MOrErr->Buf->getBuffer());
- if (Magic != llvm::file_magic::coff_object &&
- Magic != llvm::file_magic::bitcode &&
- Magic != llvm::file_magic::windows_resource) {
+
+ file_magic Magic = identify_magic(MOrErr->Buf->getBuffer());
+ if (Magic != file_magic::coff_object && Magic != file_magic::bitcode &&
+ Magic != file_magic::windows_resource) {
llvm::errs() << Arg->getValue()
<< ": not a COFF object, bitcode or resource file\n";
return 1;
@@ -153,11 +155,12 @@ int llvm::libDriverMain(llvm::ArrayRef<c
Members.emplace_back(std::move(*MOrErr));
}
+ // Create an archive file.
std::string OutputPath = getOutputPath(&Args, Members[0]);
std::error_code EC =
- llvm::writeArchive(OutputPath, Members,
- /*WriteSymtab=*/true, object::Archive::K_GNU,
- /*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin));
+ writeArchive(OutputPath, Members,
+ /*WriteSymtab=*/true, object::Archive::K_GNU,
+ /*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin));
if (EC) {
llvm::errs() << OutputPath << ": " << EC.message() << "\n";
More information about the llvm-commits
mailing list