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 != 0 && *BPre != 0; ++APre, ++BPre) {
73 "Unexpected classes for options with same name.");
89 : OptionInfos(_OptionInfos),
90 NumOptionInfos(_NumOptionInfos),
91 IgnoreCase(_IgnoreCase),
93 TheUnknownOptionID(0),
94 FirstSearchableIndex(0)
101 unsigned Kind = getInfo(i + 1).
Kind;
103 assert(!TheInputOptionID &&
"Cannot have multiple input options!");
104 TheInputOptionID = getInfo(i + 1).
ID;
106 assert(!TheUnknownOptionID &&
"Cannot have multiple unknown options!");
107 TheUnknownOptionID = getInfo(i + 1).
ID;
109 FirstSearchableIndex = i;
113 assert(FirstSearchableIndex != 0 &&
"No searchable options?");
118 for (
unsigned i = FirstSearchableIndex, e =
getNumOptions(); i != e; ++i) {
122 "Special options should be defined first!");
126 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions(); i != e; ++i){
127 if (!(getInfo(i) < getInfo(i + 1))) {
136 for (
unsigned i = FirstSearchableIndex + 1, e =
getNumOptions() + 1;
138 if (
const char *
const *
P = getInfo(i).Prefixes) {
139 for (; *
P != 0; ++
P) {
147 E = PrefixesUnion.
end();
I != E; ++
I) {
151 if (std::find(PrefixChars.begin(), PrefixChars.end(), *
C)
152 == PrefixChars.end())
153 PrefixChars.push_back(*
C);
161 unsigned id = Opt.
getID();
164 assert((
unsigned) (
id - 1) <
getNumOptions() &&
"Invalid ID.");
165 return Option(&getInfo(
id),
this);
172 E = Prefixes.
end();
I != E; ++
I)
181 for (
const char *
const *Pre = I->
Prefixes; *Pre != 0; ++Pre) {
185 bool Matched = IgnoreCase
196 unsigned FlagsToInclude,
197 unsigned FlagsToExclude)
const {
198 unsigned Prev = Index;
203 if (
isInput(PrefixesUnion, Str))
204 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
206 const Info *Start = OptionInfos + FirstSearchableIndex;
211 Start = std::lower_bound(Start, End, Name.
data());
221 for (; Start != End; ++Start) {
222 unsigned ArgSize = 0;
224 for (; Start != End; ++Start)
225 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
232 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
234 if (Opt.
hasFlag(FlagsToExclude))
238 if (
Arg *
A = Opt.
accept(Args, Index, ArgSize))
249 return new Arg(
getOption(TheInputOptionID), Str, Index++, Str);
251 return new Arg(
getOption(TheUnknownOptionID), Str, Index++, Str);
255 const char *
const *ArgEnd,
256 unsigned &MissingArgIndex,
257 unsigned &MissingArgCount,
258 unsigned FlagsToInclude,
259 unsigned FlagsToExclude)
const {
264 MissingArgIndex = MissingArgCount = 0;
265 unsigned Index = 0, End = ArgEnd - ArgBegin;
266 while (Index < End) {
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;
325 std::vector<std::pair<std::string,
326 const char*> > &OptionHelp) {
327 OS << Title <<
":\n";
330 unsigned OptionFieldWidth = 0;
331 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
333 if (!OptionHelp[i].second)
337 unsigned Length = OptionHelp[i].first.
size();
339 OptionFieldWidth = std::max(OptionFieldWidth, Length);
342 const unsigned InitialPad = 2;
343 for (
unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
344 const std::string &
Option = OptionHelp[i].first;
345 int Pad = OptionFieldWidth - int(Option.size());
346 OS.
indent(InitialPad) << Option;
351 Pad = OptionFieldWidth + InitialPad;
353 OS.
indent(Pad + 1) << OptionHelp[i].second <<
'\n';
376 bool ShowHidden)
const {
383 unsigned FlagsToInclude,
384 unsigned FlagsToExclude)
const {
385 OS <<
"OVERVIEW: " << Title <<
"\n";
387 OS <<
"USAGE: " << Name <<
" [options] <inputs>\n";
392 typedef std::map<std::string,
393 std::vector<std::pair<std::string, const char*> > > helpmap_ty;
394 helpmap_ty GroupedOptionHelp;
404 if (FlagsToInclude && !(Flags & FlagsToInclude))
406 if (Flags & FlagsToExclude)
412 GroupedOptionHelp[HelpGroup].push_back(std::make_pair(OptName, Text));
416 for (helpmap_ty::iterator it = GroupedOptionHelp .
begin(),
417 ie = GroupedOptionHelp.
end(); it != ie; ++it) {
418 if (it != GroupedOptionHelp .
begin())
int strcmp(const char *s1, const char *s2);
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
const_iterator begin(StringRef path)
Get begin iterator over path.
OptionClass getKind() const
static bool isInput(const llvm::StringSet<> &Prefixes, StringRef Arg)
#define llvm_unreachable(msg)
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
ID
LLVM Calling Convention Representation.
const char * data() const
InputArgList * ParseArgs(const char *const *ArgBegin, const char *const *ArgEnd, unsigned &MissingArgIndex, unsigned &MissingArgCount, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const
Parse an list of arguments into an InputArgList.
static const char * getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id)
bool insert(StringRef Key)
friend const_iterator end(StringRef path)
Get end iterator over path.
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
static int StrCmpOptionName(const char *A, const char *B)
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)
static int getID(struct InternalInstruction *insn, const void *miiArg)
OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos, bool _IgnoreCase=false)
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.
void append(Arg *A)
append - Append A to the arg list.
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)
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.
Arg * accept(const ArgList &Args, unsigned &Index, unsigned ArgSize) const
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.
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
StringRef ltrim(StringRef Chars=" \t\n\v\f\r") const
const char * getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text...