From 8b31d41822d0ab16854a739f6f0b7b61983f87ba Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sun, 21 Jun 2015 06:31:56 +0000 Subject: [PATCH] ArrayRef-ify libDriverMain llvm-svn: 240234 --- llvm/include/llvm/ADT/ArrayRef.h | 5 +++++ llvm/include/llvm/LibDriver/LibDriver.h | 4 +++- llvm/lib/LibDriver/LibDriver.cpp | 15 +++++++-------- llvm/tools/llvm-ar/llvm-ar.cpp | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index 397e2ee..c8242f5 100644 --- a/llvm/include/llvm/ADT/ArrayRef.h +++ b/llvm/include/llvm/ADT/ArrayRef.h @@ -286,6 +286,11 @@ namespace llvm { return MutableArrayRef(data()+N, M); } + MutableArrayRef drop_back(unsigned N) const { + assert(this->size() >= N && "Dropping more elements than exist"); + return slice(0, this->size() - N); + } + /// @} /// @name Operator Overloads /// @{ diff --git a/llvm/include/llvm/LibDriver/LibDriver.h b/llvm/include/llvm/LibDriver/LibDriver.h index 99c783c..aaaa7b7 100644 --- a/llvm/include/llvm/LibDriver/LibDriver.h +++ b/llvm/include/llvm/LibDriver/LibDriver.h @@ -15,9 +15,11 @@ #ifndef LLVM_LIBDRIVER_LIBDRIVER_H #define LLVM_LIBDRIVER_LIBDRIVER_H +#include "llvm/ADT/ArrayRef.h" + namespace llvm { -int libDriverMain(int argc, const char **argv); +int libDriverMain(llvm::ArrayRef ARgs); } diff --git a/llvm/lib/LibDriver/LibDriver.cpp b/llvm/lib/LibDriver/LibDriver.cpp index 0b7c475..e441fe8 100644 --- a/llvm/lib/LibDriver/LibDriver.cpp +++ b/llvm/lib/LibDriver/LibDriver.cpp @@ -103,19 +103,18 @@ static Optional findInputFile(StringRef File, return Optional(); } -int llvm::libDriverMain(int Argc, const char **Argv) { - SmallVector NewArgv(Argv, Argv + Argc); +int llvm::libDriverMain(llvm::ArrayRef ArgsArr) { + SmallVector NewArgs(ArgsArr.begin(), ArgsArr.end()); BumpPtrAllocator Alloc; BumpPtrStringSaver Saver(Alloc); - cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgv); - Argv = &NewArgv[0]; - Argc = static_cast(NewArgv.size()); + cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs); + ArgsArr = NewArgs; LibOptTable Table; unsigned MissingIndex; unsigned MissingCount; - std::unique_ptr Args(Table.ParseArgs( - makeArrayRef(Argv, Argc).slice(1), MissingIndex, MissingCount)); + std::unique_ptr Args( + Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount)); if (MissingCount) { llvm::errs() << "missing arg value for \"" << Args->getArgString(MissingIndex) @@ -148,7 +147,7 @@ int llvm::libDriverMain(int Argc, const char **Argv) { getOutputPath(Args.get()), Members, /*WriteSymtab=*/true); if (Result.second) { if (Result.first.empty()) - Result.first = Argv[0]; + Result.first = ArgsArr[0]; llvm::errs() << Result.first << ": " << Result.second.message() << "\n"; return 1; } diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index 6782b9c..0fd2df4 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -724,7 +724,7 @@ int main(int argc, char **argv) { StringRef Stem = sys::path::stem(ToolName); if (Stem.find("ranlib") == StringRef::npos && Stem.find("lib") != StringRef::npos) - return libDriverMain(argc, const_cast(argv)); + return libDriverMain(makeArrayRef(argv, argc)); // Have the command line options parsed and handle things // like --help and --version. -- 2.7.4