40 const char *
X = A, *
Y =
B;
41 char a = tolower(*A), b = tolower(*B);
56 return (a < b) ? -1 : 1;
73 for (
const char *
const *APre = A.
Prefixes,
75 *APre !=
nullptr && *BPre !=
nullptr; ++APre, ++BPre){
83 "Unexpected classes for options with same name.");
99 : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
105 unsigned Kind = getInfo(i + 1).
Kind;
107 assert(!TheInputOptionID &&
"Cannot have multiple input options!");
108 TheInputOptionID = getInfo(i + 1).
ID;
110 assert(!TheUnknownOptionID &&
"Cannot have multiple unknown options!");
111 TheUnknownOptionID = getInfo(i + 1).
ID;
113 FirstSearchableIndex = i;
117 assert(FirstSearchableIndex != 0 &&
"No searchable options?");
122 for (
unsigned i = FirstSearchableIndex, e =
getNumOptions(); i != e; ++i) {
126 "Special options should be defined first!");
130 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions(); i != e; ++i){
131 if (!(getInfo(i) < getInfo(i + 1))) {
140 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions() + 1;
142 if (
const char *
const *
P = getInfo(i).Prefixes) {
143 for (; *
P !=
nullptr; ++
P) {
151 E = PrefixesUnion.
end();
I !=
E; ++
I) {
156 PrefixChars.push_back(*
C);
163 unsigned id = Opt.
getID();
165 return Option(
nullptr,
nullptr);
167 return Option(&getInfo(
id),
this);
174 E = Prefixes.
end();
I !=
E; ++
I)
183 for (
const char *
const *Pre = I->
Prefixes; *Pre !=
nullptr; ++Pre) {
187 bool Matched = IgnoreCase
209 std::vector<std::string>
212 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
213 const Info &
In = OptionInfos[
I];
220 std::vector<std::string> Result;
222 if (Val.startswith(Arg) && Arg.
compare(Val))
223 Result.push_back(Val);
229 std::vector<std::string>
231 std::vector<std::string>
Ret;
232 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
233 const Info &
In = OptionInfos[
I];
236 if (In.
Flags & DisableFlags)
240 std::string S = std::string(In.
Prefixes[
I]) + std::string(In.
Name) +
"\t";
251 unsigned FlagsToInclude,
unsigned FlagsToExclude,
252 unsigned MinimumLength)
const {
256 unsigned BestDistance = UINT_MAX;
257 for (
const Info &CandidateInfo :
259 StringRef CandidateName = CandidateInfo.Name;
263 if (CandidateName.
empty() || CandidateName.
size() < MinimumLength)
268 if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude))
271 if (CandidateInfo.Flags & FlagsToExclude)
276 if (!CandidateInfo.Prefixes)
281 for (
int P = 1; CandidateInfo.Prefixes[
P];
P++) {
283 Prefix = CandidateInfo.Prefixes[
P];
289 std::string Delimiter =
"";
290 char Last = CandidateName.
back();
291 if (Last ==
'=' || Last ==
':')
292 Delimiter = std::string(1, Last);
295 if (Delimiter.empty())
298 std::tie(LHS, RHS) = Option.
split(Last);
300 std::string NormalizedName =
305 if (Distance < BestDistance) {
306 BestDistance = Distance;
307 NearestString = (Prefix + CandidateName + RHS).str();
314 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
325 unsigned FlagsToInclude,
326 unsigned FlagsToExclude)
const {
327 unsigned Prev =
Index;
332 if (
isInput(PrefixesUnion, Str))
333 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
335 const Info *Start = OptionInfos.data() + FirstSearchableIndex;
336 const Info *End = OptionInfos.data() + OptionInfos.size();
350 for (; Start != End; ++Start) {
351 unsigned ArgSize = 0;
353 for (; Start != End; ++Start)
354 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
361 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
363 if (Opt.
hasFlag(FlagsToExclude))
367 if (
Arg *A = Opt.
accept(Args, Index, ArgSize))
378 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
380 return new Arg(
getOption(TheUnknownOptionID), Str, Index++, Str);
384 unsigned &MissingArgIndex,
385 unsigned &MissingArgCount,
386 unsigned FlagsToInclude,
387 unsigned FlagsToExclude)
const {
392 MissingArgIndex = MissingArgCount = 0;
394 while (Index < End) {
396 if (
Args.getArgString(Index) ==
nullptr) {
407 unsigned Prev =
Index;
409 assert(Index > Prev &&
"Parser failed to consume argument.");
413 assert(Index >= End &&
"Unexpected parser error.");
414 assert(Index - Prev - 1 &&
"No missing arguments!");
415 MissingArgIndex = Prev;
416 MissingArgCount = Index - Prev - 1;
443 for (
unsigned i=0, e=O.
getNumArgs(); i< e; ++i) {
479 std::vector<OptionInfo> &OptionHelp) {
480 OS << Title <<
":\n";
483 unsigned OptionFieldWidth = 0;
484 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
486 unsigned Length = OptionHelp[i].Name.
size();
488 OptionFieldWidth =
std::max(OptionFieldWidth, Length);
491 const unsigned InitialPad = 2;
492 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
493 const std::string &
Option = OptionHelp[i].Name;
494 int Pad = OptionFieldWidth - int(Option.size());
495 OS.
indent(InitialPad) << Option;
500 Pad = OptionFieldWidth + InitialPad;
502 OS.
indent(Pad + 1) << OptionHelp[i].HelpText <<
'\n';
525 bool ShowHidden,
bool ShowAllAliases)
const {
527 (ShowHidden ? 0 :
HelpHidden), ShowAllAliases);
531 unsigned FlagsToInclude,
unsigned FlagsToExclude,
532 bool ShowAllAliases)
const {
533 OS <<
"OVERVIEW: " << Title <<
"\n\n";
534 OS <<
"USAGE: " << Usage <<
"\n\n";
538 std::map<std::string, std::vector<OptionInfo>> GroupedOptionHelp;
545 unsigned Flags = getInfo(
Id).Flags;
546 if (FlagsToInclude && !(Flags & FlagsToInclude))
548 if (Flags & FlagsToExclude)
554 if (!HelpText && ShowAllAliases) {
563 GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
567 for (
auto& OptionGroup : GroupedOptionHelp) {
568 if (OptionGroup.first != GroupedOptionHelp.begin()->first)
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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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.
static bool startswith(StringRef Magic, const char(&S)[N])
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static int getID(struct InternalInstruction *insn, const void *miiArg)
static bool optionMatches(const OptTable::Info &In, StringRef Option)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
OptTable(ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
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 LLVM_ATTRIBUTE_ALWAYS_INLINE int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
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
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
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.
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.
amdgpu Simplify well known AMD library false Value Value * Arg
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isInput(const StringSet<> &Prefixes, StringRef Arg)
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...