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