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 (
const Info &
In : OptionInfos.slice(FirstSearchableIndex)) {
219 std::vector<std::string> Result;
221 if (Val.startswith(Arg))
222 Result.push_back(Val);
228 std::vector<std::string>
230 std::vector<std::string>
Ret;
231 for (
const Info &
In : OptionInfos.slice(FirstSearchableIndex)) {
232 if (!
In.Prefixes || (!
In.HelpText && !
In.GroupID))
234 if (
In.Flags & DisableFlags)
237 for (
int I = 0;
In.Prefixes[
I];
I++) {
238 std::string S = std::string(
In.Prefixes[
I]) + std::string(
In.Name) +
"\t";
249 unsigned FlagsToInclude,
250 unsigned FlagsToExclude)
const {
251 unsigned Prev = Index;
256 if (
isInput(PrefixesUnion, Str))
257 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
259 const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
260 const Info *
End = OptionInfos.end();
264 Start = std::lower_bound(Start, End, Name.
data());
274 for (; Start !=
End; ++Start) {
275 unsigned ArgSize = 0;
277 for (; Start !=
End; ++Start)
278 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
285 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
287 if (Opt.
hasFlag(FlagsToExclude))
291 if (
Arg *
A = Opt.
accept(Args, Index, ArgSize))
302 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
304 return new Arg(
getOption(TheUnknownOptionID), Str, Index++, Str);
308 unsigned &MissingArgIndex,
309 unsigned &MissingArgCount,
310 unsigned FlagsToInclude,
311 unsigned FlagsToExclude)
const {
316 MissingArgIndex = MissingArgCount = 0;
317 unsigned Index = 0,
End = ArgArr.
size();
318 while (Index <
End) {
320 if (
Args.getArgString(Index) ==
nullptr) {
331 unsigned Prev = Index;
333 assert(Index > Prev &&
"Parser failed to consume argument.");
337 assert(Index >=
End &&
"Unexpected parser error.");
338 assert(Index - Prev - 1 &&
"No missing arguments!");
339 MissingArgIndex = Prev;
340 MissingArgCount = Index - Prev - 1;
367 for (
unsigned i=0, e=O.
getNumArgs(); i< e; ++i) {
403 std::vector<OptionInfo> &OptionHelp) {
404 OS << Title <<
":\n";
407 unsigned OptionFieldWidth = 0;
408 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
410 unsigned Length = OptionHelp[i].Name.
size();
412 OptionFieldWidth =
std::max(OptionFieldWidth, Length);
415 const unsigned InitialPad = 2;
416 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
417 const std::string &
Option = OptionHelp[i].Name;
418 int Pad = OptionFieldWidth - int(Option.size());
419 OS.
indent(InitialPad) << Option;
424 Pad = OptionFieldWidth + InitialPad;
426 OS.
indent(Pad + 1) << OptionHelp[i].HelpText <<
'\n';
449 bool ShowHidden)
const {
456 unsigned FlagsToInclude,
457 unsigned FlagsToExclude)
const {
458 OS <<
"OVERVIEW: " << Title <<
"\n";
460 OS <<
"USAGE: " << Name <<
" [options] <inputs>\n";
465 using helpmap_ty = std::map<std::string, std::vector<OptionInfo>>;
466 helpmap_ty GroupedOptionHelp;
476 if (FlagsToInclude && !(Flags & FlagsToInclude))
478 if (Flags & FlagsToExclude)
484 GroupedOptionHelp[HelpGroup].push_back({OptName, Text});
488 for (helpmap_ty::iterator it = GroupedOptionHelp .
begin(),
489 ie = GroupedOptionHelp.
end(); it != ie; ++it) {
490 if (it != GroupedOptionHelp .
begin())
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static bool operator<(const OptTable::Info &A, const OptTable::Info &B)
bool hasFlag(unsigned Val) const
Test if this option has the flag Val.
static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase)
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
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.
OptionClass getKind() const
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
static bool startswith(StringRef Magic, const char(&S)[N])
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 startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
unsigned getNumArgs() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
OptTable(ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static const char * getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id)
size_t size() const
size - Get the array size.
friend const_iterator end(StringRef path)
Get end iterator over path.
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.
std::string getPrefixedName() const
Get the name of this option with the default prefix.
const char *const * Prefixes
A null terminated array of prefix strings to apply to name while matching.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
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 GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static const unsigned End
static int StrCmpOptionName(const char *A, const char *B)
std::pair< typename base::iterator, bool > insert(StringRef Key)
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...
static int StrCmpOptionNameIgnoreCase(const char *A, const char *B)
std::vector< std::string > findByPrefix(StringRef Cur, unsigned short DisableFlags) const
Find flags from OptTable which starts with Cur.
void PrintHelp(raw_ostream &OS, const char *Name, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude) const
Render the help text for an option table.
unsigned getNumOptions() const
Return the total number of option classes.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Defines the llvm::Arg class for parsed arguments.
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
std::vector< std::string > suggestValueCompletions(StringRef Option, StringRef Arg) const
Find possible value for given flags.
OptSpecifier - Wrapper class for abstracting references to option IDs.
const Option getOption(OptSpecifier Opt) const
Get the given Opt's Option instance, lazily creating it if necessary.
Entry for a single option instance in the option data table.
LLVM_NODISCARD StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
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 std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id)
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...
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).
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...
StringRef - Represent a constant reference to a string, i.e.
ArgList - Ordered collection of driver arguments.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
unsigned getOptionGroupID(OptSpecifier id) const
Get the group id for the given option.
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
const char * getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.