22 using namespace llvm::opt;
31 const char *
X =
A, *
Y =
B;
32 char a = tolower(*A), b = tolower(*B);
47 return (a < b) ? -1 : 1;
64 for (
const char *
const *APre = A.
Prefixes,
66 *APre !=
nullptr && *BPre !=
nullptr; ++APre, ++BPre){
74 "Unexpected classes for options with same name.");
89 : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase), TheInputOptionID(0),
90 TheUnknownOptionID(0), FirstSearchableIndex(0) {
98 assert(!TheInputOptionID &&
"Cannot have multiple input options!");
99 TheInputOptionID = getInfo(
i + 1).
ID;
101 assert(!TheUnknownOptionID &&
"Cannot have multiple unknown options!");
102 TheUnknownOptionID = getInfo(
i + 1).
ID;
104 FirstSearchableIndex =
i;
108 assert(FirstSearchableIndex != 0 &&
"No searchable options?");
117 "Special options should be defined first!");
121 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions();
i != e; ++
i){
122 if (!(getInfo(
i) < getInfo(
i + 1))) {
131 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions() + 1;
133 if (
const char *
const *
P = getInfo(
i).Prefixes) {
134 for (; *
P !=
nullptr; ++
P) {
142 E = PrefixesUnion.
end();
I !=
E; ++
I) {
147 PrefixChars.push_back(*
C);
155 unsigned id = Opt.
getID();
157 return Option(
nullptr,
nullptr);
159 return Option(&getInfo(
id),
this);
166 E = Prefixes.
end();
I !=
E; ++
I)
175 for (
const char *
const *Pre = I->
Prefixes; *Pre !=
nullptr; ++Pre) {
179 bool Matched = IgnoreCase
190 unsigned FlagsToInclude,
191 unsigned FlagsToExclude)
const {
192 unsigned Prev = Index;
197 if (
isInput(PrefixesUnion, Str))
198 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
200 const Info *Start = OptionInfos.begin() + FirstSearchableIndex;
201 const Info *
End = OptionInfos.end();
205 Start = std::lower_bound(Start, End, Name.
data());
215 for (; Start !=
End; ++Start) {
218 for (; Start !=
End; ++Start)
219 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
226 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
228 if (Opt.
hasFlag(FlagsToExclude))
232 if (
Arg *
A = Opt.
accept(Args, Index, ArgSize))
243 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
245 return new Arg(
getOption(TheUnknownOptionID), Str, Index++, Str);
249 unsigned &MissingArgIndex,
250 unsigned &MissingArgCount,
251 unsigned FlagsToInclude,
252 unsigned FlagsToExclude)
const {
257 MissingArgIndex = MissingArgCount = 0;
258 unsigned Index = 0,
End = ArgArr.
size();
259 while (Index <
End) {
261 if (
Args.getArgString(Index) ==
nullptr) {
272 unsigned Prev = Index;
274 assert(Index > Prev &&
"Parser failed to consume argument.");
278 assert(Index >=
End &&
"Unexpected parser error.");
279 assert(Index - Prev - 1 &&
"No missing arguments!");
280 MissingArgIndex = Prev;
281 MissingArgCount = Index - Prev - 1;
334 std::vector<std::pair<std::string,
335 const char*> > &OptionHelp) {
336 OS << Title <<
":\n";
339 unsigned OptionFieldWidth = 0;
340 for (
unsigned i = 0, e = OptionHelp.size();
i != e; ++
i) {
342 if (!OptionHelp[
i].second)
346 unsigned Length = OptionHelp[
i].first.
size();
348 OptionFieldWidth = std::max(OptionFieldWidth, Length);
351 const unsigned InitialPad = 2;
352 for (
unsigned i = 0, e = OptionHelp.size();
i != e; ++
i) {
353 const std::string &
Option = OptionHelp[
i].first;
354 int Pad = OptionFieldWidth - int(Option.size());
355 OS.
indent(InitialPad) << Option;
360 Pad = OptionFieldWidth + InitialPad;
362 OS.
indent(Pad + 1) << OptionHelp[
i].second <<
'\n';
385 bool ShowHidden)
const {
392 unsigned FlagsToInclude,
393 unsigned FlagsToExclude)
const {
394 OS <<
"OVERVIEW: " << Title <<
"\n";
396 OS <<
"USAGE: " << Name <<
" [options] <inputs>\n";
401 typedef std::map<std::string,
402 std::vector<std::pair<std::string, const char*> > > helpmap_ty;
403 helpmap_ty GroupedOptionHelp;
413 if (FlagsToInclude && !(Flags & FlagsToInclude))
415 if (Flags & FlagsToExclude)
421 GroupedOptionHelp[HelpGroup].push_back(std::make_pair(OptName, Text));
425 for (helpmap_ty::iterator it = GroupedOptionHelp .
begin(),
426 ie = GroupedOptionHelp.
end(); it != ie; ++it) {
427 if (it != GroupedOptionHelp .
begin())
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.
const_iterator begin(StringRef path)
Get begin iterator over path.
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
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with strcmp
static bool isInput(const llvm::StringSet<> &Prefixes, StringRef Arg)
struct fuzzer::@269 Flags
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
static int getID(struct InternalInstruction *insn, const void *miiArg)
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)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
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)
#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 char * const_iterator
virtual const char * getArgString(unsigned Index) const =0
getArgString - Return the input argument string at Index.
static int StrCmpOptionNameIgnoreCase(const char *A, const char *B)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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.
Defines the llvm::Arg class for parsed arguments.
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
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 void PrintHelpOptionList(raw_ostream &OS, StringRef Title, std::vector< std::pair< std::string, const char * > > &OptionHelp)
#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.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
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.