[llvm] r240234 - ArrayRef-ify libDriverMain
David Blaikie
dblaikie at gmail.com
Sat Jun 20 23:31:56 PDT 2015
Author: dblaikie
Date: Sun Jun 21 01:31:56 2015
New Revision: 240234
URL: http://llvm.org/viewvc/llvm-project?rev=240234&view=rev
Log:
ArrayRef-ify libDriverMain
Modified:
llvm/trunk/include/llvm/ADT/ArrayRef.h
llvm/trunk/include/llvm/LibDriver/LibDriver.h
llvm/trunk/lib/LibDriver/LibDriver.cpp
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Modified: llvm/trunk/include/llvm/ADT/ArrayRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=240234&r1=240233&r2=240234&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
+++ llvm/trunk/include/llvm/ADT/ArrayRef.h Sun Jun 21 01:31:56 2015
@@ -286,6 +286,11 @@ namespace llvm {
return MutableArrayRef<T>(data()+N, M);
}
+ MutableArrayRef<T> drop_back(unsigned N) const {
+ assert(this->size() >= N && "Dropping more elements than exist");
+ return slice(0, this->size() - N);
+ }
+
/// @}
/// @name Operator Overloads
/// @{
Modified: llvm/trunk/include/llvm/LibDriver/LibDriver.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LibDriver/LibDriver.h?rev=240234&r1=240233&r2=240234&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LibDriver/LibDriver.h (original)
+++ llvm/trunk/include/llvm/LibDriver/LibDriver.h Sun Jun 21 01:31:56 2015
@@ -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<const char*> ARgs);
}
Modified: llvm/trunk/lib/LibDriver/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LibDriver/LibDriver.cpp?rev=240234&r1=240233&r2=240234&view=diff
==============================================================================
--- llvm/trunk/lib/LibDriver/LibDriver.cpp (original)
+++ llvm/trunk/lib/LibDriver/LibDriver.cpp Sun Jun 21 01:31:56 2015
@@ -103,19 +103,18 @@ static Optional<std::string> findInputFi
return Optional<std::string>();
}
-int llvm::libDriverMain(int Argc, const char **Argv) {
- SmallVector<const char *, 20> NewArgv(Argv, Argv + Argc);
+int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
+ SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end());
BumpPtrAllocator Alloc;
BumpPtrStringSaver Saver(Alloc);
- cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgv);
- Argv = &NewArgv[0];
- Argc = static_cast<int>(NewArgv.size());
+ cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs);
+ ArgsArr = NewArgs;
LibOptTable Table;
unsigned MissingIndex;
unsigned MissingCount;
- std::unique_ptr<llvm::opt::InputArgList> Args(Table.ParseArgs(
- makeArrayRef(Argv, Argc).slice(1), MissingIndex, MissingCount));
+ std::unique_ptr<llvm::opt::InputArgList> 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
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;
}
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=240234&r1=240233&r2=240234&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Sun Jun 21 01:31:56 2015
@@ -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<const char **>(argv));
+ return libDriverMain(makeArrayRef(argv, argc));
// Have the command line options parsed and handle things
// like --help and --version.
More information about the llvm-commits
mailing list