LLVM 24.0.0git
OptTable.h
Go to the documentation of this file.
1//===- OptTable.h - Option Table --------------------------------*- C++ -*-===//
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#ifndef LLVM_OPTION_OPTTABLE_H
10#define LLVM_OPTION_OPTTABLE_H
11
12#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/StringRef.h"
19#include <cassert>
20#include <string>
21#include <vector>
22
23namespace llvm {
24
25class raw_ostream;
26template <typename Fn> class function_ref;
27
28namespace opt {
29
30class Arg;
31class ArgList;
32class InputArgList;
33class Option;
34
35/// Helper for overload resolution while transitioning from
36/// FlagsToInclude/FlagsToExclude APIs to VisibilityMask APIs.
38 unsigned Mask = ~0U;
39
40public:
41 explicit Visibility(unsigned Mask) : Mask(Mask) {}
42 Visibility() = default;
43
44 operator unsigned() const { return Mask; }
45};
46
47/// Provide access to the Option info table.
48///
49/// The OptTable class provides a layer of indirection which allows Option
50/// instance to be created lazily. In the common case, only a few options will
51/// be needed at runtime; the OptTable class maintains enough information to
52/// parse command lines without instantiating Options, while letting other
53/// parts of the driver still use Option instances where convenient.
55public:
56 /// Represents a subcommand and its options in the option table.
57 struct SubCommand {
58 const char *Name;
59 const char *HelpText;
60 const char *Usage;
61 };
62
63 /// Values of options declared with TableGen `ValuesCode`: only the generated
64 /// code knows them, so they cannot go in the string table. The generated
65 /// table supplies getOptionValuesCode() for this.
67
68 /// Entry for a single option instance in the option data table.
69 struct Info {
72 /// Offset 0 means the .td supplied no HelpText. A HelpText<""> maps to a
73 /// distinct empty string, marking the option deliberately undocumented.
75 // Help text for specific visibilities. A list of pairs, where each pair
76 // is a list of visibilities and a specific help string for those
77 // visibilities. If no help text is found in this list for the visibility of
78 // the program, HelpTextOffset is used instead. This cannot use std::vector
79 // because OptTable is used in constexpr contexts. Increase the array sizes
80 // here if you need more entries and adjust the constants in
81 // OptionParserEmitter::EmitHelpTextsForVariants.
82 std::array<std::pair<std::array<unsigned int, 2 /*MaxVisibilityPerHelp*/>,
84 1 /*MaxVisibilityHelp*/>
87 unsigned ID;
88 unsigned char Kind;
89 unsigned char Param;
90 unsigned int Flags;
91 unsigned int Visibility;
92 unsigned short GroupID;
93 unsigned short AliasID;
95 /// The possible values as a comma separated list, empty for an option whose
96 /// values only getOptionValuesCode() knows.
98 // Offset into OptTable's SubCommandIDsTable.
100
101 bool hasNoPrefix() const { return PrefixesOffset == 0; }
102
103 unsigned getNumPrefixes(ArrayRef<StringTable::Offset> PrefixesTable) const {
104 // We embed the number of prefixes in the value of the first offset.
105 return PrefixesTable[PrefixesOffset].value();
106 }
107
111 : PrefixesTable.slice(PrefixesOffset + 1,
112 getNumPrefixes(PrefixesTable));
113 }
114
115 bool hasHelpText() const { return HelpTextOffset.value() != 0; }
116 bool hasAliasArgs() const { return AliasArgsOffset.value() != 0; }
117
118 bool hasSubCommands() const { return SubCommandIDsOffset != 0; }
119
120 unsigned getNumSubCommandIDs(ArrayRef<unsigned> SubCommandIDsTable) const {
121 // We embed the number of subcommand IDs in the value of the first offset.
122 return SubCommandIDsTable[SubCommandIDsOffset];
123 }
124
126 getSubCommandIDs(ArrayRef<unsigned> SubCommandIDsTable) const {
127 return hasSubCommands() ? SubCommandIDsTable.slice(
129 getNumSubCommandIDs(SubCommandIDsTable))
131 }
132
133 void appendPrefixes(const StringTable &StrTable,
134 ArrayRef<StringTable::Offset> PrefixesTable,
135 SmallVectorImpl<StringRef> &Prefixes) const {
136 for (auto PrefixOffset : getPrefixOffsets(PrefixesTable))
137 Prefixes.push_back(StrTable[PrefixOffset]);
138 }
139
141 ArrayRef<StringTable::Offset> PrefixesTable,
142 unsigned PrefixIndex) const {
143 return StrTable[getPrefixOffsets(PrefixesTable)[PrefixIndex]];
144 }
145
146 StringRef getPrefixedName(const StringTable &StrTable) const {
147 return StrTable[PrefixedNameOffset];
148 }
149
151 ArrayRef<StringTable::Offset> PrefixesTable) const {
152 unsigned PrefixLength =
153 hasNoPrefix() ? 0 : getPrefix(StrTable, PrefixesTable, 0).size();
154 return getPrefixedName(StrTable).drop_front(PrefixLength);
155 }
156 };
157
158public:
159 bool isValidForSubCommand(const Info *CandidateInfo,
160 StringRef SubCommand) const {
161 assert(!SubCommand.empty() &&
162 "This helper is only for valid registered subcommands.");
163 auto SCIT = llvm::find_if(
164 SubCommands, [&](const auto &C) { return SubCommand == C.Name; });
165 assert(SCIT != SubCommands.end() &&
166 "This helper is only for valid registered subcommands.");
167 auto SubCommandIDs = CandidateInfo->getSubCommandIDs(SubCommandIDsTable);
168 unsigned CurrentSubCommandID = SCIT - &SubCommands[0];
169 return llvm::is_contained(SubCommandIDs, CurrentSubCommandID);
170 }
171
172private:
173 // A unified string table for these options. Individual strings are stored as
174 // null terminated C-strings at offsets within this table.
175 const StringTable *StrTable;
176
177 // A table of different sets of prefixes. Each set starts with the number of
178 // prefixes in that set followed by that many offsets into the string table
179 // for each of the prefix strings. This is essentially a Pascal-string style
180 // encoding.
181 ArrayRef<StringTable::Offset> PrefixesTable;
182
183 /// The option information table.
184 ArrayRef<Info> OptionInfos;
185
186 bool IgnoreCase;
187
188 /// The subcommand information table.
189 ArrayRef<SubCommand> SubCommands;
190
191 /// The subcommand IDs table.
192 ArrayRef<unsigned> SubCommandIDsTable;
193
194 ValuesCodeFnTy ValuesCodeFn = nullptr;
195
196 bool GroupedShortOptions = false;
197 bool DashDashParsing = false;
198 const char *EnvVar = nullptr;
199
200 unsigned InputOptionID = 0;
201 unsigned UnknownOptionID = 0;
202
203protected:
204 /// The index of the first option which can be parsed (i.e., is not a
205 /// special option like 'input' or 'unknown', and is not an option group).
207
208 /// The union of all option prefixes. If an argument does not begin with
209 /// one of these, it is an input.
211
212 /// The union of the first element of all option prefixes.
214
215private:
216 const Info &getInfo(OptSpecifier Opt) const {
217 unsigned id = Opt.getID();
218 assert(id > 0 && id - 1 < getNumOptions() && "Invalid Option ID.");
219 return OptionInfos[id - 1];
220 }
221
222 StringTable::Offset getHelpTextOffset(const Info &I,
223 Visibility VisibilityMask) const {
224 for (const auto &[Visibilities, TextOffset] : I.HelpTextsForVariants)
225 for (auto Vis : Visibilities)
226 if (VisibilityMask & Vis)
227 return TextOffset;
228 return I.HelpTextOffset;
229 }
230
231 StringRef getOptionValues(const Info &I) const {
232 StringRef Values = (*StrTable)[I.ValuesOffset];
233 if (Values.empty() && ValuesCodeFn)
234 Values = ValuesCodeFn(I.ID);
235 return Values;
236 }
237
238 std::unique_ptr<Arg> parseOneArgGrouped(InputArgList &Args,
239 unsigned &Index) const;
240
241protected:
242 /// Initialize OptTable using Tablegen'ed OptionInfos. Child class must
243 /// manually call \c buildPrefixChars once they are fully constructed.
244 OptTable(const StringTable &StrTable,
245 ArrayRef<StringTable::Offset> PrefixesTable,
246 ArrayRef<Info> OptionInfos, bool IgnoreCase = false,
247 ArrayRef<SubCommand> SubCommands = {},
248 ArrayRef<unsigned> SubCommandIDsTable = {});
249
250 void setValuesCodeFn(ValuesCodeFnTy Fn) { ValuesCodeFn = Fn; }
251
252 /// Build (or rebuild) the PrefixChars member.
253 void buildPrefixChars();
254
255public:
256 virtual ~OptTable();
257
258 /// Return the string table used for option names.
259 const StringTable &getStrTable() const { return *StrTable; }
260
261 ArrayRef<SubCommand> getSubCommands() const { return SubCommands; }
262
263 /// Return the prefixes table used for option names.
265 return PrefixesTable;
266 }
267
268 /// Return the total number of option classes.
269 unsigned getNumOptions() const { return OptionInfos.size(); }
270
271 /// Get the given Opt's Option instance, lazily creating it
272 /// if necessary.
273 ///
274 /// \return The option, or null for the INVALID option id.
275 const Option getOption(OptSpecifier Opt) const;
276
277 /// Lookup the name of the given option.
279 return getInfo(id).getName(*StrTable, PrefixesTable);
280 }
281
282 /// Lookup the prefix of the given option.
284 const Info &I = getInfo(id);
285 return I.hasNoPrefix() ? StringRef()
286 : I.getPrefix(*StrTable, PrefixesTable, 0);
287 }
288
290 SmallVectorImpl<StringRef> &Prefixes) const {
291 const Info &I = getInfo(id);
292 I.appendPrefixes(*StrTable, PrefixesTable, Prefixes);
293 }
294
295 /// Lookup the prefixed name of the given option.
297 return getInfo(id).getPrefixedName(*StrTable);
298 }
299
300 /// Get the kind of the given option.
301 unsigned getOptionKind(OptSpecifier id) const {
302 return getInfo(id).Kind;
303 }
304
305 /// Get the group id for the given option.
306 unsigned getOptionGroupID(OptSpecifier id) const {
307 return getInfo(id).GroupID;
308 }
309
310 /// Get the help text to use to describe this option.
314
315 // Get the help text to use to describe this option.
316 // If it has visibility specific help text and that visibility is in the
317 // visibility mask, use that text instead of the generic text.
319 Visibility VisibilityMask) const {
320 return (*StrTable)[getHelpTextOffset(getInfo(id), VisibilityMask)];
321 }
322
323 /// Get the meta-variable name to use when describing
324 /// this options values in the help text.
326 return (*StrTable)[getInfo(id).MetaVarOffset];
327 }
328
329 /// Specify the environment variable where initial options should be read.
330 void setInitialOptionsFromEnvironment(const char *E) { EnvVar = E; }
331
332 /// Support grouped short options. e.g. -ab represents -a -b.
333 void setGroupedShortOptions(bool Value) { GroupedShortOptions = Value; }
334
335 /// Set whether "--" stops option parsing and treats all subsequent arguments
336 /// as positional. E.g. -- -a -b gives two positional inputs.
337 void setDashDashParsing(bool Value) { DashDashParsing = Value; }
338
339 /// Find possible value for given flags. This is used for shell
340 /// autocompletion.
341 ///
342 /// \param [in] Option - Key flag like "-stdlib=" when "-stdlib=l"
343 /// was passed to clang.
344 ///
345 /// \param [in] Arg - Value which we want to autocomplete like "l"
346 /// when "-stdlib=l" was passed to clang.
347 ///
348 /// \return The vector of possible values.
349 std::vector<std::string> suggestValueCompletions(StringRef Option,
350 StringRef Arg) const;
351
352 /// Find flags from OptTable which starts with Cur.
353 ///
354 /// \param [in] Cur - String prefix that all returned flags need
355 // to start with.
356 ///
357 /// \return The vector of flags which start with Cur.
358 std::vector<std::string> findByPrefix(StringRef Cur,
359 Visibility VisibilityMask,
360 unsigned int DisableFlags) const;
361
362 /// Find the OptTable option that most closely matches the given string.
363 ///
364 /// \param [in] Option - A string, such as "-stdlibs=l", that represents user
365 /// input of an option that may not exist in the OptTable. Note that the
366 /// string includes prefix dashes "-" as well as values "=l".
367 /// \param [out] NearestString - The nearest option string found in the
368 /// OptTable.
369 /// \param [in] VisibilityMask - Only include options with any of these
370 /// visibility flags set.
371 /// \param [in] MinimumLength - Don't find options shorter than this length.
372 /// For example, a minimum length of 3 prevents "-x" from being considered
373 /// near to "-S".
374 /// \param [in] MaximumDistance - Don't find options whose distance is greater
375 /// than this value.
376 ///
377 /// \return The edit distance of the nearest string found.
378 unsigned findNearest(StringRef Option, std::string &NearestString,
379 Visibility VisibilityMask = Visibility(),
380 unsigned MinimumLength = 4,
381 unsigned MaximumDistance = UINT_MAX) const;
382
383 unsigned findNearest(StringRef Option, std::string &NearestString,
384 unsigned FlagsToInclude, unsigned FlagsToExclude = 0,
385 unsigned MinimumLength = 4,
386 unsigned MaximumDistance = UINT_MAX) const;
387
388private:
389 unsigned
390 internalFindNearest(StringRef Option, std::string &NearestString,
391 unsigned MinimumLength, unsigned MaximumDistance,
392 std::function<bool(const Info &)> ExcludeOption) const;
393
394public:
395 bool findExact(StringRef Option, std::string &ExactString,
396 Visibility VisibilityMask = Visibility()) const {
397 return findNearest(Option, ExactString, VisibilityMask, 4, 0) == 0;
398 }
399
400 bool findExact(StringRef Option, std::string &ExactString,
401 unsigned FlagsToInclude, unsigned FlagsToExclude = 0) const {
402 return findNearest(Option, ExactString, FlagsToInclude, FlagsToExclude, 4,
403 0) == 0;
404 }
405
406 /// Parse a single argument; returning the new argument and
407 /// updating Index.
408 ///
409 /// \param [in,out] Index - The current parsing position in the argument
410 /// string list; on return this will be the index of the next argument
411 /// string to parse.
412 /// \param [in] VisibilityMask - Only include options with any of these
413 /// visibility flags set.
414 ///
415 /// \return The parsed argument, or 0 if the argument is missing values
416 /// (in which case Index still points at the conceptual next argument string
417 /// to parse).
418 std::unique_ptr<Arg>
419 ParseOneArg(const ArgList &Args, unsigned &Index,
420 Visibility VisibilityMask = Visibility()) const;
421
422 std::unique_ptr<Arg> ParseOneArg(const ArgList &Args, unsigned &Index,
423 unsigned FlagsToInclude,
424 unsigned FlagsToExclude) const;
425
426private:
427 std::unique_ptr<Arg>
428 internalParseOneArg(const ArgList &Args, unsigned &Index,
429 std::function<bool(const Option &)> ExcludeOption) const;
430
431public:
432 /// Parse an list of arguments into an InputArgList.
433 ///
434 /// The resulting InputArgList will reference the strings in [\p ArgBegin,
435 /// \p ArgEnd), and their lifetime should extend past that of the returned
436 /// InputArgList.
437 ///
438 /// The only error that can occur in this routine is if an argument is
439 /// missing values; in this case \p MissingArgCount will be non-zero.
440 ///
441 /// \param MissingArgIndex - On error, the index of the option which could
442 /// not be parsed.
443 /// \param MissingArgCount - On error, the number of missing options.
444 /// \param VisibilityMask - Only include options with any of these
445 /// visibility flags set.
446 /// \return An InputArgList; on error this will contain all the options
447 /// which could be parsed.
448 InputArgList ParseArgs(ArrayRef<const char *> Args, unsigned &MissingArgIndex,
449 unsigned &MissingArgCount,
450 Visibility VisibilityMask = Visibility()) const;
451
452 InputArgList ParseArgs(ArrayRef<const char *> Args, unsigned &MissingArgIndex,
453 unsigned &MissingArgCount, unsigned FlagsToInclude,
454 unsigned FlagsToExclude = 0) const;
455
456private:
458 internalParseArgs(ArrayRef<const char *> Args, unsigned &MissingArgIndex,
459 unsigned &MissingArgCount,
460 std::function<bool(const Option &)> ExcludeOption) const;
461
462public:
463 /// A convenience helper which handles optional initial options populated from
464 /// an environment variable, expands response files recursively and parses
465 /// options.
466 ///
467 /// \param ErrorFn - Called on a formatted error message for missing arguments
468 /// or unknown options.
469 /// \return An InputArgList; on error this will contain all the options which
470 /// could be parsed.
471 InputArgList parseArgs(int Argc, char *const *Argv, OptSpecifier Unknown,
472 StringSaver &Saver,
473 std::function<void(StringRef)> ErrorFn) const;
474
475 /// Render the help text for an option table.
476 ///
477 /// \param OS - The stream to write the help text to.
478 /// \param Usage - USAGE: Usage
479 /// \param Title - OVERVIEW: Title
480 /// \param VisibilityMask - Only in Visibility VisibilityMask,clude options with any of these
481 /// visibility flags set.
482 /// \param ShowHidden - If true, display options marked as HelpHidden
483 /// \param ShowAllAliases - If true, display all options including aliases
484 /// that don't have help texts. By default, we display
485 /// only options that are not hidden and have help
486 /// texts.
487 void printHelp(raw_ostream &OS, const char *Usage, const char *Title,
488 bool ShowHidden = false, bool ShowAllAliases = false,
489 Visibility VisibilityMask = Visibility(),
490 StringRef SubCommand = {}) const;
491
492 void printHelp(raw_ostream &OS, const char *Usage, const char *Title,
493 unsigned FlagsToInclude, unsigned FlagsToExclude,
494 bool ShowAllAliases) const;
495
496private:
497 void internalPrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
498 StringRef SubCommand, bool ShowHidden,
499 bool ShowAllAliases,
500 std::function<bool(const Info &)> ExcludeOption,
501 Visibility VisibilityMask) const;
502};
503
504/// Specialization of OptTable
505class GenericOptTable : public OptTable {
506protected:
507 LLVM_ABI GenericOptTable(const StringTable &StrTable,
508 ArrayRef<StringTable::Offset> PrefixesTable,
509 ArrayRef<Info> OptionInfos, bool IgnoreCase = false,
510 ArrayRef<SubCommand> SubCommands = {},
511 ArrayRef<unsigned> SubCommandIDsTable = {});
512};
513
515protected:
517 ArrayRef<StringTable::Offset> PrefixesTable,
518 ArrayRef<Info> OptionInfos,
519 ArrayRef<StringTable::Offset> PrefixesUnionOffsets,
520 bool IgnoreCase = false,
521 ArrayRef<SubCommand> SubCommands = {},
522 ArrayRef<unsigned> SubCommandIDsTable = {})
523 : OptTable(StrTable, PrefixesTable, OptionInfos, IgnoreCase, SubCommands,
524 SubCommandIDsTable) {
525 for (auto PrefixOffset : PrefixesUnionOffsets)
526 PrefixesUnion.push_back(StrTable[PrefixOffset]);
528 }
529};
530
531} // end namespace opt
532
533} // end namespace llvm
534
535#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
536 ID_PREFIX, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
537 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
538 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
539 ID_PREFIX##ID
540
541#define LLVM_MAKE_OPT_ID(PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, \
542 GROUP, ALIAS, ALIASARGS, FLAGS, VISIBILITY, PARAM, \
543 HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, \
544 SUBCOMMANDIDS_OFFSET) \
545 LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
546 OPT_, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
547 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
548 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET)
549
550#define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
551 ID_PREFIX, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
552 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
553 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \
554 llvm::opt::OptTable::Info { \
555 PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, HELPTEXT, HELPTEXTSFORVARIANTS, \
556 METAVAR, ID_PREFIX##ID, llvm::opt::Option::KIND##Class, PARAM, FLAGS, \
557 VISIBILITY, ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES, \
558 SUBCOMMANDIDS_OFFSET \
559 }
560
561#define LLVM_CONSTRUCT_OPT_INFO( \
562 PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, ALIASARGS, \
563 FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, \
564 SUBCOMMANDIDS_OFFSET) \
565 LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
566 OPT_, PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
567 ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \
568 METAVAR, VALUES, SUBCOMMANDIDS_OFFSET)
569
570#endif // LLVM_OPTION_OPTTABLE_H
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")
#define LLVM_ABI
Definition Compiler.h:215
#define I(x, y, z)
Definition MD5.cpp:57
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),...
Definition ArrayRef.h:40
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
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.
Definition StringRef.h:56
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition StringSaver.h:22
A table of densely packed, null-terminated strings indexed by offset.
Definition StringTable.h:34
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
ArgList - Ordered collection of driver arguments.
Definition ArgList.h:118
A concrete instance of a particular driver option.
Definition Arg.h:35
LLVM_ABI GenericOptTable(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, ArrayRef< Info > OptionInfos, bool IgnoreCase=false, ArrayRef< SubCommand > SubCommands={}, ArrayRef< unsigned > SubCommandIDsTable={})
Definition OptTable.cpp:842
OptSpecifier - Wrapper class for abstracting references to option IDs.
unsigned getID() const
void buildPrefixChars()
Build (or rebuild) the PrefixChars member.
Definition OptTable.cpp:125
bool isValidForSubCommand(const Info *CandidateInfo, StringRef SubCommand) const
Definition OptTable.h:159
StringRef getOptionName(OptSpecifier id) const
Lookup the name of the given option.
Definition OptTable.h:278
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
Definition OptTable.h:301
unsigned FirstSearchableIndex
The index of the first option which can be parsed (i.e., is not a special option like 'input' or 'unk...
Definition OptTable.h:206
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.
Definition OptTable.cpp:237
SmallVector< StringRef > PrefixesUnion
The union of all option prefixes.
Definition OptTable.h:210
StringRef getOptionPrefix(OptSpecifier id) const
Lookup the prefix of the given option.
Definition OptTable.h:283
bool findExact(StringRef Option, std::string &ExactString, unsigned FlagsToInclude, unsigned FlagsToExclude=0) const
Definition OptTable.h:400
void setInitialOptionsFromEnvironment(const char *E)
Specify the environment variable where initial options should be read.
Definition OptTable.h:330
OptTable(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, ArrayRef< Info > OptionInfos, bool IgnoreCase=false, ArrayRef< SubCommand > SubCommands={}, ArrayRef< unsigned > SubCommandIDsTable={})
Initialize OptTable using Tablegen'ed OptionInfos.
Definition OptTable.cpp:77
void setDashDashParsing(bool Value)
Set whether "--" stops option parsing and treats all subsequent arguments as positional.
Definition OptTable.h:337
StringRef getOptionHelpText(OptSpecifier id, Visibility VisibilityMask) const
Definition OptTable.h:318
StringRef(*)(unsigned) ValuesCodeFnTy
Values of options declared with TableGen ValuesCode: only the generated code knows them,...
Definition OptTable.h:66
void setValuesCodeFn(ValuesCodeFnTy Fn)
Definition OptTable.h:250
unsigned getOptionGroupID(OptSpecifier id) const
Get the group id for the given option.
Definition OptTable.h:306
StringRef getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text.
Definition OptTable.h:325
StringRef getOptionPrefixedName(OptSpecifier id) const
Lookup the prefixed name of the given option.
Definition OptTable.h:296
ArrayRef< StringTable::Offset > getPrefixesTable() const
Return the prefixes table used for option names.
Definition OptTable.h:264
SmallString< 8 > PrefixChars
The union of the first element of all option prefixes.
Definition OptTable.h:213
void appendOptionPrefixes(OptSpecifier id, SmallVectorImpl< StringRef > &Prefixes) const
Definition OptTable.h:289
unsigned getNumOptions() const
Return the total number of option classes.
Definition OptTable.h:269
bool findExact(StringRef Option, std::string &ExactString, Visibility VisibilityMask=Visibility()) const
Definition OptTable.h:395
StringRef getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
Definition OptTable.h:311
ArrayRef< SubCommand > getSubCommands() const
Definition OptTable.h:261
const StringTable & getStrTable() const
Return the string table used for option names.
Definition OptTable.h:259
void setGroupedShortOptions(bool Value)
Support grouped short options. e.g. -ab represents -a -b.
Definition OptTable.h:333
Option - Abstract representation for a single form of driver argument.
Definition Option.h:55
PrecomputedOptTable(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, ArrayRef< Info > OptionInfos, ArrayRef< StringTable::Offset > PrefixesUnionOffsets, bool IgnoreCase=false, ArrayRef< SubCommand > SubCommands={}, ArrayRef< unsigned > SubCommandIDsTable={})
Definition OptTable.h:516
Helper for overload resolution while transitioning from FlagsToInclude/FlagsToExclude APIs to Visibil...
Definition OptTable.h:37
Visibility(unsigned Mask)
Definition OptTable.h:41
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
@ 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.
Definition STLExtras.h:1772
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
Entry for a single option instance in the option data table.
Definition OptTable.h:69
void appendPrefixes(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, SmallVectorImpl< StringRef > &Prefixes) const
Definition OptTable.h:133
bool hasNoPrefix() const
Definition OptTable.h:101
StringTable::Offset AliasArgsOffset
Definition OptTable.h:94
StringTable::Offset PrefixedNameOffset
Definition OptTable.h:71
unsigned getNumPrefixes(ArrayRef< StringTable::Offset > PrefixesTable) const
Definition OptTable.h:103
bool hasHelpText() const
Definition OptTable.h:115
std::array< std::pair< std::array< unsigned int, 2 >, StringTable::Offset >, 1 > HelpTextsForVariants
Definition OptTable.h:85
bool hasSubCommands() const
Definition OptTable.h:118
unsigned char Param
Definition OptTable.h:89
StringRef getPrefixedName(const StringTable &StrTable) const
Definition OptTable.h:146
ArrayRef< StringTable::Offset > getPrefixOffsets(ArrayRef< StringTable::Offset > PrefixesTable) const
Definition OptTable.h:109
unsigned int Visibility
Definition OptTable.h:91
unsigned short AliasID
Definition OptTable.h:93
bool hasAliasArgs() const
Definition OptTable.h:116
StringTable::Offset HelpTextOffset
Offset 0 means the .td supplied no HelpText.
Definition OptTable.h:74
StringRef getPrefix(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable, unsigned PrefixIndex) const
Definition OptTable.h:140
StringTable::Offset ValuesOffset
The possible values as a comma separated list, empty for an option whose values only getOptionValuesC...
Definition OptTable.h:97
StringRef getName(const StringTable &StrTable, ArrayRef< StringTable::Offset > PrefixesTable) const
Definition OptTable.h:150
unsigned short GroupID
Definition OptTable.h:92
StringTable::Offset MetaVarOffset
Definition OptTable.h:86
ArrayRef< unsigned > getSubCommandIDs(ArrayRef< unsigned > SubCommandIDsTable) const
Definition OptTable.h:126
unsigned getNumSubCommandIDs(ArrayRef< unsigned > SubCommandIDsTable) const
Definition OptTable.h:120
Represents a subcommand and its options in the option table.
Definition OptTable.h:57