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