40 size_t MinSize = std::min(
A.size(),
B.size());
41 if (
int Res =
A.substr(0, MinSize).compare_insensitive(
B.substr(0, MinSize)))
44 if (
A.size() ==
B.size())
47 return (
A.size() == MinSize) ? 1
65 for (
size_t I = 0, K = std::min(
A.Prefixes.size(),
B.Prefixes.size());
I != K;
73 "Unexpected classes for options with same name.");
89 : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
95 unsigned Kind = getInfo(i + 1).
Kind;
97 assert(!InputOptionID &&
"Cannot have multiple input options!");
98 InputOptionID = getInfo(i + 1).
ID;
100 assert(!UnknownOptionID &&
"Cannot have multiple unknown options!");
101 UnknownOptionID = getInfo(i + 1).
ID;
116 "Special options should be defined first!");
121 if (!(getInfo(i) < getInfo(i + 1))) {
135 for (
char C : Prefix)
144 unsigned id = Opt.
getID();
146 return Option(
nullptr,
nullptr);
148 return Option(&getInfo(
id),
this);
155 if (
Arg.startswith(Prefix))
163 for (
auto Prefix :
I->Prefixes) {
164 if (Str.startswith(Prefix)) {
165 StringRef Rest = Str.substr(Prefix.size());
177 for (
auto Prefix : In.Prefixes)
178 if (
Option.endswith(In.Name))
179 if (
Option.slice(0,
Option.size() - In.Name.size()) == Prefix)
187std::vector<std::string>
191 const Info &In = OptionInfos[
I];
198 std::vector<std::string> Result;
200 if (Val.startswith(
Arg) &&
Arg.compare(Val))
201 Result.push_back(std::string(Val));
207std::vector<std::string>
209 std::vector<std::string> Ret;
211 const Info &In = OptionInfos[
I];
212 if (In.Prefixes.empty() || (!In.HelpText && !In.GroupID))
214 if (In.Flags & DisableFlags)
217 for (
auto Prefix : In.Prefixes) {
218 std::string S = (Prefix + In.Name +
"\t").str();
229 unsigned FlagsToInclude,
unsigned FlagsToExclude,
230 unsigned MinimumLength,
231 unsigned MaximumDistance)
const {
236 unsigned BestDistance =
237 MaximumDistance == UINT_MAX ? UINT_MAX : MaximumDistance + 1;
241 for (
const Info &CandidateInfo :
243 StringRef CandidateName = CandidateInfo.Name;
248 if (CandidateName.
size() < MinimumLength)
253 if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude))
256 if (CandidateInfo.Flags & FlagsToExclude)
261 if (CandidateInfo.Prefixes.empty())
268 bool CandidateHasDelimiter =
Last ==
'=' ||
Last ==
':';
270 if (CandidateHasDelimiter) {
273 NormalizedName +=
Last;
280 for (
auto CandidatePrefix : CandidateInfo.Prefixes) {
285 size_t CandidateSize = CandidatePrefix.size() + CandidateName.
size(),
286 NormalizedSize = NormalizedName.
size();
287 size_t AbsDiff = CandidateSize > NormalizedSize
288 ? CandidateSize - NormalizedSize
289 : NormalizedSize - CandidateSize;
290 if (AbsDiff > BestDistance) {
293 Candidate = CandidatePrefix;
294 Candidate += CandidateName;
296 NormalizedName,
true,
298 if (
RHS.empty() && CandidateHasDelimiter) {
307 if (Distance < BestDistance) {
308 BestDistance = Distance;
309 NearestString = (Candidate +
RHS).str();
320std::unique_ptr<Arg> OptTable::parseOneArgGrouped(
InputArgList &Args,
321 unsigned &
Index)
const {
324 const char *CStr = Args.getArgString(
Index);
327 return std::make_unique<Arg>(
getOption(InputOptionID), Str,
Index++, CStr);
329 const Info *
End = OptionInfos.data() + OptionInfos.size();
334 unsigned Prev =
Index;
337 for (; Start !=
End; ++Start) {
338 unsigned ArgSize =
matchOption(Start, Str, IgnoreCase);
343 if (std::unique_ptr<Arg>
A =
359 Option Opt(Fallback,
this);
362 return std::make_unique<Arg>(
getOption(UnknownOptionID), Str,
Index++,
365 if (std::unique_ptr<Arg>
A = Opt.accept(
366 Args, Str.substr(0, 2),
true,
Index)) {
367 Args.replaceArgString(
Index,
Twine(
'-') + Str.substr(2));
375 CStr =
Args.MakeArgString(Str.substr(0, 2));
377 return std::make_unique<Arg>(
getOption(UnknownOptionID), CStr,
Index, CStr);
380 return std::make_unique<Arg>(
getOption(UnknownOptionID), Str,
Index++, CStr);
384 unsigned FlagsToInclude,
385 unsigned FlagsToExclude)
const {
386 unsigned Prev =
Index;
392 return std::make_unique<Arg>(
getOption(InputOptionID), Str,
Index++,
396 const Info *
End = OptionInfos.data() + OptionInfos.size();
400 Start = std::lower_bound(Start,
End,
Name);
410 for (; Start !=
End; ++Start) {
411 unsigned ArgSize = 0;
413 for (; Start !=
End; ++Start)
414 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
421 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
423 if (Opt.
hasFlag(FlagsToExclude))
427 if (std::unique_ptr<Arg>
A =
440 return std::make_unique<Arg>(
getOption(InputOptionID), Str,
Index++,
443 return std::make_unique<Arg>(
getOption(UnknownOptionID), Str,
Index++,
448 unsigned &MissingArgIndex,
449 unsigned &MissingArgCount,
450 unsigned FlagsToInclude,
451 unsigned FlagsToExclude)
const {
456 MissingArgIndex = MissingArgCount = 0;
460 if (Args.getArgString(
Index) ==
nullptr) {
471 unsigned Prev =
Index;
472 std::unique_ptr<Arg>
A = GroupedShortOptions
473 ? parseOneArgGrouped(Args,
Index)
476 "Parser failed to consume argument.");
481 assert(
Index - Prev - 1 &&
"No missing arguments!");
482 MissingArgIndex = Prev;
483 MissingArgCount =
Index - Prev - 1;
487 Args.append(
A.release());
504 ErrorFn((
Twine(Args.getArgString(MAI)) +
": missing argument").str());
510 std::string Spelling =
A->getAsString(Args);
512 ErrorFn(
"unknown argument '" + Spelling +
"'");
514 ErrorFn(
"unknown argument '" + Spelling +
"', did you mean '" + Nearest +
522 std::string
Name = O.getPrefixedName();
525 switch (O.getKind()) {
537 for (
unsigned i=0, e=O.getNumArgs(); i< e; ++i) {
573 std::vector<OptionInfo> &OptionHelp) {
574 OS << Title <<
":\n";
577 unsigned OptionFieldWidth = 0;
578 for (
const OptionInfo &Opt : OptionHelp) {
580 unsigned Length = Opt.Name.size();
582 OptionFieldWidth = std::max(OptionFieldWidth,
Length);
585 const unsigned InitialPad = 2;
586 for (
const OptionInfo &Opt : OptionHelp) {
587 const std::string &
Option = Opt.Name;
588 int Pad = OptionFieldWidth - int(
Option.size());
594 Pad = OptionFieldWidth + InitialPad;
596 OS.
indent(Pad + 1) << Opt.HelpText <<
'\n';
619 bool ShowHidden,
bool ShowAllAliases)
const {
621 (ShowHidden ? 0 :
HelpHidden), ShowAllAliases);
625 unsigned FlagsToInclude,
unsigned FlagsToExclude,
626 bool ShowAllAliases)
const {
627 OS <<
"OVERVIEW: " << Title <<
"\n\n";
628 OS <<
"USAGE: " << Usage <<
"\n\n";
632 std::map<std::string, std::vector<OptionInfo>> GroupedOptionHelp;
634 for (
unsigned Id = 1, e =
getNumOptions() + 1; Id != e; ++Id) {
640 if (FlagsToInclude && !(
Flags & FlagsToInclude))
642 if (
Flags & FlagsToExclude)
648 if (!HelpText && ShowAllAliases) {
654 if (HelpText && (strlen(HelpText) != 0)) {
657 GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
661 for (
auto& OptionGroup : GroupedOptionHelp) {
662 if (OptionGroup.first != GroupedOptionHelp.begin()->first)
671 :
OptTable(OptionInfos, IgnoreCase) {
673 std::set<StringLiteral> TmpPrefixesUnion;
676 PrefixesUnionBuffer.append(TmpPrefixesUnion.begin(), TmpPrefixesUnion.end());
Defines the llvm::Arg class for parsed arguments.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase)
static bool optionMatches(const OptTable::Info &In, StringRef Option)
static const char * getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id)
static bool isInput(const ArrayRef< StringLiteral > &Prefixes, StringRef Arg)
static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id)
static void PrintHelpOptionList(raw_ostream &OS, StringRef Title, std::vector< OptionInfo > &OptionHelp)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
size_t size() const
size - Get the array size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool starts_with_insensitive(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
char back() const
back - Get the last character in the string.
constexpr size_t size() const
size - Get the string size.
bool startswith(StringRef Prefix) const
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
An efficient, type-erasing, non-owning reference to a callable.
ArgList - Ordered collection of driver arguments.
A concrete instance of a particular driver option.
GenericOptTable(ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
OptSpecifier - Wrapper class for abstracting references to option IDs.
Provide access to the Option info table.
void buildPrefixChars()
Build (or rebuild) the PrefixChars member.
std::unique_ptr< 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.
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
unsigned FirstSearchableIndex
The index of the first option which can be parsed (i.e., is not a special option like 'input' or 'unk...
const char * getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text.
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.
const Option getOption(OptSpecifier Opt) const
Get the given Opt's Option instance, lazily creating it if necessary.
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
InputArgList parseArgs(int Argc, char *const *Argv, OptSpecifier Unknown, StringSaver &Saver, function_ref< void(StringRef)> ErrorFn) const
A convenience helper which handles optional initial options populated from an environment variable,...
std::vector< std::string > findByPrefix(StringRef Cur, unsigned int DisableFlags) const
Find flags from OptTable which starts with Cur.
OptTable(ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
Initialize OptTable using Tablegen'ed OptionInfos.
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.
unsigned findNearest(StringRef Option, std::string &NearestString, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0, unsigned MinimumLength=4, unsigned MaximumDistance=UINT_MAX) const
Find the OptTable option that most closely matches the given string.
unsigned getOptionGroupID(OptSpecifier id) const
Get the group id for the given option.
std::vector< std::string > suggestValueCompletions(StringRef Option, StringRef Arg) const
Find possible value for given flags.
SmallString< 8 > PrefixChars
The union of the first element of all option prefixes.
virtual ArrayRef< StringLiteral > getPrefixesUnion() const =0
The union of all option prefixes.
unsigned getNumOptions() const
Return the total number of option classes.
Option - Abstract representation for a single form of driver argument.
const Option getAlias() const
bool hasFlag(unsigned Val) const
Test if this option has the flag Val.
@ RemainingArgsJoinedClass
std::unique_ptr< Arg > accept(const ArgList &Args, StringRef CurArg, bool GroupedShortOption, unsigned &Index) const
Potentially accept the current argument, returning a new Arg instance, or 0 if the option does not ac...
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ C
The default llvm calling convention, compatible with C.
bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, SmallVectorImpl< const char * > &NewArgv)
A convenience helper which concatenates the options specified by the environment variable EnvVar and ...
static int StrCmpOptionName(StringRef A, StringRef B)
static bool operator<(const OptTable::Info &A, const OptTable::Info &B)
static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B)
This is an optimization pass for GlobalISel generic memory operations.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Entry for a single option instance in the option data table.
ArrayRef< StringLiteral > Prefixes
A null terminated array of prefix strings to apply to name while matching.