LLVM  9.0.0svn
OptTable.cpp
Go to the documentation of this file.
1 //===- OptTable.cpp - Option Table Implementation -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ADT/STLExtras.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/ADT/StringSet.h"
12 #include "llvm/Option/Arg.h"
13 #include "llvm/Option/ArgList.h"
14 #include "llvm/Option/Option.h"
16 #include "llvm/Option/OptTable.h"
17 #include "llvm/Support/Compiler.h"
20 #include <algorithm>
21 #include <cassert>
22 #include <cctype>
23 #include <cstring>
24 #include <map>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 using namespace llvm;
30 using namespace llvm::opt;
31 
32 namespace llvm {
33 namespace opt {
34 
35 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
36 // with an exception. '\0' comes at the end of the alphabet instead of the
37 // beginning (thus options precede any other options which prefix them).
38 static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
39  const char *X = A, *Y = B;
40  char a = tolower(*A), b = tolower(*B);
41  while (a == b) {
42  if (a == '\0')
43  return 0;
44 
45  a = tolower(*++X);
46  b = tolower(*++Y);
47  }
48 
49  if (a == '\0') // A is a prefix of B.
50  return 1;
51  if (b == '\0') // B is a prefix of A.
52  return -1;
53 
54  // Otherwise lexicographic.
55  return (a < b) ? -1 : 1;
56 }
57 
58 #ifndef NDEBUG
59 static int StrCmpOptionName(const char *A, const char *B) {
60  if (int N = StrCmpOptionNameIgnoreCase(A, B))
61  return N;
62  return strcmp(A, B);
63 }
64 
65 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
66  if (&A == &B)
67  return false;
68 
69  if (int N = StrCmpOptionName(A.Name, B.Name))
70  return N < 0;
71 
72  for (const char * const *APre = A.Prefixes,
73  * const *BPre = B.Prefixes;
74  *APre != nullptr && *BPre != nullptr; ++APre, ++BPre){
75  if (int N = StrCmpOptionName(*APre, *BPre))
76  return N < 0;
77  }
78 
79  // Names are the same, check that classes are in order; exactly one
80  // should be joined, and it should succeed the other.
82  "Unexpected classes for options with same name.");
83  return B.Kind == Option::JoinedClass;
84 }
85 #endif
86 
87 // Support lower_bound between info and an option name.
88 static inline bool operator<(const OptTable::Info &I, const char *Name) {
89  return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
90 }
91 
92 } // end namespace opt
93 } // end namespace llvm
94 
95 OptSpecifier::OptSpecifier(const Option *Opt) : ID(Opt->getID()) {}
96 
97 OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
98  : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
99  // Explicitly zero initialize the error to work around a bug in array
100  // value-initialization on MinGW with gcc 4.3.5.
101 
102  // Find start of normal options.
103  for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
104  unsigned Kind = getInfo(i + 1).Kind;
105  if (Kind == Option::InputClass) {
106  assert(!TheInputOptionID && "Cannot have multiple input options!");
107  TheInputOptionID = getInfo(i + 1).ID;
108  } else if (Kind == Option::UnknownClass) {
109  assert(!TheUnknownOptionID && "Cannot have multiple unknown options!");
110  TheUnknownOptionID = getInfo(i + 1).ID;
111  } else if (Kind != Option::GroupClass) {
112  FirstSearchableIndex = i;
113  break;
114  }
115  }
116  assert(FirstSearchableIndex != 0 && "No searchable options?");
117 
118 #ifndef NDEBUG
119  // Check that everything after the first searchable option is a
120  // regular option class.
121  for (unsigned i = FirstSearchableIndex, e = getNumOptions(); i != e; ++i) {
123  assert((Kind != Option::InputClass && Kind != Option::UnknownClass &&
124  Kind != Option::GroupClass) &&
125  "Special options should be defined first!");
126  }
127 
128  // Check that options are in order.
129  for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions(); i != e; ++i){
130  if (!(getInfo(i) < getInfo(i + 1))) {
131  getOption(i).dump();
132  getOption(i + 1).dump();
133  llvm_unreachable("Options are not in order!");
134  }
135  }
136 #endif
137 
138  // Build prefixes.
139  for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions() + 1;
140  i != e; ++i) {
141  if (const char *const *P = getInfo(i).Prefixes) {
142  for (; *P != nullptr; ++P) {
143  PrefixesUnion.insert(*P);
144  }
145  }
146  }
147 
148  // Build prefix chars.
149  for (StringSet<>::const_iterator I = PrefixesUnion.begin(),
150  E = PrefixesUnion.end(); I != E; ++I) {
151  StringRef Prefix = I->getKey();
152  for (StringRef::const_iterator C = Prefix.begin(), CE = Prefix.end();
153  C != CE; ++C)
154  if (!is_contained(PrefixChars, *C))
155  PrefixChars.push_back(*C);
156  }
157 }
158 
159 OptTable::~OptTable() = default;
160 
162  unsigned id = Opt.getID();
163  if (id == 0)
164  return Option(nullptr, nullptr);
165  assert((unsigned) (id - 1) < getNumOptions() && "Invalid ID.");
166  return Option(&getInfo(id), this);
167 }
168 
169 static bool isInput(const StringSet<> &Prefixes, StringRef Arg) {
170  if (Arg == "-")
171  return true;
172  for (StringSet<>::const_iterator I = Prefixes.begin(),
173  E = Prefixes.end(); I != E; ++I)
174  if (Arg.startswith(I->getKey()))
175  return false;
176  return true;
177 }
178 
179 /// \returns Matched size. 0 means no match.
180 static unsigned matchOption(const OptTable::Info *I, StringRef Str,
181  bool IgnoreCase) {
182  for (const char * const *Pre = I->Prefixes; *Pre != nullptr; ++Pre) {
183  StringRef Prefix(*Pre);
184  if (Str.startswith(Prefix)) {
185  StringRef Rest = Str.substr(Prefix.size());
186  bool Matched = IgnoreCase
187  ? Rest.startswith_lower(I->Name)
188  : Rest.startswith(I->Name);
189  if (Matched)
190  return Prefix.size() + StringRef(I->Name).size();
191  }
192  }
193  return 0;
194 }
195 
196 // Returns true if one of the Prefixes + In.Names matches Option
198  if (In.Prefixes)
199  for (size_t I = 0; In.Prefixes[I]; I++)
200  if (Option == std::string(In.Prefixes[I]) + In.Name)
201  return true;
202  return false;
203 }
204 
205 // This function is for flag value completion.
206 // Eg. When "-stdlib=" and "l" was passed to this function, it will return
207 // appropiriate values for stdlib, which starts with l.
208 std::vector<std::string>
210  // Search all options and return possible values.
211  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
212  const Info &In = OptionInfos[I];
213  if (!In.Values || !optionMatches(In, Option))
214  continue;
215 
216  SmallVector<StringRef, 8> Candidates;
217  StringRef(In.Values).split(Candidates, ",", -1, false);
218 
219  std::vector<std::string> Result;
220  for (StringRef Val : Candidates)
221  if (Val.startswith(Arg) && Arg.compare(Val))
222  Result.push_back(Val);
223  return Result;
224  }
225  return {};
226 }
227 
228 std::vector<std::string>
229 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
230  std::vector<std::string> Ret;
231  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
232  const Info &In = OptionInfos[I];
233  if (!In.Prefixes || (!In.HelpText && !In.GroupID))
234  continue;
235  if (In.Flags & DisableFlags)
236  continue;
237 
238  for (int I = 0; In.Prefixes[I]; I++) {
239  std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t";
240  if (In.HelpText)
241  S += In.HelpText;
242  if (StringRef(S).startswith(Cur) && S.compare(std::string(Cur) + "\t"))
243  Ret.push_back(S);
244  }
245  }
246  return Ret;
247 }
248 
249 unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
250  unsigned FlagsToInclude, unsigned FlagsToExclude,
251  unsigned MinimumLength) const {
252  assert(!Option.empty());
253 
254  // Consider each option as a candidate, finding the closest match.
255  unsigned BestDistance = UINT_MAX;
256  for (const Info &CandidateInfo :
257  ArrayRef<Info>(OptionInfos).drop_front(FirstSearchableIndex)) {
258  StringRef CandidateName = CandidateInfo.Name;
259 
260  // Ignore option candidates with empty names, such as "--", or names
261  // that do not meet the minimum length.
262  if (CandidateName.empty() || CandidateName.size() < MinimumLength)
263  continue;
264 
265  // If FlagsToInclude were specified, ignore options that don't include
266  // those flags.
267  if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude))
268  continue;
269  // Ignore options that contain the FlagsToExclude.
270  if (CandidateInfo.Flags & FlagsToExclude)
271  continue;
272 
273  // Ignore positional argument option candidates (which do not
274  // have prefixes).
275  if (!CandidateInfo.Prefixes)
276  continue;
277  // Find the most appropriate prefix. For example, if a user asks for
278  // "--helm", suggest "--help" over "-help".
279  StringRef Prefix = CandidateInfo.Prefixes[0];
280  for (int P = 1; CandidateInfo.Prefixes[P]; P++) {
281  if (Option.startswith(CandidateInfo.Prefixes[P]))
282  Prefix = CandidateInfo.Prefixes[P];
283  }
284 
285  // Check if the candidate ends with a character commonly used when
286  // delimiting an option from its value, such as '=' or ':'. If it does,
287  // attempt to split the given option based on that delimiter.
288  std::string Delimiter = "";
289  char Last = CandidateName.back();
290  if (Last == '=' || Last == ':')
291  Delimiter = std::string(1, Last);
292 
293  StringRef LHS, RHS;
294  if (Delimiter.empty())
295  LHS = Option;
296  else
297  std::tie(LHS, RHS) = Option.split(Last);
298 
299  std::string NormalizedName =
300  (LHS.drop_front(Prefix.size()) + Delimiter).str();
301  unsigned Distance =
302  CandidateName.edit_distance(NormalizedName, /*AllowReplacements=*/true,
303  /*MaxEditDistance=*/BestDistance);
304  if (Distance < BestDistance) {
305  BestDistance = Distance;
306  NearestString = (Prefix + CandidateName + RHS).str();
307  }
308  }
309  return BestDistance;
310 }
311 
312 bool OptTable::addValues(const char *Option, const char *Values) {
313  for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
314  Info &In = OptionInfos[I];
315  if (optionMatches(In, Option)) {
316  In.Values = Values;
317  return true;
318  }
319  }
320  return false;
321 }
322 
324  unsigned FlagsToInclude,
325  unsigned FlagsToExclude) const {
326  unsigned Prev = Index;
327  const char *Str = Args.getArgString(Index);
328 
329  // Anything that doesn't start with PrefixesUnion is an input, as is '-'
330  // itself.
331  if (isInput(PrefixesUnion, Str))
332  return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
333 
334  const Info *Start = OptionInfos.data() + FirstSearchableIndex;
335  const Info *End = OptionInfos.data() + OptionInfos.size();
336  StringRef Name = StringRef(Str).ltrim(PrefixChars);
337 
338  // Search for the first next option which could be a prefix.
339  Start = std::lower_bound(Start, End, Name.data());
340 
341  // Options are stored in sorted order, with '\0' at the end of the
342  // alphabet. Since the only options which can accept a string must
343  // prefix it, we iteratively search for the next option which could
344  // be a prefix.
345  //
346  // FIXME: This is searching much more than necessary, but I am
347  // blanking on the simplest way to make it fast. We can solve this
348  // problem when we move to TableGen.
349  for (; Start != End; ++Start) {
350  unsigned ArgSize = 0;
351  // Scan for first option which is a proper prefix.
352  for (; Start != End; ++Start)
353  if ((ArgSize = matchOption(Start, Str, IgnoreCase)))
354  break;
355  if (Start == End)
356  break;
357 
358  Option Opt(Start, this);
359 
360  if (FlagsToInclude && !Opt.hasFlag(FlagsToInclude))
361  continue;
362  if (Opt.hasFlag(FlagsToExclude))
363  continue;
364 
365  // See if this option matches.
366  if (Arg *A = Opt.accept(Args, Index, ArgSize))
367  return A;
368 
369  // Otherwise, see if this argument was missing values.
370  if (Prev != Index)
371  return nullptr;
372  }
373 
374  // If we failed to find an option and this arg started with /, then it's
375  // probably an input path.
376  if (Str[0] == '/')
377  return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
378 
379  return new Arg(getOption(TheUnknownOptionID), Str, Index++, Str);
380 }
381 
383  unsigned &MissingArgIndex,
384  unsigned &MissingArgCount,
385  unsigned FlagsToInclude,
386  unsigned FlagsToExclude) const {
387  InputArgList Args(ArgArr.begin(), ArgArr.end());
388 
389  // FIXME: Handle '@' args (or at least error on them).
390 
391  MissingArgIndex = MissingArgCount = 0;
392  unsigned Index = 0, End = ArgArr.size();
393  while (Index < End) {
394  // Ingore nullptrs, they are response file's EOL markers
395  if (Args.getArgString(Index) == nullptr) {
396  ++Index;
397  continue;
398  }
399  // Ignore empty arguments (other things may still take them as arguments).
400  StringRef Str = Args.getArgString(Index);
401  if (Str == "") {
402  ++Index;
403  continue;
404  }
405 
406  unsigned Prev = Index;
407  Arg *A = ParseOneArg(Args, Index, FlagsToInclude, FlagsToExclude);
408  assert(Index > Prev && "Parser failed to consume argument.");
409 
410  // Check for missing argument error.
411  if (!A) {
412  assert(Index >= End && "Unexpected parser error.");
413  assert(Index - Prev - 1 && "No missing arguments!");
414  MissingArgIndex = Prev;
415  MissingArgCount = Index - Prev - 1;
416  break;
417  }
418 
419  Args.append(A);
420  }
421 
422  return Args;
423 }
424 
425 static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) {
426  const Option O = Opts.getOption(Id);
427  std::string Name = O.getPrefixedName();
428 
429  // Add metavar, if used.
430  switch (O.getKind()) {
432  llvm_unreachable("Invalid option with help text.");
433 
435  if (const char *MetaVarName = Opts.getOptionMetaVar(Id)) {
436  // For MultiArgs, metavar is full list of all argument names.
437  Name += ' ';
438  Name += MetaVarName;
439  }
440  else {
441  // For MultiArgs<N>, if metavar not supplied, print <value> N times.
442  for (unsigned i=0, e=O.getNumArgs(); i< e; ++i) {
443  Name += " <value>";
444  }
445  }
446  break;
447 
448  case Option::FlagClass:
449  break;
450 
451  case Option::ValuesClass:
452  break;
453 
456  Name += ' ';
460  if (const char *MetaVarName = Opts.getOptionMetaVar(Id))
461  Name += MetaVarName;
462  else
463  Name += "<value>";
464  break;
465  }
466 
467  return Name;
468 }
469 
470 namespace {
471 struct OptionInfo {
472  std::string Name;
473  StringRef HelpText;
474 };
475 } // namespace
476 
478  std::vector<OptionInfo> &OptionHelp) {
479  OS << Title << ":\n";
480 
481  // Find the maximum option length.
482  unsigned OptionFieldWidth = 0;
483  for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
484  // Limit the amount of padding we are willing to give up for alignment.
485  unsigned Length = OptionHelp[i].Name.size();
486  if (Length <= 23)
487  OptionFieldWidth = std::max(OptionFieldWidth, Length);
488  }
489 
490  const unsigned InitialPad = 2;
491  for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
492  const std::string &Option = OptionHelp[i].Name;
493  int Pad = OptionFieldWidth - int(Option.size());
494  OS.indent(InitialPad) << Option;
495 
496  // Break on long option names.
497  if (Pad < 0) {
498  OS << "\n";
499  Pad = OptionFieldWidth + InitialPad;
500  }
501  OS.indent(Pad + 1) << OptionHelp[i].HelpText << '\n';
502  }
503 }
504 
505 static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) {
506  unsigned GroupID = Opts.getOptionGroupID(Id);
507 
508  // If not in a group, return the default help group.
509  if (!GroupID)
510  return "OPTIONS";
511 
512  // Abuse the help text of the option groups to store the "help group"
513  // name.
514  //
515  // FIXME: Split out option groups.
516  if (const char *GroupHelp = Opts.getOptionHelpText(GroupID))
517  return GroupHelp;
518 
519  // Otherwise keep looking.
520  return getOptionHelpGroup(Opts, GroupID);
521 }
522 
523 void OptTable::PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
524  bool ShowHidden, bool ShowAllAliases) const {
525  PrintHelp(OS, Usage, Title, /*Include*/ 0, /*Exclude*/
526  (ShowHidden ? 0 : HelpHidden), ShowAllAliases);
527 }
528 
529 void OptTable::PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
530  unsigned FlagsToInclude, unsigned FlagsToExclude,
531  bool ShowAllAliases) const {
532  OS << "OVERVIEW: " << Title << "\n\n";
533  OS << "USAGE: " << Usage << "\n\n";
534 
535  // Render help text into a map of group-name to a list of (option, help)
536  // pairs.
537  std::map<std::string, std::vector<OptionInfo>> GroupedOptionHelp;
538 
539  for (unsigned Id = 1, e = getNumOptions() + 1; Id != e; ++Id) {
540  // FIXME: Split out option groups.
542  continue;
543 
544  unsigned Flags = getInfo(Id).Flags;
545  if (FlagsToInclude && !(Flags & FlagsToInclude))
546  continue;
547  if (Flags & FlagsToExclude)
548  continue;
549 
550  // If an alias doesn't have a help text, show a help text for the aliased
551  // option instead.
552  const char *HelpText = getOptionHelpText(Id);
553  if (!HelpText && ShowAllAliases) {
554  const Option Alias = getOption(Id).getAlias();
555  if (Alias.isValid())
556  HelpText = getOptionHelpText(Alias.getID());
557  }
558 
559  if (HelpText) {
560  const char *HelpGroup = getOptionHelpGroup(*this, Id);
561  const std::string &OptName = getOptionHelpName(*this, Id);
562  GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
563  }
564  }
565 
566  for (auto& OptionGroup : GroupedOptionHelp) {
567  if (OptionGroup.first != GroupedOptionHelp.begin()->first)
568  OS << "\n";
569  PrintHelpOptionList(OS, OptionGroup.first, OptionGroup.second);
570  }
571 
572  OS.flush();
573 }
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...
Definition: STLExtras.h:1281
uint64_t CallInst * C
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.
Definition: StringRef.cpp:46
unsigned getNumOptions() const
Return the total number of option classes.
Definition: OptTable.h:89
unsigned short GroupID
Definition: OptTable.h:52
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
unsigned short Flags
Definition: OptTable.h:51
This class represents lattice values for constants.
Definition: AllocatorList.h:23
std::string getPrefixedName() const
Get the name of this option with the default prefix.
Definition: Option.h:132
static bool operator<(const OptTable::Info &A, const OptTable::Info &B)
Definition: OptTable.cpp:65
iterator begin() const
Definition: ArrayRef.h:136
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.
Definition: StringRef.h:256
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...
Definition: StringRef.h:174
static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase)
Definition: OptTable.cpp:180
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.
Definition: OptTable.cpp:382
unsigned getOptionGroupID(OptSpecifier id) const
Get the group id for the given option.
Definition: OptTable.h:108
void dump() const
Definition: Option.cpp:90
raw_ostream & indent(unsigned NumSpaces)
indent - Insert &#39;NumSpaces&#39; spaces.
LLVM_NODISCARD StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
Definition: StringRef.h:789
LLVM_NODISCARD unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
Definition: StringRef.cpp:94
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.
Definition: OptTable.cpp:229
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to &#39;this&#39; but with the first N elements dropped.
Definition: StringRef.h:620
unsigned getID() const
Definition: OptSpecifier.h:29
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.
Definition: OptTable.cpp:323
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:578
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
static bool startswith(StringRef Magic, const char(&S)[N])
Definition: Magic.cpp:29
static int getID(struct InternalInstruction *insn, const void *miiArg)
static bool optionMatches(const OptTable::Info &In, StringRef Option)
Definition: OptTable.cpp:197
unsigned char Kind
Definition: OptTable.h:49
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
OptTable(ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
Definition: OptTable.cpp:97
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
static const char * getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id)
Definition: OptTable.cpp:505
OptionClass getKind() const
Definition: Option.h:92
#define P(N)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Option - Abstract representation for a single form of driver argument.
Definition: Option.h:51
Definition: Arg.h:26
A concrete instance of a particular driver option.
Definition: Arg.h:34
Provide access to the Option info table.
Definition: OptTable.h:38
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
bool hasFlag(unsigned Val) const
Test if this option has the flag Val.
Definition: Option.h:170
const char * HelpText
Definition: OptTable.h:46
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.
Definition: OptTable.h:44
const Option getOption(OptSpecifier Opt) const
Get the given Opt&#39;s Option instance, lazily creating it if necessary.
Definition: OptTable.cpp:161
bool isValid() const
Definition: Option.h:83
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static int StrCmpOptionName(const char *A, const char *B)
Definition: OptTable.cpp:59
const char * Values
Definition: OptTable.h:55
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Definition: StringRef.h:141
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:38
const Option getAlias() const
Definition: Option.h:109
std::vector< std::string > suggestValueCompletions(StringRef Option, StringRef Arg) const
Find possible value for given flags.
Definition: OptTable.cpp:209
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.
Definition: OptTable.cpp:249
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)
Definition: OptTable.cpp:477
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:841
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:696
static int StrCmpOptionNameIgnoreCase(const char *A, const char *B)
Definition: OptTable.cpp:38
iterator end() const
Definition: ArrayRef.h:137
unsigned getNumArgs() const
Definition: Option.h:138
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
Definition: OptTable.h:103
Defines the llvm::Arg class for parsed arguments.
iterator begin() const
Definition: StringRef.h:101
OptSpecifier - Wrapper class for abstracting references to option IDs.
Definition: OptSpecifier.h:18
iterator begin()
Definition: StringMap.h:314
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:187
Entry for a single option instance in the option data table.
Definition: OptTable.h:41
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
bool addValues(const char *Option, const char *Values)
Add Values to Option&#39;s Values class.
Definition: OptTable.cpp:312
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
Definition: OptTable.h:113
static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id)
Definition: OptTable.cpp:425
const char * getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text...
Definition: OptTable.h:119
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:122
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getID() const
Definition: Option.h:87
static bool isInput(const StringSet<> &Prefixes, StringRef Arg)
Definition: OptTable.cpp:169
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:250
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:27
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
hexagon cext opt
ArgList - Ordered collection of driver arguments.
Definition: ArgList.h:116
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.
Definition: OptTable.cpp:529
iterator end() const
Definition: StringRef.h:103
iterator end()
Definition: StringMap.h:317
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.
Definition: STLExtras.h:1244
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...
Definition: Option.cpp:109