39 const char *
X = A, *
Y =
B;
40 char a = tolower(*A), b = tolower(*B);
55 return (a < b) ? -1 : 1;
72 for (
const char *
const *APre = A.
Prefixes,
74 *APre !=
nullptr && *BPre !=
nullptr; ++APre, ++BPre){
82 "Unexpected classes for options with same name.");
98 : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
104 unsigned Kind = getInfo(i + 1).
Kind;
106 assert(!TheInputOptionID &&
"Cannot have multiple input options!");
107 TheInputOptionID = getInfo(i + 1).
ID;
109 assert(!TheUnknownOptionID &&
"Cannot have multiple unknown options!");
110 TheUnknownOptionID = getInfo(i + 1).
ID;
112 FirstSearchableIndex = i;
116 assert(FirstSearchableIndex != 0 &&
"No searchable options?");
121 for (
unsigned i = FirstSearchableIndex,
e =
getNumOptions(); i !=
e; ++i) {
125 "Special options should be defined first!");
129 for (
unsigned i = FirstSearchableIndex + 1,
e =
getNumOptions(); i !=
e; ++i){
130 if (!(getInfo(i) < getInfo(i + 1))) {
139 for (
unsigned i = FirstSearchableIndex + 1,
e =
getNumOptions() + 1;
141 if (
const char *
const *
P = getInfo(i).Prefixes) {
142 for (; *
P !=
nullptr; ++
P) {
150 E = PrefixesUnion.
end();
I !=
E; ++
I) {
155 PrefixChars.push_back(*
C);
162 unsigned id = Opt.
getID();
164 return Option(
nullptr,
nullptr);
166 return Option(&getInfo(
id),
this);
173 E = Prefixes.
end();
I !=
E; ++
I)
182 for (
const char *
const *Pre = I->
Prefixes; *Pre !=
nullptr; ++Pre) {
186 bool Matched = IgnoreCase
208 std::vector<std::string>
211 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
212 const Info &
In = OptionInfos[
I];
219 std::vector<std::string> Result;
221 if (Val.startswith(Arg) && Arg.
compare(Val))
222 Result.push_back(Val);
228 std::vector<std::string>
230 std::vector<std::string>
Ret;
231 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
232 const Info &
In = OptionInfos[
I];
235 if (In.
Flags & DisableFlags)
239 std::string S = std::string(In.
Prefixes[
I]) + std::string(In.
Name) +
"\t";
250 unsigned FlagsToInclude,
unsigned FlagsToExclude,
251 unsigned MinimumLength)
const {
256 unsigned BestDistance = UINT_MAX;
257 for (
const Info &CandidateInfo :
259 StringRef CandidateName = CandidateInfo.Name;
264 if (CandidateName.
empty() || CandidateName.
size() < MinimumLength)
269 if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude))
272 if (CandidateInfo.Flags & FlagsToExclude)
277 if (!CandidateInfo.Prefixes)
284 char Last = CandidateName.
back();
285 bool CandidateHasDelimiter = Last ==
'=' || Last ==
':';
286 std::string NormalizedName = Option;
287 if (CandidateHasDelimiter) {
288 std::tie(LHS, RHS) = Option.
split(Last);
289 NormalizedName = LHS;
290 if (Option.
find(Last) == LHS.
size())
291 NormalizedName += Last;
298 const char *
const CandidatePrefix = CandidateInfo.Prefixes[
P];
P++) {
299 std::string Candidate = (CandidatePrefix + CandidateName).str();
304 if (RHS.
empty() && CandidateHasDelimiter) {
313 if (Distance < BestDistance) {
314 BestDistance = Distance;
315 NearestString = (Candidate + RHS).str();
323 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
334 unsigned FlagsToInclude,
335 unsigned FlagsToExclude)
const {
336 unsigned Prev =
Index;
341 if (
isInput(PrefixesUnion, Str))
342 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
344 const Info *Start = OptionInfos.data() + FirstSearchableIndex;
345 const Info *End = OptionInfos.data() + OptionInfos.size();
359 for (; Start != End; ++Start) {
360 unsigned ArgSize = 0;
362 for (; Start != End; ++Start)
363 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
370 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
372 if (Opt.
hasFlag(FlagsToExclude))
376 if (
Arg *A = Opt.
accept(Args, Index, ArgSize))
387 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
389 return new Arg(
getOption(TheUnknownOptionID), Str, Index++, Str);
393 unsigned &MissingArgIndex,
394 unsigned &MissingArgCount,
395 unsigned FlagsToInclude,
396 unsigned FlagsToExclude)
const {
401 MissingArgIndex = MissingArgCount = 0;
403 while (Index < End) {
405 if (
Args.getArgString(Index) ==
nullptr) {
416 unsigned Prev =
Index;
418 assert(Index > Prev &&
"Parser failed to consume argument.");
422 assert(Index >= End &&
"Unexpected parser error.");
423 assert(Index - Prev - 1 &&
"No missing arguments!");
424 MissingArgIndex = Prev;
425 MissingArgCount = Index - Prev - 1;
488 std::vector<OptionInfo> &OptionHelp) {
489 OS << Title <<
":\n";
492 unsigned OptionFieldWidth = 0;
493 for (
unsigned i = 0,
e = OptionHelp.size(); i !=
e; ++i) {
495 unsigned Length = OptionHelp[i].Name.
size();
497 OptionFieldWidth =
std::max(OptionFieldWidth, Length);
500 const unsigned InitialPad = 2;
501 for (
unsigned i = 0,
e = OptionHelp.size(); i !=
e; ++i) {
502 const std::string &
Option = OptionHelp[i].Name;
503 int Pad = OptionFieldWidth - int(Option.size());
504 OS.
indent(InitialPad) << Option;
509 Pad = OptionFieldWidth + InitialPad;
511 OS.
indent(Pad + 1) << OptionHelp[i].HelpText <<
'\n';
534 bool ShowHidden,
bool ShowAllAliases)
const {
536 (ShowHidden ? 0 :
HelpHidden), ShowAllAliases);
540 unsigned FlagsToInclude,
unsigned FlagsToExclude,
541 bool ShowAllAliases)
const {
542 OS <<
"OVERVIEW: " << Title <<
"\n\n";
543 OS <<
"USAGE: " << Usage <<
"\n\n";
547 std::map<std::string, std::vector<OptionInfo>> GroupedOptionHelp;
554 unsigned Flags = getInfo(
Id).Flags;
555 if (FlagsToInclude && !(Flags & FlagsToInclude))
557 if (Flags & FlagsToExclude)
563 if (!HelpText && ShowAllAliases) {
572 GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
576 for (
auto& OptionGroup : GroupedOptionHelp) {
577 if (OptionGroup.first != GroupedOptionHelp.begin()->first)
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
unsigned getNumOptions() const
Return the total number of option classes.
This class represents lattice values for constants.
std::string getPrefixedName() const
Get the name of this option with the default prefix.
static bool operator<(const OptTable::Info &A, const OptTable::Info &B)
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_NODISCARD int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase)
InputArgList ParseArgs(ArrayRef< const char *> Args, unsigned &MissingArgIndex, unsigned &MissingArgCount, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const
Parse an list of arguments into an InputArgList.
unsigned getOptionGroupID(OptSpecifier id) const
Get the group id for the given option.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
LLVM_NODISCARD StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
LLVM_NODISCARD unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
std::vector< std::string > findByPrefix(StringRef Cur, unsigned short DisableFlags) const
Find flags from OptTable which starts with Cur.
Arg * ParseOneArg(const ArgList &Args, unsigned &Index, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const
Parse a single argument; returning the new argument and updating Index.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
static bool startswith(StringRef Magic, const char(&S)[N])
static bool optionMatches(const OptTable::Info &In, StringRef Option)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
OptTable(ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
LLVM_NODISCARD size_t size() const
size - Get the string size.
static const char * getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id)
OptionClass getKind() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Option - Abstract representation for a single form of driver argument.
A concrete instance of a particular driver option.
Provide access to the Option info table.
size_t size() const
size - Get the array size.
bool hasFlag(unsigned Val) const
Test if this option has the flag Val.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const char *const * Prefixes
A null terminated array of prefix strings to apply to name while matching.
const Option getOption(OptSpecifier Opt) const
Get the given Opt's Option instance, lazily creating it if necessary.
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static int StrCmpOptionName(const char *A, const char *B)
LLVM_NODISCARD char back() const
back - Get the last character in the string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< typename base::iterator, bool > insert(StringRef Key)
const Option getAlias() const
std::vector< std::string > suggestValueCompletions(StringRef Option, StringRef Arg) const
Find possible value for given flags.
unsigned findNearest(StringRef Option, std::string &NearestString, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0, unsigned MinimumLength=4) const
Find the OptTable option that most closely matches the given string.
Align max(MaybeAlign Lhs, Align Rhs)
virtual const char * getArgString(unsigned Index) const =0
getArgString - Return the input argument string at Index.
static void PrintHelpOptionList(raw_ostream &OS, StringRef Title, std::vector< OptionInfo > &OptionHelp)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
static int StrCmpOptionNameIgnoreCase(const char *A, const char *B)
unsigned getNumArgs() const
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
Defines the llvm::Arg class for parsed arguments.
OptSpecifier - Wrapper class for abstracting references to option IDs.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Entry for a single option instance in the option data table.
bool addValues(const char *Option, const char *Values)
Add Values to Option's Values class.
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id)
const char * getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text...
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isInput(const StringSet<> &Prefixes, StringRef Arg)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
StringSet - A wrapper for StringMap that provides set-like functionality.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
ArgList - Ordered collection of driver arguments.
void PrintHelp(raw_ostream &OS, const char *Usage, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude, bool ShowAllAliases) const
Render the help text for an option table.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Arg * accept(const ArgList &Args, unsigned &Index, unsigned ArgSize) const
accept - Potentially accept the current argument, returning a new Arg instance, or 0 if the option do...