21 using namespace llvm::opt;
30 const char *
X =
A, *
Y = B;
31 char a = tolower(*A), b = tolower(*B);
46 return (a < b) ? -1 : 1;
63 for (
const char *
const *APre = A.
Prefixes,
65 *APre !=
nullptr && *BPre !=
nullptr; ++APre, ++BPre){
73 "Unexpected classes for options with same name.");
89 : OptionInfos(OptionInfos), NumOptionInfos(NumOptionInfos),
90 IgnoreCase(IgnoreCase), TheInputOptionID(0), TheUnknownOptionID(0),
91 FirstSearchableIndex(0) {
99 assert(!TheInputOptionID &&
"Cannot have multiple input options!");
100 TheInputOptionID = getInfo(i + 1).
ID;
102 assert(!TheUnknownOptionID &&
"Cannot have multiple unknown options!");
103 TheUnknownOptionID = getInfo(i + 1).
ID;
105 FirstSearchableIndex = i;
109 assert(FirstSearchableIndex != 0 &&
"No searchable options?");
114 for (
unsigned i = FirstSearchableIndex, e =
getNumOptions(); i != e; ++i) {
118 "Special options should be defined first!");
122 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions(); i != e; ++i){
123 if (!(getInfo(i) < getInfo(i + 1))) {
132 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions() + 1;
134 if (
const char *
const *
P = getInfo(i).Prefixes) {
135 for (; *
P !=
nullptr; ++
P) {
143 E = PrefixesUnion.
end();
I != E; ++
I) {
147 if (std::find(PrefixChars.begin(), PrefixChars.end(), *C)
148 == PrefixChars.end())
149 PrefixChars.push_back(*C);
157 unsigned id = Opt.
getID();
159 return Option(
nullptr,
nullptr);
160 assert((
unsigned) (
id - 1) <
getNumOptions() &&
"Invalid ID.");
161 return Option(&getInfo(
id),
this);
168 E = Prefixes.
end();
I != E; ++
I)
177 for (
const char *
const *Pre = I->
Prefixes; *Pre !=
nullptr; ++Pre) {
181 bool Matched = IgnoreCase
192 unsigned FlagsToInclude,
193 unsigned FlagsToExclude)
const {
194 unsigned Prev = Index;
199 if (
isInput(PrefixesUnion, Str))
200 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
202 const Info *Start = OptionInfos + FirstSearchableIndex;
207 Start = std::lower_bound(Start, End, Name.
data());
217 for (; Start != End; ++Start) {
218 unsigned ArgSize = 0;
220 for (; Start != End; ++Start)
221 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
228 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
230 if (Opt.
hasFlag(FlagsToExclude))
234 if (
Arg *
A = Opt.
accept(Args, Index, ArgSize))
245 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
247 return new Arg(
getOption(TheUnknownOptionID), Str, Index++, Str);
251 unsigned &MissingArgIndex,
252 unsigned &MissingArgCount,
253 unsigned FlagsToInclude,
254 unsigned FlagsToExclude)
const {
259 MissingArgIndex = MissingArgCount = 0;
260 unsigned Index = 0, End = ArgArr.
size();
261 while (Index < End) {
263 if (Args.getArgString(Index) ==
nullptr) {
268 StringRef Str = Args.getArgString(Index);
274 unsigned Prev = Index;
276 assert(Index > Prev &&
"Parser failed to consume argument.");
280 assert(Index >= End &&
"Unexpected parser error.");
281 assert(Index - Prev - 1 &&
"No missing arguments!");
282 MissingArgIndex = Prev;
283 MissingArgCount = Index - Prev - 1;
310 for (
unsigned i=0, e=O.
getNumArgs(); i< e; ++i) {
336 std::vector<std::pair<std::string,
337 const char*> > &OptionHelp) {
338 OS << Title <<
":\n";
341 unsigned OptionFieldWidth = 0;
342 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
344 if (!OptionHelp[i].second)
348 unsigned Length = OptionHelp[i].first.
size();
350 OptionFieldWidth = std::max(OptionFieldWidth, Length);
353 const unsigned InitialPad = 2;
354 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
355 const std::string &
Option = OptionHelp[i].first;
356 int Pad = OptionFieldWidth -
int(Option.size());
357 OS.
indent(InitialPad) << Option;
362 Pad = OptionFieldWidth + InitialPad;
364 OS.
indent(Pad + 1) << OptionHelp[i].second <<
'\n';
387 bool ShowHidden)
const {
394 unsigned FlagsToInclude,
395 unsigned FlagsToExclude)
const {
396 OS <<
"OVERVIEW: " << Title <<
"\n";
398 OS <<
"USAGE: " << Name <<
" [options] <inputs>\n";
403 typedef std::map<std::string,
404 std::vector<std::pair<std::string, const char*> > > helpmap_ty;
405 helpmap_ty GroupedOptionHelp;
415 if (FlagsToInclude && !(Flags & FlagsToInclude))
417 if (Flags & FlagsToExclude)
423 GroupedOptionHelp[HelpGroup].push_back(std::make_pair(OptName, Text));
427 for (helpmap_ty::iterator it = GroupedOptionHelp .
begin(),
428 ie = GroupedOptionHelp.
end(); it != ie; ++it) {
429 if (it != GroupedOptionHelp .
begin())
size_t size() const
size - Get the string size.
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.
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
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
static bool isInput(const llvm::StringSet<> &Prefixes, StringRef Arg)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
OptTable(const Info *OptionInfos, unsigned NumOptionInfos, bool IgnoreCase=false)
static int getID(struct InternalInstruction *insn, const void *miiArg)
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
unsigned getNumArgs() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
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.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static int StrCmpOptionName(const char *A, const char *B)
std::pair< typename base::iterator, bool > insert(StringRef Key)
const char * const_iterator
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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)
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.
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)
const ARM::ArchExtKind Kind
static void PrintHelpOptionList(raw_ostream &OS, StringRef Title, std::vector< std::pair< std::string, const char * > > &OptionHelp)
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...
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.
bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
StringRef ltrim(StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left removed.
const char * getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text...