diff --git a/include/llvm/Option/ArgList.h b/include/llvm/Option/ArgList.h index ef4005761b7..0a78e935afa 100644 --- a/include/llvm/Option/ArgList.h +++ b/include/llvm/Option/ArgList.h @@ -259,6 +259,9 @@ public: void AddLastArg(ArgStringList &Output, OptSpecifier Id0, OptSpecifier Id1) const; + /// AddAllArgs - Render all arguments matching any of the given ids. + void AddAllArgs(ArgStringList &Output, ArrayRef Ids) const; + /// AddAllArgs - Render all arguments matching the given ids. void AddAllArgs(ArgStringList &Output, OptSpecifier Id0, OptSpecifier Id1 = 0U, OptSpecifier Id2 = 0U) const; diff --git a/lib/Option/ArgList.cpp b/lib/Option/ArgList.cpp index a74ead6b358..a37f443e56f 100644 --- a/lib/Option/ArgList.cpp +++ b/lib/Option/ArgList.cpp @@ -258,6 +258,21 @@ void ArgList::AddLastArg(ArgStringList &Output, OptSpecifier Id0, } } +void ArgList::AddAllArgs(ArgStringList &Output, + ArrayRef Ids) const { + for (const Arg *Arg : Args) { + for (OptSpecifier Id : Ids) { + if (Arg->getOption().matches(Id)) { + Arg->claim(); + Arg->render(*this, Output); + break; + } + } + } +} + +/// This 3-opt variant of AddAllArgs could be eliminated in favor of one +/// that accepts a single specifier, given the above which accepts any number. void ArgList::AddAllArgs(ArgStringList &Output, OptSpecifier Id0, OptSpecifier Id1, OptSpecifier Id2) const { for (auto Arg: filtered(Id0, Id1, Id2)) {