From db8c4e1c9e10dd2787a3c8b4cf9d1c05afe69553 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 6 Sep 2017 22:05:32 +0000 Subject: [PATCH] Removes redundant `llvm::`, add comments and simplify a return type of a function. No functional change intended. llvm-svn: 312673 --- lib/ToolDrivers/llvm-lib/LibDriver.cpp | 61 ++++++++++++++------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/lib/ToolDrivers/llvm-lib/LibDriver.cpp index 912a09316d6..a7268d048e3 100644 --- a/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -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 getSearchPaths(llvm::opt::InputArgList *Args, +static std::vector getSearchPaths(opt::InputArgList *Args, StringSaver &Saver) { std::vector Ret; // Add current directory as first item of the search path. @@ -87,28 +87,29 @@ static std::vector getSearchPaths(llvm::opt::InputArgList *Args, return Ret; } -static Optional findInputFile(StringRef File, - ArrayRef Paths) { - for (auto Dir : Paths) { +static std::string findInputFile(StringRef File, ArrayRef 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(); + return ""; } -int llvm::libDriverMain(llvm::ArrayRef ArgsArr) { - SmallVector NewArgs(ArgsArr.begin(), ArgsArr.end()); +int llvm::libDriverMain(ArrayRef ArgsArr) { BumpPtrAllocator Alloc; StringSaver Saver(Alloc); + + // Parse command line arguments. + SmallVector 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 ArgsArr) { 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 SearchPaths = getSearchPaths(&Args, Saver); - std::vector Members; + // Create a NewArchiveMember for each input file. + std::vector Members; for (auto *Arg : Args.filtered(OPT_INPUT)) { - Optional 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 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 ArgsArr) { 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";