9#ifndef LLVM_OPTION_OPTTABLE_H
10#define LLVM_OPTION_OPTTABLE_H
128 Prefixes.
push_back(StrTable[PrefixOffset]);
133 unsigned PrefixIndex)
const {
143 unsigned PrefixLength =
164 "This helper is only for valid registered subcommands.");
166 SubCommands, [&](
const auto &
C) {
return SubCommand ==
C.Name; });
167 assert(SCIT != SubCommands.end() &&
168 "This helper is only for valid registered subcommands.");
169 auto SubCommandIDs = getSubCommandIDs(*CandidateInfo);
170 unsigned CurrentSubCommandID = SCIT - &SubCommands[0];
200 ValuesCodeFnTy ValuesCodeFn =
nullptr;
202 bool GroupedShortOptions =
false;
203 bool DashDashParsing =
false;
204 const char *EnvVar =
nullptr;
206 unsigned InputOptionID = 0;
207 unsigned UnknownOptionID = 0;
211 unsigned FirstSearchableIndex = 0;
221 unsigned id = Opt.
getID();
222 assert(
id > 0 &&
id - 1 < getNumOptions() &&
"Invalid Option ID.");
223 return OptionInfos[
id - 1];
226 const InfoExtra &getExtra(
const Info &
I)
const {
227 return InfoExtrasTable[
I.ExtraOffset];
230 StringTable::Offset getHelpTextOffset(
const Info &
I,
231 Visibility VisibilityMask)
const {
232 for (
const HelpTextVariant *V =
233 &HelpTextVariantsTable[getExtra(
I).HelpTextVariantsOffset];
235 if (VisibilityMask & V->Visibility)
236 return V->HelpTextOffset;
237 return I.HelpTextOffset;
240 StringRef getOptionValues(
const Info &
I)
const {
241 StringRef
Values = StrTable[getExtra(
I).ValuesOffset];
242 if (
Values.empty() && ValuesCodeFn)
243 Values = ValuesCodeFn(getOptionID(
I));
247 ArrayRef<unsigned> getSubCommandIDs(
const Info &
I)
const {
249 unsigned Offset = getExtra(
I).SubCommandIDsOffset;
250 return SubCommandIDsTable.
slice(Offset + 1, SubCommandIDsTable[Offset]);
253 std::unique_ptr<Arg> parseOneArgGrouped(InputArgList &Args,
254 unsigned &Index)
const;
257 OptTable(
const Tables &Tables,
bool IgnoreCase =
false);
271 return PrefixesTable;
278 return &
I - OptionInfos.data() + 1;
289 return getInfo(
id).getName(StrTable, PrefixesTable);
294 const Info &
I = getInfo(
id);
296 :
I.getPrefix(StrTable, PrefixesTable, 0);
301 const Info &
I = getInfo(
id);
302 I.appendPrefixes(StrTable, PrefixesTable, Prefixes);
307 return getInfo(
id).getPrefixedName(StrTable);
312 return getInfo(
id).Kind;
317 return getInfo(
id).GroupID;
330 return StrTable[getHelpTextOffset(getInfo(
id), VisibilityMask)];
336 return StrTable[getExtra(getInfo(
id)).MetaVarOffset];
341 return StrTable.getCString(getExtra(getInfo(
id)).AliasArgsOffset);
373 std::vector<std::string> findByPrefix(
StringRef Cur,
375 unsigned int DisableFlags)
const;
395 unsigned MinimumLength = 4,
396 unsigned MaximumDistance = UINT_MAX)
const;
399 unsigned FlagsToInclude,
unsigned FlagsToExclude = 0,
400 unsigned MinimumLength = 4,
401 unsigned MaximumDistance = UINT_MAX)
const;
406 unsigned MinimumLength,
unsigned MaximumDistance,
407 std::function<
bool(
const Info &)> ExcludeOption)
const;
416 unsigned FlagsToInclude,
unsigned FlagsToExclude = 0)
const {
434 ParseOneArg(
const ArgList &Args,
unsigned &Index,
437 std::unique_ptr<Arg> ParseOneArg(
const ArgList &Args,
unsigned &Index,
438 unsigned FlagsToInclude,
439 unsigned FlagsToExclude)
const;
443 internalParseOneArg(
const ArgList &Args,
unsigned &Index,
444 std::function<
bool(
const Option &)> ExcludeOption)
const;
464 unsigned &MissingArgCount,
468 unsigned &MissingArgCount,
unsigned FlagsToInclude,
469 unsigned FlagsToExclude = 0)
const;
474 unsigned &MissingArgCount,
475 std::function<
bool(
const Option &)> ExcludeOption)
const;
488 std::function<
void(
StringRef)> ErrorFn)
const;
502 void printHelp(
raw_ostream &OS,
const char *Usage,
const char *Title,
503 bool ShowHidden =
false,
bool ShowAllAliases =
false,
507 void printHelp(
raw_ostream &OS,
const char *Usage,
const char *Title,
508 unsigned FlagsToInclude,
unsigned FlagsToExclude,
509 bool ShowAllAliases)
const;
512 void internalPrintHelp(
raw_ostream &OS,
const char *Usage,
const char *Title,
515 std::function<
bool(
const Info &)> ExcludeOption,
516 Visibility VisibilityMask)
const;
523#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
524 ID_PREFIX, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
525 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
526 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
529#define LLVM_MAKE_OPT_ID(PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, \
530 GROUP, ALIAS, ALIASARGS, FLAGS, VISIBILITY, PARAM, \
531 HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, \
532 SUBCOMMANDIDS_OFFSET) \
533 LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
534 OPT_, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
535 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
536 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static Expected< size_t > parseArgs(StringRef Section, mcdxbc::SourceInfo::ProgramArgs &Args)
This file defines the SmallString class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
A table of densely packed, null-terminated strings indexed by offset.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
ArgList - Ordered collection of driver arguments.
A concrete instance of a particular driver option.
OptSpecifier - Wrapper class for abstracting references to option IDs.
bool isValidForSubCommand(const Info *CandidateInfo, StringRef SubCommand) const
StringRef getOptionName(OptSpecifier id) const
Lookup the name of the given option.
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
unsigned findNearest(StringRef Option, std::string &NearestString, Visibility VisibilityMask=Visibility(), unsigned MinimumLength=4, unsigned MaximumDistance=UINT_MAX) const
Find the OptTable option that most closely matches the given string.
StringRef getOptionPrefix(OptSpecifier id) const
Lookup the prefix of the given option.
bool findExact(StringRef Option, std::string &ExactString, unsigned FlagsToInclude, unsigned FlagsToExclude=0) const
void setInitialOptionsFromEnvironment(const char *E)
Specify the environment variable where initial options should be read.
void setDashDashParsing(bool Value)
Set whether "--" stops option parsing and treats all subsequent arguments as positional.
StringRef getOptionHelpText(OptSpecifier id, Visibility VisibilityMask) const
StringRef(*)(unsigned) ValuesCodeFnTy
Values of options declared with TableGen ValuesCode: only the generated code knows them,...
const char * getOptionAliasArgs(OptSpecifier id) const
Get the alias arguments as a \0 separated list, e.g. "foo\0bar\0".
void setValuesCodeFn(ValuesCodeFnTy Fn)
unsigned getOptionGroupID(OptSpecifier id) const
Get the group id for the given option.
StringRef getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text.
OptTable(const Tables &Tables, bool IgnoreCase=false)
StringRef getOptionPrefixedName(OptSpecifier id) const
Lookup the prefixed name of the given option.
ArrayRef< StringTable::Offset > getPrefixesTable() const
Return the prefixes table used for option names.
void appendOptionPrefixes(OptSpecifier id, SmallVectorImpl< StringRef > &Prefixes) const
unsigned getOptionID(const Info &I) const
unsigned getNumOptions() const
Return the total number of option classes.
bool findExact(StringRef Option, std::string &ExactString, Visibility VisibilityMask=Visibility()) const
StringRef getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
ArrayRef< SubCommand > getSubCommands() const
const StringTable & getStrTable() const
Return the string table used for option names.
void setGroupedShortOptions(bool Value)
Support grouped short options. e.g. -ab represents -a -b.
Option - Abstract representation for a single form of driver argument.
Helper for overload resolution while transitioning from FlagsToInclude/FlagsToExclude APIs to Visibil...
Visibility(unsigned Mask)
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
@ Unknown
Not known to have no common set bits.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Help text that replaces Info::HelpTextOffset when the visibility mask being printed intersects Visibi...
StringTable::Offset HelpTextOffset
Entry for a single option instance in the option data table.
unsigned short ExtraOffset
void appendPrefixes(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, SmallVectorImpl< StringRef > &Prefixes) const
StringTable::Offset PrefixedNameOffset
unsigned getNumPrefixes(ArrayRef< StringTable::Offset > PrefixesTable) const
StringRef getPrefixedName(const StringTable &StrTable) const
ArrayRef< StringTable::Offset > getPrefixOffsets(ArrayRef< StringTable::Offset > PrefixesTable) const
StringTable::Offset HelpTextOffset
Offset 0 means the .td supplied no HelpText.
StringRef getPrefix(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, unsigned PrefixIndex) const
unsigned short PrefixesOffset
StringRef getName(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable) const
unsigned short Visibility
Represents a subcommand and its options in the option table.
The tables TableGen emits for an option set under OPTTABLE_CODE.
ArrayRef< unsigned > SubCommandIDs
ArrayRef< InfoExtra > InfoExtras
ArrayRef< SubCommand > SubCommands
ArrayRef< HelpTextVariant > HelpTextVariants
ArrayRef< StringTable::Offset > PrefixesTable