Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
CommandLine.h
Go to the documentation of this file.
1//===- llvm/Support/CommandLine.h - Command line handler --------*- 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// This class implements a command line argument processor that is useful when
10// creating a tool. It provides a simple, minimalistic interface that is easily
11// extensible and supports nonlocal (library) command line options.
12//
13// Note that rather than trying to figure out what this code does, you should
14// read the library documentation located in docs/CommandLine.html or looks at
15// the many example usages in tools/*/*.cpp
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_SUPPORT_COMMANDLINE_H
20#define LLVM_SUPPORT_COMMANDLINE_H
21
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/STLExtras.h"
24#include "llvm/ADT/SmallPtrSet.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/ADT/Twine.h"
29#include "llvm/ADT/iterator_range.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/StringSaver.h"
32#include "llvm/Support/raw_ostream.h"
33#include <cassert>
34#include <climits>
35#include <cstddef>
36#include <functional>
37#include <initializer_list>
38#include <string>
39#include <type_traits>
40#include <vector>
41
42namespacellvm {
43
44namespacevfs {
45classFileSystem;
46}
47
48classStringSaver;
49
50/// This namespace contains all of the command line option processing machinery.
51/// It is intentionally a short name to make qualified usage concise.
52namespacecl {
53
54//===----------------------------------------------------------------------===//
55// Command line option processing entry point.
56//
57// Returns true on success. Otherwise, this will print the error message to
58// stderr and exit if \p Errs is not set (nullptr by default), or print the
59// error message to \p Errs and return false if \p Errs is provided.
60//
61// If EnvVar is not nullptr, command-line options are also parsed from the
62// environment variable named by EnvVar. Precedence is given to occurrences
63// from argv. This precedence is currently implemented by parsing argv after
64// the environment variable, so it is only implemented correctly for options
65// that give precedence to later occurrences. If your program supports options
66// that give precedence to earlier occurrences, you will need to extend this
67// function to support it correctly.
68boolParseCommandLineOptions(int argc,constchar *const *argv,
69StringRef Overview ="",
70raw_ostream *Errs =nullptr,
71constchar *EnvVar =nullptr,
72bool LongOptionsUseDoubleDash =false);
73
74// Function pointer type for printing version information.
75usingVersionPrinterTy = std::function<void(raw_ostream &)>;
76
77///===---------------------------------------------------------------------===//
78/// Override the default (LLVM specific) version printer used to print out the
79/// version when --version is given on the command line. This allows other
80/// systems using the CommandLine utilities to print their own version string.
81voidSetVersionPrinter(VersionPrinterTyfunc);
82
83///===---------------------------------------------------------------------===//
84/// Add an extra printer to use in addition to the default one. This can be
85/// called multiple times, and each time it adds a new function to the list
86/// which will be called after the basic LLVM version printing is complete.
87/// Each can then add additional information specific to the tool.
88voidAddExtraVersionPrinter(VersionPrinterTyfunc);
89
90// Print option values.
91// With -print-options print the difference between option values and defaults.
92// With -print-all-options print all option values.
93// (Currently not perfect, but best-effort.)
94voidPrintOptionValues();
95
96// Forward declaration - AddLiteralOption needs to be up here to make gcc happy.
97classOption;
98
99/// Adds a new option for parsing and provides the option it refers to.
100///
101/// \param O pointer to the option
102/// \param Name the string name for the option to handle during parsing
103///
104/// Literal options are used by some parsers to register special option values.
105/// This is how the PassNameParser registers pass names for opt.
106voidAddLiteralOption(Option &O,StringRefName);
107
108//===----------------------------------------------------------------------===//
109// Flags permitted to be passed to command line arguments
110//
111
112enumNumOccurrencesFlag {// Flags for the number of occurrences allowed
113Optional = 0x00,// Zero or One occurrence
114ZeroOrMore = 0x01,// Zero or more occurrences allowed
115Required = 0x02,// One occurrence required
116OneOrMore = 0x03,// One or more occurrences required
117
118// Indicates that this option is fed anything that follows the last positional
119// argument required by the application (it is an error if there are zero
120// positional arguments, and a ConsumeAfter option is used).
121// Thus, for example, all arguments to LLI are processed until a filename is
122// found. Once a filename is found, all of the succeeding arguments are
123// passed, unprocessed, to the ConsumeAfter option.
124//
125ConsumeAfter = 0x04
126};
127
128enumValueExpected {// Is a value required for the option?
129// zero reserved for the unspecified value
130ValueOptional = 0x01,// The value can appear... or not
131ValueRequired = 0x02,// The value is required to appear!
132ValueDisallowed = 0x03// A value may not be specified (for flags)
133};
134
135enumOptionHidden {// Control whether -help shows this option
136NotHidden = 0x00,// Option included in -help & -help-hidden
137Hidden = 0x01,// -help doesn't, but -help-hidden does
138ReallyHidden = 0x02// Neither -help nor -help-hidden show this arg
139};
140
141// This controls special features that the option might have that cause it to be
142// parsed differently...
143//
144// Prefix - This option allows arguments that are otherwise unrecognized to be
145// matched by options that are a prefix of the actual value. This is useful for
146// cases like a linker, where options are typically of the form '-lfoo' or
147// '-L../../include' where -l or -L are the actual flags. When prefix is
148// enabled, and used, the value for the flag comes from the suffix of the
149// argument.
150//
151// AlwaysPrefix - Only allow the behavior enabled by the Prefix flag and reject
152// the Option=Value form.
153//
154
155enumFormattingFlags {
156NormalFormatting = 0x00,// Nothing special
157Positional = 0x01,// Is a positional argument, no '-' required
158Prefix = 0x02,// Can this option directly prefix its value?
159AlwaysPrefix = 0x03// Can this option only directly prefix its value?
160};
161
162enumMiscFlags {// Miscellaneous flags to adjust argument
163CommaSeparated = 0x01,// Should this cl::list split between commas?
164PositionalEatsArgs = 0x02,// Should this positional cl::list eat -args?
165Sink = 0x04,// Should this cl::list eat all unknown options?
166
167// Can this option group with other options?
168// If this is enabled, multiple letter options are allowed to bunch together
169// with only a single hyphen for the whole group. This allows emulation
170// of the behavior that ls uses for example: ls -la === ls -l -a
171Grouping = 0x08,
172
173// Default option
174DefaultOption = 0x10
175};
176
177//===----------------------------------------------------------------------===//
178//
179classOptionCategory {
180private:
181StringRefconst Name;
182StringRefconst Description;
183
184void registerCategory();
185
186public:
187OptionCategory(StringRefconst Name,
188StringRefconst Description ="")
189 : Name(Name), Description(Description) {
190 registerCategory();
191 }
192
193StringRefgetName() const{return Name; }
194StringRefgetDescription() const{return Description; }
195};
196
197// The general Option Category (used as default category).
198OptionCategory &getGeneralCategory();
199
200//===----------------------------------------------------------------------===//
201//
202classSubCommand {
203private:
204StringRef Name;
205StringRef Description;
206
207protected:
208voidregisterSubCommand();
209voidunregisterSubCommand();
210
211public:
212SubCommand(StringRef Name,StringRef Description ="")
213 : Name(Name), Description(Description) {
214registerSubCommand();
215 }
216SubCommand() =default;
217
218// Get the special subcommand representing no subcommand.
219staticSubCommand &getTopLevel();
220
221// Get the special subcommand that can be used to put an option into all
222// subcommands.
223staticSubCommand &getAll();
224
225voidreset();
226
227explicitoperatorbool()const;
228
229StringRefgetName() const{return Name; }
230StringRefgetDescription() const{return Description; }
231
232SmallVector<Option *, 4>PositionalOpts;
233SmallVector<Option *, 4>SinkOpts;
234StringMap<Option *>OptionsMap;
235
236Option *ConsumeAfterOpt =nullptr;// The ConsumeAfter option if it exists.
237};
238
239classSubCommandGroup {
240SmallVector<SubCommand *, 4> Subs;
241
242public:
243SubCommandGroup(std::initializer_list<SubCommand *> IL) : Subs(IL) {}
244
245ArrayRef<SubCommand *>getSubCommands() const{return Subs; }
246};
247
248//===----------------------------------------------------------------------===//
249//
250classOption {
251friendclassalias;
252
253// Overriden by subclasses to handle the value passed into an argument. Should
254// return true if there was an error processing the argument and the program
255// should exit.
256//
257virtualbool handleOccurrence(unsigned pos,StringRef ArgName,
258StringRef Arg) = 0;
259
260virtualenumValueExpected getValueExpectedFlagDefault() const{
261returnValueOptional;
262 }
263
264// Out of line virtual function to provide home for the class.
265virtualvoid anchor();
266
267uint16_t NumOccurrences;// The number of times specified
268// Occurrences, HiddenFlag, and Formatting are all enum types but to avoid
269// problems with signed enums in bitfields.
270uint16_t Occurrences : 3;// enum NumOccurrencesFlag
271// not using the enum type for 'Value' because zero is an implementation
272// detail representing the non-value
273uint16_tValue : 2;
274uint16_t HiddenFlag : 2;// enum OptionHidden
275uint16_t Formatting : 2;// enum FormattingFlags
276uint16_t Misc : 5;
277uint16_t FullyInitialized : 1;// Has addArgument been called?
278uint16_t Position;// Position of last occurrence of the option
279uint16_t AdditionalVals;// Greater than 0 for multi-valued option.
280
281public:
282StringRefArgStr;// The argument string itself (ex: "help", "o")
283StringRefHelpStr;// The descriptive text message for -help
284StringRefValueStr;// String describing what the value of this option is
285SmallVector<OptionCategory *, 1>
286Categories;// The Categories this option belongs to
287SmallPtrSet<SubCommand *, 1>Subs;// The subcommands this option belongs to.
288
289inlineenumNumOccurrencesFlaggetNumOccurrencesFlag() const{
290return (enumNumOccurrencesFlag)Occurrences;
291 }
292
293inlineenumValueExpectedgetValueExpectedFlag() const{
294returnValue ? ((enumValueExpected)Value) : getValueExpectedFlagDefault();
295 }
296
297inlineenumOptionHiddengetOptionHiddenFlag() const{
298return (enumOptionHidden)HiddenFlag;
299 }
300
301inlineenumFormattingFlagsgetFormattingFlag() const{
302return (enumFormattingFlags)Formatting;
303 }
304
305inlineunsignedgetMiscFlags() const{return Misc; }
306inlineunsignedgetPosition() const{return Position; }
307inlineunsignedgetNumAdditionalVals() const{return AdditionalVals; }
308
309// Return true if the argstr != ""
310boolhasArgStr() const{return !ArgStr.empty(); }
311boolisPositional() const{returngetFormattingFlag() ==cl::Positional; }
312boolisSink() const{returngetMiscFlags() &cl::Sink; }
313boolisDefaultOption() const{returngetMiscFlags() &cl::DefaultOption; }
314
315boolisConsumeAfter() const{
316returngetNumOccurrencesFlag() ==cl::ConsumeAfter;
317 }
318
319//-------------------------------------------------------------------------===
320// Accessor functions set by OptionModifiers
321//
322voidsetArgStr(StringRef S);
323voidsetDescription(StringRef S) {HelpStr = S; }
324voidsetValueStr(StringRef S) {ValueStr = S; }
325voidsetNumOccurrencesFlag(enumNumOccurrencesFlag Val) { Occurrences = Val; }
326voidsetValueExpectedFlag(enumValueExpected Val) {Value = Val; }
327voidsetHiddenFlag(enumOptionHidden Val) { HiddenFlag = Val; }
328voidsetFormattingFlag(enumFormattingFlags V) { Formatting = V; }
329voidsetMiscFlag(enumMiscFlags M) { Misc |= M; }
330voidsetPosition(unsigned pos) { Position = pos; }
331voidaddCategory(OptionCategory &C);
332voidaddSubCommand(SubCommand &S) {Subs.insert(&S); }
333
334protected:
335explicitOption(enumNumOccurrencesFlag OccurrencesFlag,
336enumOptionHiddenHidden)
337 : NumOccurrences(0), Occurrences(OccurrencesFlag),Value(0),
338 HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0),
339 FullyInitialized(false), Position(0), AdditionalVals(0) {
340Categories.push_back(&getGeneralCategory());
341 }
342
343inlinevoidsetNumAdditionalVals(unsigned n) { AdditionalVals = n; }
344
345public:
346virtual~Option() =default;
347
348// Register this argument with the commandline system.
349//
350voidaddArgument();
351
352 /// Unregisters this option from the CommandLine system.
353 ///
354 /// This option must have been the last option registered.
355 /// For testing purposes only.
356voidremoveArgument();
357
358// Return the width of the option tag for printing...
359virtualsize_tgetOptionWidth()const = 0;
360
361// Print out information about this option. The to-be-maintained width is
362// specified.
363//
364virtualvoidprintOptionInfo(size_t GlobalWidth)const = 0;
365
366virtualvoidprintOptionValue(size_t GlobalWidth,bool Force)const = 0;
367
368virtualvoidsetDefault() = 0;
369
370// Prints the help string for an option.
371//
372// This maintains the Indent for multi-line descriptions.
373// FirstLineIndentedBy is the count of chars of the first line
374// i.e. the one containing the --<option name>.
375staticvoidprintHelpStr(StringRefHelpStr,size_t Indent,
376size_t FirstLineIndentedBy);
377
378// Prints the help string for an enum value.
379//
380// This maintains the Indent for multi-line descriptions.
381// FirstLineIndentedBy is the count of chars of the first line
382// i.e. the one containing the =<value>.
383staticvoidprintEnumValHelpStr(StringRefHelpStr,size_t Indent,
384size_t FirstLineIndentedBy);
385
386virtualvoidgetExtraOptionNames(SmallVectorImpl<StringRef> &) {}
387
388// Wrapper around handleOccurrence that enforces Flags.
389//
390virtualbooladdOccurrence(unsigned pos,StringRef ArgName,StringRefValue,
391bool MultiArg =false);
392
393// Prints option name followed by message. Always returns true.
394boolerror(constTwine &Message,StringRef ArgName =StringRef(),raw_ostream &Errs =llvm::errs());
395boolerror(constTwine &Message,raw_ostream &Errs) {
396returnerror(Message,StringRef(), Errs);
397 }
398
399inlineintgetNumOccurrences() const{return NumOccurrences; }
400voidreset();
401};
402
403//===----------------------------------------------------------------------===//
404// Command line option modifiers that can be used to modify the behavior of
405// command line option parsers...
406//
407
408// Modifier to set the description shown in the -help output...
409structdesc {
410StringRefDesc;
411
412desc(StringRef Str) :Desc(Str) {}
413
414voidapply(Option &O) const{ O.setDescription(Desc); }
415};
416
417// Modifier to set the value description shown in the -help output...
418structvalue_desc {
419StringRefDesc;
420
421value_desc(StringRef Str) :Desc(Str) {}
422
423voidapply(Option &O) const{ O.setValueStr(Desc); }
424};
425
426// Specify a default (initial) value for the command line argument, if the
427// default constructor for the argument type does not give you what you want.
428// This is only valid on "opt" arguments, not on "list" arguments.
429template <class Ty>structinitializer {
430const Ty &Init;
431initializer(const Ty &Val) :Init(Val) {}
432
433template <class Opt>voidapply(Opt &O) const{ O.setInitialValue(Init); }
434};
435
436template <class Ty>structlist_initializer {
437ArrayRef<Ty>Inits;
438list_initializer(ArrayRef<Ty> Vals) :Inits(Vals) {}
439
440template <class Opt>voidapply(Opt &O) const{ O.setInitialValues(Inits); }
441};
442
443template <class Ty>initializer<Ty>init(const Ty &Val) {
444returninitializer<Ty>(Val);
445}
446
447template <class Ty>
448list_initializer<Ty>list_init(ArrayRef<Ty> Vals) {
449returnlist_initializer<Ty>(Vals);
450}
451
452// Allow the user to specify which external variable they want to store the
453// results of the command line argument processing into, if they don't want to
454// store it in the option itself.
455template <class Ty>structLocationClass {
456 Ty &Loc;
457
458LocationClass(Ty &L) :Loc(L) {}
459
460template <class Opt>voidapply(Opt &O) const{ O.setLocation(O,Loc); }
461};
462
463template <class Ty>LocationClass<Ty>location(Ty &L) {
464returnLocationClass<Ty>(L);
465}
466
467// Specify the Option category for the command line argument to belong to.
468structcat {
469OptionCategory &Category;
470
471cat(OptionCategory &c) :Category(c) {}
472
473template <class Opt>voidapply(Opt &O) const{ O.addCategory(Category); }
474};
475
476// Specify the subcommand that this option belongs to.
477structsub {
478SubCommand *Sub =nullptr;
479SubCommandGroup *Group =nullptr;
480
481sub(SubCommand &S) :Sub(&S) {}
482sub(SubCommandGroup &G) :Group(&G) {}
483
484template <class Opt>voidapply(Opt &O) const{
485if (Sub)
486 O.addSubCommand(*Sub);
487elseif (Group)
488for (SubCommand *SC :Group->getSubCommands())
489 O.addSubCommand(*SC);
490 }
491};
492
493// Specify a callback function to be called when an option is seen.
494// Can be used to set other options automatically.
495template <typename R,typename Ty>structcb {
496 std::function<R(Ty)>CB;
497
498cb(std::function<R(Ty)>CB) :CB(CB) {}
499
500template <typename Opt>voidapply(Opt &O) const{ O.setCallback(CB); }
501};
502
503namespacedetail {
504template <typename F>
505structcallback_traits :publiccallback_traits<decltype(&F::operator())> {};
506
507template <typename R,typenameC,typename... Args>
508structcallback_traits<R (C::*)(Args...)const> {
509usingresult_type = R;
510usingarg_type = std::tuple_element_t<0, std::tuple<Args...>>;
511static_assert(sizeof...(Args) == 1,"callback function must have one and only one parameter");
512static_assert(std::is_same_v<result_type, void>,
513"callback return type must be void");
514static_assert(std::is_lvalue_reference_v<arg_type> &&
515 std::is_const_v<std::remove_reference_t<arg_type>>,
516"callback arg_type must be a const lvalue reference");
517};
518}// namespace detail
519
520template <typename F>
521cb<typename detail::callback_traits<F>::result_type,
522typenamedetail::callback_traits<F>::arg_type>
523callback(F CB) {
524usingresult_type =typenamedetail::callback_traits<F>::result_type;
525usingarg_type =typenamedetail::callback_traits<F>::arg_type;
526returncb<result_type, arg_type>(CB);
527}
528
529//===----------------------------------------------------------------------===//
530
531// Support value comparison outside the template.
532structGenericOptionValue {
533virtualboolcompare(constGenericOptionValue &V)const = 0;
534
535protected:
536GenericOptionValue() =default;
537GenericOptionValue(constGenericOptionValue&) =default;
538GenericOptionValue &operator=(constGenericOptionValue &) =default;
539~GenericOptionValue() =default;
540
541private:
542virtualvoid anchor();
543};
544
545template <class DataType>structOptionValue;
546
547// The default value safely does nothing. Option value printing is only
548// best-effort.
549template <class DataType,bool isClass>
550structOptionValueBase :publicGenericOptionValue {
551// Temporary storage for argument passing.
552usingWrapperType =OptionValue<DataType>;
553
554boolhasValue() const{returnfalse; }
555
556const DataType &getValue() const{llvm_unreachable("no default value"); }
557
558// Some options may take their value from a different data type.
559template <class DT>voidsetValue(const DT &/*V*/) {}
560
561// Returns whether this instance matches the argument.
562boolcompare(const DataType &/*V*/) const{returnfalse; }
563
564boolcompare(constGenericOptionValue &/*V*/) const override{
565returnfalse;
566 }
567
568protected:
569~OptionValueBase() =default;
570};
571
572// Simple copy of the option value.
573template <class DataType>classOptionValueCopy :publicGenericOptionValue {
574 DataTypeValue;
575bool Valid =false;
576
577protected:
578OptionValueCopy(constOptionValueCopy&) =default;
579OptionValueCopy &operator=(constOptionValueCopy &) =default;
580~OptionValueCopy() =default;
581
582public:
583OptionValueCopy() =default;
584
585boolhasValue() const{return Valid; }
586
587const DataType &getValue() const{
588assert(Valid &&"invalid option value");
589returnValue;
590 }
591
592voidsetValue(const DataType &V) {
593 Valid =true;
594Value = V;
595 }
596
597// Returns whether this instance matches V.
598boolcompare(const DataType &V) const{return Valid && (Value == V); }
599
600boolcompare(constGenericOptionValue &V) const override{
601constOptionValueCopy<DataType> &VC =
602static_cast<constOptionValueCopy<DataType> &>(V);
603if (!VC.hasValue())
604returnfalse;
605returncompare(VC.getValue());
606 }
607};
608
609// Non-class option values.
610template <class DataType>
611structOptionValueBase<DataType,false> :OptionValueCopy<DataType> {
612usingWrapperType = DataType;
613
614protected:
615OptionValueBase() =default;
616OptionValueBase(constOptionValueBase&) =default;
617OptionValueBase &operator=(constOptionValueBase &) =default;
618~OptionValueBase() =default;
619};
620
621// Top-level option class.
622template <class DataType>
623structOptionValue final
624 :OptionValueBase<DataType, std::is_class_v<DataType>> {
625OptionValue() =default;
626
627OptionValue(const DataType &V) { this->setValue(V); }
628
629// Some options may take their value from a different data type.
630template <class DT>OptionValue<DataType> &operator=(const DT &V) {
631 this->setValue(V);
632return *this;
633 }
634};
635
636// Other safe-to-copy-by-value common option types.
637enumboolOrDefault {BOU_UNSET,BOU_TRUE,BOU_FALSE };
638template <>
639structOptionValue<cl::boolOrDefault> final
640 :OptionValueCopy<cl::boolOrDefault> {
641usingWrapperType =cl::boolOrDefault;
642
643OptionValue() =default;
644
645OptionValue(constcl::boolOrDefault &V) { this->setValue(V); }
646
647OptionValue<cl::boolOrDefault> &operator=(constcl::boolOrDefault &V) {
648setValue(V);
649return *this;
650 }
651
652private:
653void anchor()override;
654};
655
656template <>
657structOptionValue<std::string> final :OptionValueCopy<std::string> {
658usingWrapperType =StringRef;
659
660OptionValue() =default;
661
662OptionValue(const std::string &V) { this->setValue(V); }
663
664OptionValue<std::string> &operator=(const std::string &V) {
665setValue(V);
666return *this;
667 }
668
669private:
670void anchor()override;
671};
672
673//===----------------------------------------------------------------------===//
674// Enum valued command line option
675//
676
677// This represents a single enum value, using "int" as the underlying type.
678structOptionEnumValue {
679StringRefName;
680intValue;
681StringRefDescription;
682};
683
684#define clEnumVal(ENUMVAL, DESC) \
685 llvm::cl::OptionEnumValue { #ENUMVAL, int(ENUMVAL), DESC }
686#define clEnumValN(ENUMVAL, FLAGNAME, DESC) \
687 llvm::cl::OptionEnumValue { FLAGNAME, int(ENUMVAL), DESC }
688
689// For custom data types, allow specifying a group of values together as the
690// values that go into the mapping that the option handler uses.
691//
692classValuesClass {
693// Use a vector instead of a map, because the lists should be short,
694// the overhead is less, and most importantly, it keeps them in the order
695// inserted so we can print our option out nicely.
696SmallVector<OptionEnumValue, 4> Values;
697
698public:
699ValuesClass(std::initializer_list<OptionEnumValue>Options)
700 : Values(Options) {}
701
702template <class Opt>voidapply(Opt &O) const{
703for (constauto &Value : Values)
704 O.getParser().addLiteralOption(Value.Name,Value.Value,
705Value.Description);
706 }
707};
708
709/// Helper to build a ValuesClass by forwarding a variable number of arguments
710/// as an initializer list to the ValuesClass constructor.
711template <typename... OptsTy>ValuesClassvalues(OptsTy...Options) {
712returnValuesClass({Options...});
713}
714
715//===----------------------------------------------------------------------===//
716// Parameterizable parser for different data types. By default, known data types
717// (string, int, bool) have specialized parsers, that do what you would expect.
718// The default parser, used for data types that are not built-in, uses a mapping
719// table to map specific options to values, which is used, among other things,
720// to handle enum types.
721
722//--------------------------------------------------
723// This class holds all the non-generic code that we do not need replicated for
724// every instance of the generic parser. This also allows us to put stuff into
725// CommandLine.cpp
726//
727classgeneric_parser_base {
728protected:
729classGenericOptionInfo {
730public:
731GenericOptionInfo(StringRefname,StringRef helpStr)
732 :Name(name),HelpStr(helpStr) {}
733StringRefName;
734StringRefHelpStr;
735 };
736
737public:
738generic_parser_base(Option &O) :Owner(O) {}
739
740virtual~generic_parser_base() =default;
741// Base class should have virtual-destructor
742
743// Virtual function implemented by generic subclass to indicate how many
744// entries are in Values.
745//
746virtualunsignedgetNumOptions()const = 0;
747
748// Return option name N.
749virtualStringRefgetOption(unsignedN)const = 0;
750
751// Return description N
752virtualStringRefgetDescription(unsignedN)const = 0;
753
754// Return the width of the option tag for printing...
755virtualsize_tgetOptionWidth(constOption &O)const;
756
757virtualconstGenericOptionValue &getOptionValue(unsignedN)const = 0;
758
759// Print out information about this option. The to-be-maintained width is
760// specified.
761//
762virtualvoidprintOptionInfo(constOption &O,size_t GlobalWidth)const;
763
764voidprintGenericOptionDiff(constOption &O,constGenericOptionValue &V,
765constGenericOptionValue &Default,
766size_t GlobalWidth)const;
767
768// Print the value of an option and it's default.
769//
770// Template definition ensures that the option and default have the same
771// DataType (via the same AnyOptionValue).
772template <class AnyOptionValue>
773voidprintOptionDiff(constOption &O,const AnyOptionValue &V,
774const AnyOptionValue &Default,
775size_t GlobalWidth) const{
776printGenericOptionDiff(O, V,Default, GlobalWidth);
777 }
778
779voidinitialize() {}
780
781voidgetExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) {
782// If there has been no argstr specified, that means that we need to add an
783// argument for every possible option. This ensures that our options are
784// vectored to us.
785if (!Owner.hasArgStr())
786for (unsigned i = 0, e =getNumOptions(); i != e; ++i)
787 OptionNames.push_back(getOption(i));
788 }
789
790enumValueExpectedgetValueExpectedFlagDefault() const{
791// If there is an ArgStr specified, then we are of the form:
792//
793// -opt=O2 or -opt O2 or -optO2
794//
795// In which case, the value is required. Otherwise if an arg str has not
796// been specified, we are of the form:
797//
798// -O2 or O2 or -la (where -l and -a are separate options)
799//
800// If this is the case, we cannot allow a value.
801//
802if (Owner.hasArgStr())
803returnValueRequired;
804else
805returnValueDisallowed;
806 }
807
808// Return the option number corresponding to the specified
809// argument string. If the option is not found, getNumOptions() is returned.
810//
811unsignedfindOption(StringRefName);
812
813protected:
814Option &Owner;
815};
816
817// Default parser implementation - This implementation depends on having a
818// mapping of recognized options to values of some sort. In addition to this,
819// each entry in the mapping also tracks a help message that is printed with the
820// command line option for -help. Because this is a simple mapping parser, the
821// data type can be any unsupported type.
822//
823template <class DataType>classparser :publicgeneric_parser_base {
824protected:
825classOptionInfo :publicGenericOptionInfo {
826public:
827OptionInfo(StringRefname, DataType v,StringRef helpStr)
828 :GenericOptionInfo(name, helpStr),V(v) {}
829
830OptionValue<DataType>V;
831 };
832SmallVector<OptionInfo, 8>Values;
833
834public:
835parser(Option &O) :generic_parser_base(O) {}
836
837usingparser_data_type = DataType;
838
839// Implement virtual functions needed by generic_parser_base
840unsignedgetNumOptions() const override{returnunsigned(Values.size()); }
841StringRefgetOption(unsignedN) const override{returnValues[N].Name; }
842StringRefgetDescription(unsignedN) const override{
843returnValues[N].HelpStr;
844 }
845
846// Return the value of option name N.
847constGenericOptionValue &getOptionValue(unsignedN) const override{
848returnValues[N].V;
849 }
850
851// Return true on error.
852boolparse(Option &O,StringRef ArgName,StringRef Arg, DataType &V) {
853StringRef ArgVal;
854if (Owner.hasArgStr())
855 ArgVal = Arg;
856else
857 ArgVal = ArgName;
858
859for (size_t i = 0, e =Values.size(); i != e; ++i)
860if (Values[i].Name == ArgVal) {
861 V =Values[i].V.getValue();
862returnfalse;
863 }
864
865return O.error("Cannot find option named '" + ArgVal +"'!");
866 }
867
868 /// Add an entry to the mapping table.
869 ///
870template <class DT>
871voidaddLiteralOption(StringRefName,const DT &V,StringRef HelpStr) {
872#ifndef NDEBUG
873if (findOption(Name) !=Values.size())
874report_fatal_error("Option '" +Name +"' already exists!");
875#endif
876OptionInfoX(Name,static_cast<DataType>(V), HelpStr);
877Values.push_back(X);
878AddLiteralOption(Owner,Name);
879 }
880
881 /// Remove the specified option.
882 ///
883voidremoveLiteralOption(StringRefName) {
884unsignedN =findOption(Name);
885assert(N !=Values.size() &&"Option not found!");
886Values.erase(Values.begin() +N);
887 }
888};
889
890//--------------------------------------------------
891// Super class of parsers to provide boilerplate code
892//
893classbasic_parser_impl {// non-template implementation of basic_parser<t>
894public:
895basic_parser_impl(Option &) {}
896
897virtual~basic_parser_impl() =default;
898
899enumValueExpectedgetValueExpectedFlagDefault() const{
900returnValueRequired;
901 }
902
903voidgetExtraOptionNames(SmallVectorImpl<StringRef> &) {}
904
905voidinitialize() {}
906
907// Return the width of the option tag for printing...
908size_tgetOptionWidth(constOption &O)const;
909
910// Print out information about this option. The to-be-maintained width is
911// specified.
912//
913voidprintOptionInfo(constOption &O,size_t GlobalWidth)const;
914
915// Print a placeholder for options that don't yet support printOptionDiff().
916voidprintOptionNoValue(constOption &O,size_t GlobalWidth)const;
917
918// Overload in subclass to provide a better default value.
919virtualStringRefgetValueName() const{return"value"; }
920
921// An out-of-line virtual method to provide a 'home' for this class.
922virtualvoidanchor();
923
924protected:
925// A helper for basic_parser::printOptionDiff.
926voidprintOptionName(constOption &O,size_t GlobalWidth)const;
927};
928
929// The real basic parser is just a template wrapper that provides a typedef for
930// the provided data type.
931//
932template <class DataType>classbasic_parser :publicbasic_parser_impl {
933public:
934usingparser_data_type = DataType;
935usingOptVal =OptionValue<DataType>;
936
937basic_parser(Option &O) :basic_parser_impl(O) {}
938};
939
940//--------------------------------------------------
941
942externtemplateclassbasic_parser<bool>;
943
944template <>classparser<bool> :publicbasic_parser<bool> {
945public:
946parser(Option &O) :basic_parser(O) {}
947
948// Return true on error.
949boolparse(Option &O,StringRef ArgName,StringRef Arg,bool &Val);
950
951voidinitialize() {}
952
953enumValueExpectedgetValueExpectedFlagDefault() const{
954returnValueOptional;
955 }
956
957// Do not print =<value> at all.
958StringRefgetValueName() const override{returnStringRef(); }
959
960voidprintOptionDiff(constOption &O,bool V,OptValDefault,
961size_t GlobalWidth)const;
962
963// An out-of-line virtual method to provide a 'home' for this class.
964voidanchor()override;
965};
966
967//--------------------------------------------------
968
969externtemplateclassbasic_parser<boolOrDefault>;
970
971template <>classparser<boolOrDefault> :publicbasic_parser<boolOrDefault> {
972public:
973parser(Option &O) :basic_parser(O) {}
974
975// Return true on error.
976boolparse(Option &O,StringRef ArgName,StringRef Arg,boolOrDefault &Val);
977
978enumValueExpectedgetValueExpectedFlagDefault() const{
979returnValueOptional;
980 }
981
982// Do not print =<value> at all.
983StringRefgetValueName() const override{returnStringRef(); }
984
985voidprintOptionDiff(constOption &O,boolOrDefault V,OptValDefault,
986size_t GlobalWidth)const;
987
988// An out-of-line virtual method to provide a 'home' for this class.
989voidanchor()override;
990};
991
992//--------------------------------------------------
993
994externtemplateclassbasic_parser<int>;
995
996template <>classparser<int> :publicbasic_parser<int> {
997public:
998parser(Option &O) :basic_parser(O) {}
999
1000// Return true on error.
1001boolparse(Option &O,StringRef ArgName,StringRef Arg,int &Val);
1002
1003// Overload in subclass to provide a better default value.
1004StringRefgetValueName() const override{return"int"; }
1005
1006voidprintOptionDiff(constOption &O,int V,OptValDefault,
1007size_t GlobalWidth)const;
1008
1009// An out-of-line virtual method to provide a 'home' for this class.
1010voidanchor()override;
1011};
1012
1013//--------------------------------------------------
1014
1015externtemplateclassbasic_parser<long>;
1016
1017template <>classparser<long> final :publicbasic_parser<long> {
1018public:
1019parser(Option &O) :basic_parser(O) {}
1020
1021// Return true on error.
1022boolparse(Option &O,StringRef ArgName,StringRef Arg,long &Val);
1023
1024// Overload in subclass to provide a better default value.
1025StringRefgetValueName() const override{return"long"; }
1026
1027voidprintOptionDiff(constOption &O,long V,OptValDefault,
1028size_t GlobalWidth)const;
1029
1030// An out-of-line virtual method to provide a 'home' for this class.
1031voidanchor()override;
1032};
1033
1034//--------------------------------------------------
1035
1036externtemplateclassbasic_parser<long long>;
1037
1038template <>classparser<long long> :publicbasic_parser<long long> {
1039public:
1040parser(Option &O) :basic_parser(O) {}
1041
1042// Return true on error.
1043boolparse(Option &O,StringRef ArgName,StringRef Arg,longlong &Val);
1044
1045// Overload in subclass to provide a better default value.
1046StringRefgetValueName() const override{return"long"; }
1047
1048voidprintOptionDiff(constOption &O,longlong V,OptValDefault,
1049size_t GlobalWidth)const;
1050
1051// An out-of-line virtual method to provide a 'home' for this class.
1052voidanchor()override;
1053};
1054
1055//--------------------------------------------------
1056
1057externtemplateclassbasic_parser<unsigned>;
1058
1059template <>classparser<unsigned> :publicbasic_parser<unsigned> {
1060public:
1061parser(Option &O) :basic_parser(O) {}
1062
1063// Return true on error.
1064boolparse(Option &O,StringRef ArgName,StringRef Arg,unsigned &Val);
1065
1066// Overload in subclass to provide a better default value.
1067StringRefgetValueName() const override{return"uint"; }
1068
1069voidprintOptionDiff(constOption &O,unsigned V,OptValDefault,
1070size_t GlobalWidth)const;
1071
1072// An out-of-line virtual method to provide a 'home' for this class.
1073voidanchor()override;
1074};
1075
1076//--------------------------------------------------
1077
1078externtemplateclassbasic_parser<unsigned long>;
1079
1080template <>
1081classparser<unsigned long> final :publicbasic_parser<unsigned long> {
1082public:
1083parser(Option &O) :basic_parser(O) {}
1084
1085// Return true on error.
1086boolparse(Option &O,StringRef ArgName,StringRef Arg,unsignedlong &Val);
1087
1088// Overload in subclass to provide a better default value.
1089StringRefgetValueName() const override{return"ulong"; }
1090
1091voidprintOptionDiff(constOption &O,unsignedlong V,OptValDefault,
1092size_t GlobalWidth)const;
1093
1094// An out-of-line virtual method to provide a 'home' for this class.
1095voidanchor()override;
1096};
1097
1098//--------------------------------------------------
1099
1100externtemplateclassbasic_parser<unsigned long long>;
1101
1102template <>
1103classparser<unsigned long long> :publicbasic_parser<unsigned long long> {
1104public:
1105parser(Option &O) :basic_parser(O) {}
1106
1107// Return true on error.
1108boolparse(Option &O,StringRef ArgName,StringRef Arg,
1109unsignedlonglong &Val);
1110
1111// Overload in subclass to provide a better default value.
1112StringRefgetValueName() const override{return"ulong"; }
1113
1114voidprintOptionDiff(constOption &O,unsignedlonglong V,OptValDefault,
1115size_t GlobalWidth)const;
1116
1117// An out-of-line virtual method to provide a 'home' for this class.
1118voidanchor()override;
1119};
1120
1121//--------------------------------------------------
1122
1123externtemplateclassbasic_parser<double>;
1124
1125template <>classparser<double> :publicbasic_parser<double> {
1126public:
1127parser(Option &O) :basic_parser(O) {}
1128
1129// Return true on error.
1130boolparse(Option &O,StringRef ArgName,StringRef Arg,double &Val);
1131
1132// Overload in subclass to provide a better default value.
1133StringRefgetValueName() const override{return"number"; }
1134
1135voidprintOptionDiff(constOption &O,double V,OptValDefault,
1136size_t GlobalWidth)const;
1137
1138// An out-of-line virtual method to provide a 'home' for this class.
1139voidanchor()override;
1140};
1141
1142//--------------------------------------------------
1143
1144externtemplateclassbasic_parser<float>;
1145
1146template <>classparser<float> :publicbasic_parser<float> {
1147public:
1148parser(Option &O) :basic_parser(O) {}
1149
1150// Return true on error.
1151boolparse(Option &O,StringRef ArgName,StringRef Arg,float &Val);
1152
1153// Overload in subclass to provide a better default value.
1154StringRefgetValueName() const override{return"number"; }
1155
1156voidprintOptionDiff(constOption &O,float V,OptValDefault,
1157size_t GlobalWidth)const;
1158
1159// An out-of-line virtual method to provide a 'home' for this class.
1160voidanchor()override;
1161};
1162
1163//--------------------------------------------------
1164
1165externtemplateclassbasic_parser<std::string>;
1166
1167template <>classparser<std::string> :publicbasic_parser<std::string> {
1168public:
1169parser(Option &O) :basic_parser(O) {}
1170
1171// Return true on error.
1172boolparse(Option &,StringRef,StringRef Arg, std::string &Value) {
1173Value = Arg.str();
1174returnfalse;
1175 }
1176
1177// Overload in subclass to provide a better default value.
1178StringRefgetValueName() const override{return"string"; }
1179
1180voidprintOptionDiff(constOption &O,StringRef V,constOptVal &Default,
1181size_t GlobalWidth)const;
1182
1183// An out-of-line virtual method to provide a 'home' for this class.
1184voidanchor()override;
1185};
1186
1187//--------------------------------------------------
1188
1189externtemplateclassbasic_parser<char>;
1190
1191template <>classparser<char> :publicbasic_parser<char> {
1192public:
1193parser(Option &O) :basic_parser(O) {}
1194
1195// Return true on error.
1196boolparse(Option &,StringRef,StringRef Arg,char &Value) {
1197Value = Arg[0];
1198returnfalse;
1199 }
1200
1201// Overload in subclass to provide a better default value.
1202StringRefgetValueName() const override{return"char"; }
1203
1204voidprintOptionDiff(constOption &O,char V,OptValDefault,
1205size_t GlobalWidth)const;
1206
1207// An out-of-line virtual method to provide a 'home' for this class.
1208voidanchor()override;
1209};
1210
1211//--------------------------------------------------
1212// This collection of wrappers is the intermediary between class opt and class
1213// parser to handle all the template nastiness.
1214
1215// This overloaded function is selected by the generic parser.
1216template <class ParserClass,class DT>
1217voidprintOptionDiff(constOption &O,constgeneric_parser_base &P,const DT &V,
1218constOptionValue<DT> &Default,size_t GlobalWidth) {
1219OptionValue<DT> OV = V;
1220P.printOptionDiff(O, OV,Default, GlobalWidth);
1221}
1222
1223// This is instantiated for basic parsers when the parsed value has a different
1224// type than the option value. e.g. HelpPrinter.
1225template <class ParserDT,class ValDT>structOptionDiffPrinter {
1226voidprint(constOption &O,constparser<ParserDT> &P,const ValDT &/*V*/,
1227constOptionValue<ValDT> &/*Default*/,size_t GlobalWidth) {
1228P.printOptionNoValue(O, GlobalWidth);
1229 }
1230};
1231
1232// This is instantiated for basic parsers when the parsed value has the same
1233// type as the option value.
1234template <class DT>structOptionDiffPrinter<DT, DT> {
1235voidprint(constOption &O,constparser<DT> &P,const DT &V,
1236constOptionValue<DT> &Default,size_t GlobalWidth) {
1237P.printOptionDiff(O, V,Default, GlobalWidth);
1238 }
1239};
1240
1241// This overloaded function is selected by the basic parser, which may parse a
1242// different type than the option type.
1243template <class ParserClass,class ValDT>
1244voidprintOptionDiff(
1245constOption &O,
1246constbasic_parser<typename ParserClass::parser_data_type> &P,
1247const ValDT &V,constOptionValue<ValDT> &Default,size_t GlobalWidth) {
1248
1249OptionDiffPrinter<typename ParserClass::parser_data_type, ValDT>printer;
1250printer.print(O,static_cast<constParserClass &>(P), V,Default,
1251 GlobalWidth);
1252}
1253
1254//===----------------------------------------------------------------------===//
1255// This class is used because we must use partial specialization to handle
1256// literal string arguments specially (const char* does not correctly respond to
1257// the apply method). Because the syntax to use this is a pain, we have the
1258// 'apply' method below to handle the nastiness...
1259//
1260template <class Mod>structapplicator {
1261template <class Opt>staticvoidopt(constMod &M, Opt &O) { M.apply(O); }
1262};
1263
1264// Handle const char* as a special case...
1265template <unsigned n>structapplicator<char[n]> {
1266template <class Opt>staticvoidopt(StringRef Str, Opt &O) {
1267 O.setArgStr(Str);
1268 }
1269};
1270template <unsigned n>structapplicator<const char[n]> {
1271template <class Opt>staticvoidopt(StringRef Str, Opt &O) {
1272 O.setArgStr(Str);
1273 }
1274};
1275template <>structapplicator<StringRef > {
1276template <class Opt>staticvoidopt(StringRef Str, Opt &O) {
1277 O.setArgStr(Str);
1278 }
1279};
1280
1281template <>structapplicator<NumOccurrencesFlag> {
1282staticvoidopt(NumOccurrencesFlagN,Option &O) {
1283 O.setNumOccurrencesFlag(N);
1284 }
1285};
1286
1287template <>structapplicator<ValueExpected> {
1288staticvoidopt(ValueExpected VE,Option &O) { O.setValueExpectedFlag(VE); }
1289};
1290
1291template <>structapplicator<OptionHidden> {
1292staticvoidopt(OptionHidden OH,Option &O) { O.setHiddenFlag(OH); }
1293};
1294
1295template <>structapplicator<FormattingFlags> {
1296staticvoidopt(FormattingFlags FF,Option &O) { O.setFormattingFlag(FF); }
1297};
1298
1299template <>structapplicator<MiscFlags> {
1300staticvoidopt(MiscFlags MF,Option &O) {
1301assert((MF !=Grouping || O.ArgStr.size() == 1) &&
1302"cl::Grouping can only apply to single character Options.");
1303 O.setMiscFlag(MF);
1304 }
1305};
1306
1307// Apply modifiers to an option in a type safe way.
1308template <classOpt,classMod,class... Mods>
1309voidapply(Opt *O,constMod &M,const Mods &... Ms) {
1310applicator<Mod>::opt(M, *O);
1311apply(O, Ms...);
1312}
1313
1314template <class Opt,class Mod>voidapply(Opt *O,constMod &M) {
1315applicator<Mod>::opt(M, *O);
1316}
1317
1318//===----------------------------------------------------------------------===//
1319// Default storage class definition: external storage. This implementation
1320// assumes the user will specify a variable to store the data into with the
1321// cl::location(x) modifier.
1322//
1323template <class DataType,bool ExternalStorage,bool isClass>
1324classopt_storage {
1325 DataType *Location =nullptr;// Where to store the object...
1326OptionValue<DataType> Default;
1327
1328void check_location() const{
1329assert(Location &&"cl::location(...) not specified for a command "
1330"line option with external storage, "
1331"or cl::init specified before cl::location()!!");
1332 }
1333
1334public:
1335opt_storage() =default;
1336
1337boolsetLocation(Option &O, DataType &L) {
1338if (Location)
1339return O.error("cl::location(x) specified more than once!");
1340 Location = &L;
1341 Default = L;
1342returnfalse;
1343 }
1344
1345template <class T>voidsetValue(constT &V,bool initial =false) {
1346 check_location();
1347 *Location = V;
1348if (initial)
1349 Default = V;
1350 }
1351
1352 DataType &getValue() {
1353 check_location();
1354return *Location;
1355 }
1356const DataType &getValue() const{
1357 check_location();
1358return *Location;
1359 }
1360
1361operator DataType() const{return this->getValue(); }
1362
1363constOptionValue<DataType> &getDefault() const{return Default; }
1364};
1365
1366// Define how to hold a class type object, such as a string. Since we can
1367// inherit from a class, we do so. This makes us exactly compatible with the
1368// object in all cases that it is used.
1369//
1370template <class DataType>
1371classopt_storage<DataType,false,true> :public DataType {
1372public:
1373OptionValue<DataType>Default;
1374
1375template <class T>voidsetValue(constT &V,bool initial =false) {
1376 DataType::operator=(V);
1377if (initial)
1378 Default = V;
1379 }
1380
1381 DataType &getValue() {return *this; }
1382const DataType &getValue() const{return *this; }
1383
1384constOptionValue<DataType> &getDefault() const{return Default; }
1385};
1386
1387// Define a partial specialization to handle things we cannot inherit from. In
1388// this case, we store an instance through containment, and overload operators
1389// to get at the value.
1390//
1391template <class DataType>classopt_storage<DataType,false,false> {
1392public:
1393 DataTypeValue;
1394OptionValue<DataType>Default;
1395
1396// Make sure we initialize the value with the default constructor for the
1397// type.
1398opt_storage() :Value(DataType()), Default() {}
1399
1400template <class T>voidsetValue(constT &V,bool initial =false) {
1401Value = V;
1402if (initial)
1403 Default = V;
1404 }
1405 DataType &getValue() {returnValue; }
1406 DataTypegetValue() const{returnValue; }
1407
1408constOptionValue<DataType> &getDefault() const{return Default; }
1409
1410operator DataType() const{returngetValue(); }
1411
1412// If the datatype is a pointer, support -> on it.
1413 DataTypeoperator->() const{returnValue; }
1414};
1415
1416//===----------------------------------------------------------------------===//
1417// A scalar command line option.
1418//
1419template <classDataType,bool ExternalStorage =false,
1420classParserClass = parser<DataType>>
1421classopt
1422 :publicOption,
1423publicopt_storage<DataType, ExternalStorage, std::is_class_v<DataType>> {
1424 ParserClass Parser;
1425
1426bool handleOccurrence(unsigned pos,StringRef ArgName,
1427StringRef Arg) override{
1428typename ParserClass::parser_data_type Val =
1429typename ParserClass::parser_data_type();
1430if (Parser.parse(*this, ArgName, Arg, Val))
1431returntrue;// Parse error!
1432 this->setValue(Val);
1433 this->setPosition(pos);
1434Callback(Val);
1435returnfalse;
1436 }
1437
1438enumValueExpected getValueExpectedFlagDefault() const override{
1439return Parser.getValueExpectedFlagDefault();
1440 }
1441
1442void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override{
1443return Parser.getExtraOptionNames(OptionNames);
1444 }
1445
1446// Forward printing stuff to the parser...
1447size_t getOptionWidth() const override{
1448return Parser.getOptionWidth(*this);
1449 }
1450
1451void printOptionInfo(size_t GlobalWidth) const override{
1452 Parser.printOptionInfo(*this, GlobalWidth);
1453 }
1454
1455void printOptionValue(size_t GlobalWidth,bool Force) const override{
1456if (Force || !this->getDefault().compare(this->getValue())) {
1457 cl::printOptionDiff<ParserClass>(*this, Parser, this->getValue(),
1458 this->getDefault(), GlobalWidth);
1459 }
1460 }
1461
1462template <class T,class = std::enable_if_t<std::is_assignable_v<T &, T>>>
1463void setDefaultImpl() {
1464constOptionValue<DataType> &V = this->getDefault();
1465if (V.hasValue())
1466 this->setValue(V.getValue());
1467else
1468 this->setValue(T());
1469 }
1470
1471template <class T,class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
1472void setDefaultImpl(...) {}
1473
1474void setDefault() override{ setDefaultImpl<DataType>(); }
1475
1476void done() {
1477addArgument();
1478 Parser.initialize();
1479 }
1480
1481public:
1482// Command line options should not be copyable
1483opt(constopt &) =delete;
1484opt &operator=(constopt &) =delete;
1485
1486// setInitialValue - Used by the cl::init modifier...
1487voidsetInitialValue(const DataType &V) { this->setValue(V,true); }
1488
1489 ParserClass &getParser() {return Parser; }
1490
1491template <class T> DataType &operator=(constT &Val) {
1492 this->setValue(Val);
1493Callback(Val);
1494return this->getValue();
1495 }
1496
1497template <class... Mods>
1498explicitopt(const Mods &... Ms)
1499 :Option(llvm::cl::Optional,NotHidden), Parser(*this) {
1500apply(this, Ms...);
1501 done();
1502 }
1503
1504voidsetCallback(
1505 std::function<void(consttypename ParserClass::parser_data_type &)> CB) {
1506Callback = CB;
1507 }
1508
1509 std::function<void(consttypename ParserClass::parser_data_type &)>Callback =
1510 [](consttypename ParserClass::parser_data_type &) {};
1511};
1512
1513externtemplateclassopt<unsigned>;
1514externtemplateclassopt<int>;
1515externtemplateclassopt<std::string>;
1516externtemplateclassopt<char>;
1517externtemplateclassopt<bool>;
1518
1519//===----------------------------------------------------------------------===//
1520// Default storage class definition: external storage. This implementation
1521// assumes the user will specify a variable to store the data into with the
1522// cl::location(x) modifier.
1523//
1524template <class DataType,class StorageClass>classlist_storage {
1525StorageClass *Location =nullptr;// Where to store the object...
1526 std::vector<OptionValue<DataType>>Default =
1527 std::vector<OptionValue<DataType>>();
1528bool DefaultAssigned =false;
1529
1530public:
1531list_storage() =default;
1532
1533voidclear() {}
1534
1535boolsetLocation(Option &O,StorageClass &L) {
1536if (Location)
1537return O.error("cl::location(x) specified more than once!");
1538 Location = &L;
1539returnfalse;
1540 }
1541
1542template <class T>voidaddValue(constT &V,bool initial =false) {
1543assert(Location !=nullptr &&
1544"cl::location(...) not specified for a command "
1545"line option with external storage!");
1546 Location->push_back(V);
1547if (initial)
1548Default.push_back(V);
1549 }
1550
1551const std::vector<OptionValue<DataType>> &getDefault() const{
1552returnDefault;
1553 }
1554
1555voidassignDefault() { DefaultAssigned =true; }
1556voidoverwriteDefault() { DefaultAssigned =false; }
1557boolisDefaultAssigned() {return DefaultAssigned; }
1558};
1559
1560// Define how to hold a class type object, such as a string.
1561// Originally this code inherited from std::vector. In transitioning to a new
1562// API for command line options we should change this. The new implementation
1563// of this list_storage specialization implements the minimum subset of the
1564// std::vector API required for all the current clients.
1565//
1566// FIXME: Reduce this API to a more narrow subset of std::vector
1567//
1568template <class DataType>classlist_storage<DataType,bool> {
1569 std::vector<DataType> Storage;
1570 std::vector<OptionValue<DataType>> Default;
1571bool DefaultAssigned =false;
1572
1573public:
1574usingiterator =typename std::vector<DataType>::iterator;
1575
1576iteratorbegin() {return Storage.begin(); }
1577iteratorend() {return Storage.end(); }
1578
1579usingconst_iterator =typename std::vector<DataType>::const_iterator;
1580
1581const_iteratorbegin() const{return Storage.begin(); }
1582const_iteratorend() const{return Storage.end(); }
1583
1584usingsize_type =typename std::vector<DataType>::size_type;
1585
1586size_typesize() const{return Storage.size(); }
1587
1588boolempty() const{return Storage.empty(); }
1589
1590voidpush_back(const DataType &value) { Storage.push_back(value); }
1591voidpush_back(DataType &&value) { Storage.push_back(value); }
1592
1593usingreference =typename std::vector<DataType>::reference;
1594usingconst_reference =typename std::vector<DataType>::const_reference;
1595
1596referenceoperator[](size_type pos) {return Storage[pos]; }
1597const_referenceoperator[](size_type pos) const{return Storage[pos]; }
1598
1599voidclear() {
1600 Storage.clear();
1601 }
1602
1603iteratorerase(const_iterator pos) {return Storage.erase(pos); }
1604iteratorerase(const_iterator first,const_iterator last) {
1605return Storage.erase(first, last);
1606 }
1607
1608iteratorerase(iterator pos) {return Storage.erase(pos); }
1609iteratorerase(iterator first,iterator last) {
1610return Storage.erase(first, last);
1611 }
1612
1613iteratorinsert(const_iterator pos,const DataType &value) {
1614return Storage.insert(pos,value);
1615 }
1616iteratorinsert(const_iterator pos, DataType &&value) {
1617return Storage.insert(pos,value);
1618 }
1619
1620iteratorinsert(iterator pos,const DataType &value) {
1621return Storage.insert(pos,value);
1622 }
1623iteratorinsert(iterator pos, DataType &&value) {
1624return Storage.insert(pos,value);
1625 }
1626
1627referencefront() {return Storage.front(); }
1628const_referencefront() const{return Storage.front(); }
1629
1630operator std::vector<DataType> &() {return Storage; }
1631operatorArrayRef<DataType>() const{return Storage; }
1632 std::vector<DataType> *operator&() {return &Storage; }
1633const std::vector<DataType> *operator&() const{return &Storage; }
1634
1635template <class T>voidaddValue(constT &V,bool initial =false) {
1636 Storage.push_back(V);
1637if (initial)
1638 Default.push_back(OptionValue<DataType>(V));
1639 }
1640
1641const std::vector<OptionValue<DataType>> &getDefault() const{
1642return Default;
1643 }
1644
1645voidassignDefault() { DefaultAssigned =true; }
1646voidoverwriteDefault() { DefaultAssigned =false; }
1647boolisDefaultAssigned() {return DefaultAssigned; }
1648};
1649
1650//===----------------------------------------------------------------------===//
1651// A list of command line options.
1652//
1653template <classDataType,classStorageClass =bool,
1654classParserClass = parser<DataType>>
1655classlist :publicOption,publiclist_storage<DataType, StorageClass> {
1656 std::vector<unsigned> Positions;
1657 ParserClass Parser;
1658
1659enumValueExpected getValueExpectedFlagDefault() const override{
1660return Parser.getValueExpectedFlagDefault();
1661 }
1662
1663void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override{
1664return Parser.getExtraOptionNames(OptionNames);
1665 }
1666
1667bool handleOccurrence(unsigned pos,StringRef ArgName,
1668StringRef Arg) override{
1669typename ParserClass::parser_data_type Val =
1670typename ParserClass::parser_data_type();
1671if (list_storage<DataType, StorageClass>::isDefaultAssigned()) {
1672clear();
1673list_storage<DataType, StorageClass>::overwriteDefault();
1674 }
1675if (Parser.parse(*this, ArgName, Arg, Val))
1676returntrue;// Parse Error!
1677list_storage<DataType, StorageClass>::addValue(Val);
1678setPosition(pos);
1679 Positions.push_back(pos);
1680Callback(Val);
1681returnfalse;
1682 }
1683
1684// Forward printing stuff to the parser...
1685size_t getOptionWidth() const override{
1686return Parser.getOptionWidth(*this);
1687 }
1688
1689void printOptionInfo(size_t GlobalWidth) const override{
1690 Parser.printOptionInfo(*this, GlobalWidth);
1691 }
1692
1693// Unimplemented: list options don't currently store their default value.
1694void printOptionValue(size_t/*GlobalWidth*/,bool/*Force*/) const override{
1695 }
1696
1697void setDefault() override{
1698 Positions.clear();
1699list_storage<DataType, StorageClass>::clear();
1700for (auto &Val :list_storage<DataType, StorageClass>::getDefault())
1701list_storage<DataType, StorageClass>::addValue(Val.getValue());
1702 }
1703
1704void done() {
1705addArgument();
1706 Parser.initialize();
1707 }
1708
1709public:
1710// Command line options should not be copyable
1711list(constlist &) =delete;
1712list &operator=(constlist &) =delete;
1713
1714 ParserClass &getParser() {return Parser; }
1715
1716unsignedgetPosition(unsigned optnum) const{
1717assert(optnum < this->size() &&"Invalid option index");
1718return Positions[optnum];
1719 }
1720
1721voidclear() {
1722 Positions.clear();
1723list_storage<DataType, StorageClass>::clear();
1724 }
1725
1726// setInitialValues - Used by the cl::list_init modifier...
1727voidsetInitialValues(ArrayRef<DataType> Vs) {
1728assert(!(list_storage<DataType, StorageClass>::isDefaultAssigned()) &&
1729"Cannot have two default values");
1730list_storage<DataType, StorageClass>::assignDefault();
1731for (auto &Val : Vs)
1732list_storage<DataType, StorageClass>::addValue(Val,true);
1733 }
1734
1735voidsetNumAdditionalVals(unsigned n) {Option::setNumAdditionalVals(n); }
1736
1737template <class... Mods>
1738explicitlist(const Mods &... Ms)
1739 :Option(ZeroOrMore,NotHidden), Parser(*this) {
1740apply(this, Ms...);
1741 done();
1742 }
1743
1744voidsetCallback(
1745 std::function<void(consttypename ParserClass::parser_data_type &)> CB) {
1746Callback = CB;
1747 }
1748
1749 std::function<void(consttypename ParserClass::parser_data_type &)>Callback =
1750 [](consttypename ParserClass::parser_data_type &) {};
1751};
1752
1753// Modifier to set the number of additional values.
1754structmulti_val {
1755unsignedAdditionalVals;
1756explicitmulti_val(unsignedN) :AdditionalVals(N) {}
1757
1758template <typename D,typename S,typename P>
1759voidapply(list<D, S, P> &L) const{
1760 L.setNumAdditionalVals(AdditionalVals);
1761 }
1762};
1763
1764//===----------------------------------------------------------------------===//
1765// Default storage class definition: external storage. This implementation
1766// assumes the user will specify a variable to store the data into with the
1767// cl::location(x) modifier.
1768//
1769template <class DataType,class StorageClass>classbits_storage {
1770unsigned *Location =nullptr;// Where to store the bits...
1771
1772template <class T>staticunsigned Bit(constT &V) {
1773unsigned BitPos =static_cast<unsigned>(V);
1774assert(BitPos <sizeof(unsigned) * CHAR_BIT &&
1775"enum exceeds width of bit vector!");
1776return 1 << BitPos;
1777 }
1778
1779public:
1780bits_storage() =default;
1781
1782boolsetLocation(Option &O,unsigned &L) {
1783if (Location)
1784return O.error("cl::location(x) specified more than once!");
1785 Location = &L;
1786returnfalse;
1787 }
1788
1789template <class T>voidaddValue(constT &V) {
1790assert(Location !=nullptr &&
1791"cl::location(...) not specified for a command "
1792"line option with external storage!");
1793 *Location |= Bit(V);
1794 }
1795
1796unsignedgetBits() {return *Location; }
1797
1798voidclear() {
1799if (Location)
1800 *Location = 0;
1801 }
1802
1803template <class T>boolisSet(constT &V) {
1804return (*Location & Bit(V)) != 0;
1805 }
1806};
1807
1808// Define how to hold bits. Since we can inherit from a class, we do so.
1809// This makes us exactly compatible with the bits in all cases that it is used.
1810//
1811template <class DataType>classbits_storage<DataType,bool> {
1812unsigned Bits{0};// Where to store the bits...
1813
1814template <class T>staticunsigned Bit(constT &V) {
1815unsigned BitPos =static_cast<unsigned>(V);
1816assert(BitPos <sizeof(unsigned) * CHAR_BIT &&
1817"enum exceeds width of bit vector!");
1818return 1 << BitPos;
1819 }
1820
1821public:
1822template <class T>voidaddValue(constT &V) { Bits |= Bit(V); }
1823
1824unsignedgetBits() {return Bits; }
1825
1826voidclear() { Bits = 0; }
1827
1828template <class T>boolisSet(constT &V) {return (Bits & Bit(V)) != 0; }
1829};
1830
1831//===----------------------------------------------------------------------===//
1832// A bit vector of command options.
1833//
1834template <classDataType,classStorage =bool,
1835classParserClass = parser<DataType>>
1836classbits :publicOption,publicbits_storage<DataType, Storage> {
1837 std::vector<unsigned> Positions;
1838 ParserClass Parser;
1839
1840enumValueExpected getValueExpectedFlagDefault() const override{
1841return Parser.getValueExpectedFlagDefault();
1842 }
1843
1844void getExtraOptionNames(SmallVectorImpl<StringRef> &OptionNames) override{
1845return Parser.getExtraOptionNames(OptionNames);
1846 }
1847
1848bool handleOccurrence(unsigned pos,StringRef ArgName,
1849StringRef Arg) override{
1850typename ParserClass::parser_data_type Val =
1851typename ParserClass::parser_data_type();
1852if (Parser.parse(*this, ArgName, Arg, Val))
1853returntrue;// Parse Error!
1854 this->addValue(Val);
1855setPosition(pos);
1856 Positions.push_back(pos);
1857Callback(Val);
1858returnfalse;
1859 }
1860
1861// Forward printing stuff to the parser...
1862size_t getOptionWidth() const override{
1863return Parser.getOptionWidth(*this);
1864 }
1865
1866void printOptionInfo(size_t GlobalWidth) const override{
1867 Parser.printOptionInfo(*this, GlobalWidth);
1868 }
1869
1870// Unimplemented: bits options don't currently store their default values.
1871void printOptionValue(size_t/*GlobalWidth*/,bool/*Force*/) const override{
1872 }
1873
1874void setDefault() override{bits_storage<DataType, Storage>::clear(); }
1875
1876void done() {
1877addArgument();
1878 Parser.initialize();
1879 }
1880
1881public:
1882// Command line options should not be copyable
1883bits(constbits &) =delete;
1884bits &operator=(constbits &) =delete;
1885
1886 ParserClass &getParser() {return Parser; }
1887
1888unsignedgetPosition(unsigned optnum) const{
1889assert(optnum < this->size() &&"Invalid option index");
1890return Positions[optnum];
1891 }
1892
1893template <class... Mods>
1894explicitbits(const Mods &... Ms)
1895 :Option(ZeroOrMore,NotHidden), Parser(*this) {
1896apply(this, Ms...);
1897 done();
1898 }
1899
1900voidsetCallback(
1901 std::function<void(consttypename ParserClass::parser_data_type &)> CB) {
1902Callback = CB;
1903 }
1904
1905 std::function<void(consttypename ParserClass::parser_data_type &)>Callback =
1906 [](consttypename ParserClass::parser_data_type &) {};
1907};
1908
1909//===----------------------------------------------------------------------===//
1910// Aliased command line option (alias this name to a preexisting name)
1911//
1912
1913classalias :publicOption {
1914Option *AliasFor;
1915
1916bool handleOccurrence(unsigned pos,StringRef/*ArgName*/,
1917StringRef Arg) override{
1918return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
1919 }
1920
1921bool addOccurrence(unsigned pos,StringRef/*ArgName*/,StringRefValue,
1922bool MultiArg =false) override{
1923return AliasFor->addOccurrence(pos, AliasFor->ArgStr,Value, MultiArg);
1924 }
1925
1926// Handle printing stuff...
1927size_t getOptionWidth()const override;
1928void printOptionInfo(size_t GlobalWidth)const override;
1929
1930// Aliases do not need to print their values.
1931void printOptionValue(size_t/*GlobalWidth*/,bool/*Force*/) const override{
1932 }
1933
1934void setDefault() override{ AliasFor->setDefault(); }
1935
1936ValueExpected getValueExpectedFlagDefault() const override{
1937return AliasFor->getValueExpectedFlag();
1938 }
1939
1940void done() {
1941if (!hasArgStr())
1942error("cl::alias must have argument name specified!");
1943if (!AliasFor)
1944error("cl::alias must have an cl::aliasopt(option) specified!");
1945if (!Subs.empty())
1946error("cl::alias must not have cl::sub(), aliased option's cl::sub() will be used!");
1947Subs = AliasFor->Subs;
1948Categories = AliasFor->Categories;
1949addArgument();
1950 }
1951
1952public:
1953// Command line options should not be copyable
1954alias(constalias &) =delete;
1955alias &operator=(constalias &) =delete;
1956
1957voidsetAliasFor(Option &O) {
1958if (AliasFor)
1959error("cl::alias must only have one cl::aliasopt(...) specified!");
1960 AliasFor = &O;
1961 }
1962
1963template <class... Mods>
1964explicitalias(const Mods &... Ms)
1965 :Option(Optional,Hidden), AliasFor(nullptr) {
1966apply(this, Ms...);
1967 done();
1968 }
1969};
1970
1971// Modifier to set the option an alias aliases.
1972structaliasopt {
1973Option &Opt;
1974
1975explicitaliasopt(Option &O) :Opt(O) {}
1976
1977voidapply(alias &A) const{A.setAliasFor(Opt); }
1978};
1979
1980// Provide additional help at the end of the normal help output. All occurrences
1981// of cl::extrahelp will be accumulated and printed to stderr at the end of the
1982// regular help, just before exit is called.
1983structextrahelp {
1984StringRefmorehelp;
1985
1986explicitextrahelp(StringRef help);
1987};
1988
1989voidPrintVersionMessage();
1990
1991/// This function just prints the help message, exactly the same way as if the
1992/// -help or -help-hidden option had been given on the command line.
1993///
1994/// \param Hidden if true will print hidden options
1995/// \param Categorized if true print options in categories
1996voidPrintHelpMessage(boolHidden =false,bool Categorized =false);
1997
1998/// An array of optional enabled settings in the LLVM build configuration,
1999/// which may be of interest to compiler developers. For example, includes
2000/// "+assertions" if assertions are enabled. Used by printBuildConfig.
2001ArrayRef<StringRef>getCompilerBuildConfig();
2002
2003/// Prints the compiler build configuration.
2004/// Designed for compiler developers, not compiler end-users.
2005/// Intended to be used in --version output when enabled.
2006voidprintBuildConfig(raw_ostream &OS);
2007
2008//===----------------------------------------------------------------------===//
2009// Public interface for accessing registered options.
2010//
2011
2012/// Use this to get a StringMap to all registered named options
2013/// (e.g. -help).
2014///
2015/// \return A reference to the StringMap used by the cl APIs to parse options.
2016///
2017/// Access to unnamed arguments (i.e. positional) are not provided because
2018/// it is expected that the client already has access to these.
2019///
2020/// Typical usage:
2021/// \code
2022/// main(int argc,char* argv[]) {
2023/// StringMap<llvm::cl::Option*> &opts = llvm::cl::getRegisteredOptions();
2024/// assert(opts.count("help") == 1)
2025/// opts["help"]->setDescription("Show alphabetical help information")
2026/// // More code
2027/// llvm::cl::ParseCommandLineOptions(argc,argv);
2028/// //More code
2029/// }
2030/// \endcode
2031///
2032/// This interface is useful for modifying options in libraries that are out of
2033/// the control of the client. The options should be modified before calling
2034/// llvm::cl::ParseCommandLineOptions().
2035///
2036/// Hopefully this API can be deprecated soon. Any situation where options need
2037/// to be modified by tools or libraries should be handled by sane APIs rather
2038/// than just handing around a global list.
2039StringMap<Option *> &
2040getRegisteredOptions(SubCommand &Sub =SubCommand::getTopLevel());
2041
2042/// Use this to get all registered SubCommands from the provided parser.
2043///
2044/// \return A range of all SubCommand pointers registered with the parser.
2045///
2046/// Typical usage:
2047/// \code
2048/// main(int argc, char* argv[]) {
2049/// llvm::cl::ParseCommandLineOptions(argc, argv);
2050/// for (auto* S : llvm::cl::getRegisteredSubcommands()) {
2051/// if (*S) {
2052/// std::cout << "Executing subcommand: " << S->getName() << std::endl;
2053/// // Execute some function based on the name...
2054/// }
2055/// }
2056/// }
2057/// \endcode
2058///
2059/// This interface is useful for defining subcommands in libraries and
2060/// the dispatch from a single point (like in the main function).
2061iterator_range<typename SmallPtrSet<SubCommand *, 4>::iterator>
2062getRegisteredSubcommands();
2063
2064//===----------------------------------------------------------------------===//
2065// Standalone command line processing utilities.
2066//
2067
2068/// Tokenizes a command line that can contain escapes and quotes.
2069//
2070/// The quoting rules match those used by GCC and other tools that use
2071/// libiberty's buildargv() or expandargv() utilities, and do not match bash.
2072/// They differ from buildargv() on treatment of backslashes that do not escape
2073/// a special character to make it possible to accept most Windows file paths.
2074///
2075/// \param [in] Source The string to be split on whitespace with quotes.
2076/// \param [in] Saver Delegates back to the caller for saving parsed strings.
2077/// \param [in] MarkEOLs true if tokenizing a response file and you want end of
2078/// lines and end of the response file to be marked with a nullptr string.
2079/// \param [out] NewArgv All parsed strings are appended to NewArgv.
2080voidTokenizeGNUCommandLine(StringRef Source,StringSaver &Saver,
2081SmallVectorImpl<const char *> &NewArgv,
2082bool MarkEOLs =false);
2083
2084/// Tokenizes a string of Windows command line arguments, which may contain
2085/// quotes and escaped quotes.
2086///
2087/// See MSDN docs for CommandLineToArgvW for information on the quoting rules.
2088/// http://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft(v=vs.85).aspx
2089///
2090/// For handling a full Windows command line including the executable name at
2091/// the start, see TokenizeWindowsCommandLineFull below.
2092///
2093/// \param [in] Source The string to be split on whitespace with quotes.
2094/// \param [in] Saver Delegates back to the caller for saving parsed strings.
2095/// \param [in] MarkEOLs true if tokenizing a response file and you want end of
2096/// lines and end of the response file to be marked with a nullptr string.
2097/// \param [out] NewArgv All parsed strings are appended to NewArgv.
2098voidTokenizeWindowsCommandLine(StringRef Source,StringSaver &Saver,
2099SmallVectorImpl<const char *> &NewArgv,
2100bool MarkEOLs =false);
2101
2102/// Tokenizes a Windows command line while attempting to avoid copies. If no
2103/// quoting or escaping was used, this produces substrings of the original
2104/// string. If a token requires unquoting, it will be allocated with the
2105/// StringSaver.
2106voidTokenizeWindowsCommandLineNoCopy(StringRef Source,StringSaver &Saver,
2107SmallVectorImpl<StringRef> &NewArgv);
2108
2109/// Tokenizes a Windows full command line, including command name at the start.
2110///
2111/// This uses the same syntax rules as TokenizeWindowsCommandLine for all but
2112/// the first token. But the first token is expected to be parsed as the
2113/// executable file name in the way CreateProcess would do it, rather than the
2114/// way the C library startup code would do it: CreateProcess does not consider
2115/// that \ is ever an escape character (because " is not a valid filename char,
2116/// hence there's never a need to escape it to be used literally).
2117///
2118/// Parameters are the same as for TokenizeWindowsCommandLine. In particular,
2119/// if you set MarkEOLs = true, then the first word of every line will be
2120/// parsed using the special rules for command names, making this function
2121/// suitable for parsing a file full of commands to execute.
2122voidTokenizeWindowsCommandLineFull(StringRef Source,StringSaver &Saver,
2123SmallVectorImpl<const char *> &NewArgv,
2124bool MarkEOLs =false);
2125
2126/// String tokenization function type. Should be compatible with either
2127/// Windows or Unix command line tokenizers.
2128usingTokenizerCallback = void (*)(StringRef Source,StringSaver &Saver,
2129SmallVectorImpl<const char *> &NewArgv,
2130bool MarkEOLs);
2131
2132/// Tokenizes content of configuration file.
2133///
2134/// \param [in] Source The string representing content of config file.
2135/// \param [in] Saver Delegates back to the caller for saving parsed strings.
2136/// \param [out] NewArgv All parsed strings are appended to NewArgv.
2137/// \param [in] MarkEOLs Added for compatibility with TokenizerCallback.
2138///
2139/// It works like TokenizeGNUCommandLine with ability to skip comment lines.
2140///
2141voidtokenizeConfigFile(StringRef Source,StringSaver &Saver,
2142SmallVectorImpl<const char *> &NewArgv,
2143bool MarkEOLs =false);
2144
2145/// Contains options that control response file expansion.
2146classExpansionContext {
2147 /// Provides persistent storage for parsed strings.
2148StringSaver Saver;
2149
2150 /// Tokenization strategy. Typically Unix or Windows.
2151TokenizerCallback Tokenizer;
2152
2153 /// File system used for all file access when running the expansion.
2154vfs::FileSystem *FS;
2155
2156 /// Path used to resolve relative rsp files. If empty, the file system
2157 /// current directory is used instead.
2158StringRef CurrentDir;
2159
2160 /// Directories used for search of config files.
2161ArrayRef<StringRef> SearchDirs;
2162
2163 /// True if names of nested response files must be resolved relative to
2164 /// including file.
2165bool RelativeNames =false;
2166
2167 /// If true, mark end of lines and the end of the response file with nullptrs
2168 /// in the Argv vector.
2169bool MarkEOLs =false;
2170
2171 /// If true, body of config file is expanded.
2172bool InConfigFile =false;
2173
2174llvm::Error expandResponseFile(StringRef FName,
2175SmallVectorImpl<const char *> &NewArgv);
2176
2177public:
2178ExpansionContext(BumpPtrAllocator &A,TokenizerCallbackT);
2179
2180ExpansionContext &setMarkEOLs(boolX) {
2181 MarkEOLs =X;
2182return *this;
2183 }
2184
2185ExpansionContext &setRelativeNames(boolX) {
2186 RelativeNames =X;
2187return *this;
2188 }
2189
2190ExpansionContext &setCurrentDir(StringRefX) {
2191 CurrentDir =X;
2192return *this;
2193 }
2194
2195ExpansionContext &setSearchDirs(ArrayRef<StringRef>X) {
2196 SearchDirs =X;
2197return *this;
2198 }
2199
2200ExpansionContext &setVFS(vfs::FileSystem *X) {
2201 FS =X;
2202return *this;
2203 }
2204
2205 /// Looks for the specified configuration file.
2206 ///
2207 /// \param[in] FileName Name of the file to search for.
2208 /// \param[out] FilePath File absolute path, if it was found.
2209 /// \return True if file was found.
2210 ///
2211 /// If the specified file name contains a directory separator, it is searched
2212 /// for by its absolute path. Otherwise looks for file sequentially in
2213 /// directories specified by SearchDirs field.
2214boolfindConfigFile(StringRef FileName,SmallVectorImpl<char> &FilePath);
2215
2216 /// Reads command line options from the given configuration file.
2217 ///
2218 /// \param [in] CfgFile Path to configuration file.
2219 /// \param [out] Argv Array to which the read options are added.
2220 /// \return true if the file was successfully read.
2221 ///
2222 /// It reads content of the specified file, tokenizes it and expands "@file"
2223 /// commands resolving file names in them relative to the directory where
2224 /// CfgFilename resides. It also expands "<CFGDIR>" to the base path of the
2225 /// current config file.
2226ErrorreadConfigFile(StringRef CfgFile,SmallVectorImpl<const char *> &Argv);
2227
2228 /// Expands constructs "@file" in the provided array of arguments recursively.
2229ErrorexpandResponseFiles(SmallVectorImpl<const char *> &Argv);
2230};
2231
2232/// A convenience helper which concatenates the options specified by the
2233/// environment variable EnvVar and command line options, then expands
2234/// response files recursively.
2235/// \return true if all @files were expanded successfully or there were none.
2236boolexpandResponseFiles(int Argc,constchar *const *Argv,constchar *EnvVar,
2237SmallVectorImpl<const char *> &NewArgv);
2238
2239/// A convenience helper which supports the typical use case of expansion
2240/// function call.
2241boolExpandResponseFiles(StringSaver &Saver,TokenizerCallback Tokenizer,
2242SmallVectorImpl<const char *> &Argv);
2243
2244/// A convenience helper which concatenates the options specified by the
2245/// environment variable EnvVar and command line options, then expands response
2246/// files recursively. The tokenizer is a predefined GNU or Windows one.
2247/// \return true if all @files were expanded successfully or there were none.
2248boolexpandResponseFiles(int Argc,constchar *const *Argv,constchar *EnvVar,
2249StringSaver &Saver,
2250SmallVectorImpl<const char *> &NewArgv);
2251
2252/// Mark all options not part of this category as cl::ReallyHidden.
2253///
2254/// \param Category the category of options to keep displaying
2255///
2256/// Some tools (like clang-format) like to be able to hide all options that are
2257/// not specific to the tool. This function allows a tool to specify a single
2258/// option category to display in the -help output.
2259voidHideUnrelatedOptions(cl::OptionCategory &Category,
2260SubCommand &Sub =SubCommand::getTopLevel());
2261
2262/// Mark all options not part of the categories as cl::ReallyHidden.
2263///
2264/// \param Categories the categories of options to keep displaying.
2265///
2266/// Some tools (like clang-format) like to be able to hide all options that are
2267/// not specific to the tool. This function allows a tool to specify a single
2268/// option category to display in the -help output.
2269voidHideUnrelatedOptions(ArrayRef<const cl::OptionCategory *> Categories,
2270SubCommand &Sub =SubCommand::getTopLevel());
2271
2272/// Reset all command line options to a state that looks as if they have
2273/// never appeared on the command line. This is useful for being able to parse
2274/// a command line multiple times (especially useful for writing tests).
2275voidResetAllOptionOccurrences();
2276
2277/// Reset the command line parser back to its initial state. This
2278/// removes
2279/// all options, categories, and subcommands and returns the parser to a state
2280/// where no options are supported.
2281voidResetCommandLineParser();
2282
2283/// Parses `Arg` into the option handler `Handler`.
2284boolProvidePositionalOption(Option *Handler,StringRef Arg,int i);
2285
2286}// end namespace cl
2287
2288}// end namespace llvm
2289
2290#endif// LLVM_SUPPORT_COMMANDLINE_H
const
aarch64 promote const
Definition:AArch64PromoteConstant.cpp:230
StringMap.h
This file defines the StringMap class.
ArrayRef.h
true
basic Basic Alias true
Definition:BasicAliasAnalysis.cpp:1981
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
printer
dxil pretty printer
Definition:DXILPrettyPrinter.cpp:304
value
Given that RA is a live value
Definition:DeadArgumentElimination.cpp:716
Name
std::string Name
Definition:ELFObjHandler.cpp:77
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
func
global merge func
Definition:GlobalMergeFunctions.cpp:622
SpecialSubKind::string
@ string
Options
static LVOptions Options
Definition:LVOptions.cpp:25
F
#define F(x, y, z)
Definition:MD5.cpp:55
G
#define G(x, y, z)
Definition:MD5.cpp:56
T
#define T
Definition:Mips16ISelLowering.cpp:341
P
#define P(N)
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
name
static const char * name
Definition:SMEABIPass.cpp:46
STLExtras.h
This file contains some templates that are useful if you are working with the STL at all.
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
SmallPtrSet.h
This file defines the SmallPtrSet class.
SmallVector.h
This file defines the SmallVector class.
StringRef.h
StringSaver.h
error
#define error(X)
Definition:SymbolRecordMapping.cpp:14
Twine.h
T
bool
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition:Allocator.h:66
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Init
Definition:Record.h:285
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition:StringMap.h:128
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::str
std::string str() const
str - Get the contents as an std::string.
Definition:StringRef.h:229
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::StringSaver
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition:StringSaver.h:21
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::Value
Value(Type *Ty, unsigned scid)
Definition:Value.cpp:53
llvm::cl::ExpansionContext
Contains options that control response file expansion.
Definition:CommandLine.h:2146
llvm::cl::ExpansionContext::setCurrentDir
ExpansionContext & setCurrentDir(StringRef X)
Definition:CommandLine.h:2190
llvm::cl::ExpansionContext::setVFS
ExpansionContext & setVFS(vfs::FileSystem *X)
Definition:CommandLine.h:2200
llvm::cl::ExpansionContext::setMarkEOLs
ExpansionContext & setMarkEOLs(bool X)
Definition:CommandLine.h:2180
llvm::cl::ExpansionContext::setSearchDirs
ExpansionContext & setSearchDirs(ArrayRef< StringRef > X)
Definition:CommandLine.h:2195
llvm::cl::ExpansionContext::setRelativeNames
ExpansionContext & setRelativeNames(bool X)
Definition:CommandLine.h:2185
llvm::cl::ExpansionContext::findConfigFile
bool findConfigFile(StringRef FileName, SmallVectorImpl< char > &FilePath)
Looks for the specified configuration file.
Definition:CommandLine.cpp:1389
llvm::cl::ExpansionContext::expandResponseFiles
Error expandResponseFiles(SmallVectorImpl< const char * > &Argv)
Expands constructs "@file" in the provided array of arguments recursively.
Definition:CommandLine.cpp:1234
llvm::cl::ExpansionContext::readConfigFile
Error readConfigFile(StringRef CfgFile, SmallVectorImpl< const char * > &Argv)
Reads command line options from the given configuration file.
Definition:CommandLine.cpp:1426
llvm::cl::OptionCategory
Definition:CommandLine.h:179
llvm::cl::OptionCategory::OptionCategory
OptionCategory(StringRef const Name, StringRef const Description="")
Definition:CommandLine.h:187
llvm::cl::OptionCategory::getDescription
StringRef getDescription() const
Definition:CommandLine.h:194
llvm::cl::OptionCategory::getName
StringRef getName() const
Definition:CommandLine.h:193
llvm::cl::OptionValueCopy
Definition:CommandLine.h:573
llvm::cl::OptionValueCopy::operator=
OptionValueCopy & operator=(const OptionValueCopy &)=default
llvm::cl::OptionValueCopy::hasValue
bool hasValue() const
Definition:CommandLine.h:585
llvm::cl::OptionValueCopy::OptionValueCopy
OptionValueCopy()=default
llvm::cl::OptionValueCopy::compare
bool compare(const GenericOptionValue &V) const override
Definition:CommandLine.h:600
llvm::cl::OptionValueCopy::setValue
void setValue(const DataType &V)
Definition:CommandLine.h:592
llvm::cl::OptionValueCopy::~OptionValueCopy
~OptionValueCopy()=default
llvm::cl::OptionValueCopy::getValue
const DataType & getValue() const
Definition:CommandLine.h:587
llvm::cl::OptionValueCopy::OptionValueCopy
OptionValueCopy(const OptionValueCopy &)=default
llvm::cl::OptionValueCopy::compare
bool compare(const DataType &V) const
Definition:CommandLine.h:598
llvm::cl::Option
Definition:CommandLine.h:250
llvm::cl::Option::isPositional
bool isPositional() const
Definition:CommandLine.h:311
llvm::cl::Option::getExtraOptionNames
virtual void getExtraOptionNames(SmallVectorImpl< StringRef > &)
Definition:CommandLine.h:386
llvm::cl::Option::setValueExpectedFlag
void setValueExpectedFlag(enum ValueExpected Val)
Definition:CommandLine.h:326
llvm::cl::Option::setPosition
void setPosition(unsigned pos)
Definition:CommandLine.h:330
llvm::cl::Option::isConsumeAfter
bool isConsumeAfter() const
Definition:CommandLine.h:315
llvm::cl::Option::ValueStr
StringRef ValueStr
Definition:CommandLine.h:284
llvm::cl::Option::Subs
SmallPtrSet< SubCommand *, 1 > Subs
Definition:CommandLine.h:287
llvm::cl::Option::ArgStr
StringRef ArgStr
Definition:CommandLine.h:282
llvm::cl::Option::getNumOccurrences
int getNumOccurrences() const
Definition:CommandLine.h:399
llvm::cl::Option::getValueExpectedFlag
enum ValueExpected getValueExpectedFlag() const
Definition:CommandLine.h:293
llvm::cl::Option::addCategory
void addCategory(OptionCategory &C)
Definition:CommandLine.cpp:447
llvm::cl::Option::setValueStr
void setValueStr(StringRef S)
Definition:CommandLine.h:324
llvm::cl::Option::setNumOccurrencesFlag
void setNumOccurrencesFlag(enum NumOccurrencesFlag Val)
Definition:CommandLine.h:325
llvm::cl::Option::setNumAdditionalVals
void setNumAdditionalVals(unsigned n)
Definition:CommandLine.h:343
llvm::cl::Option::addOccurrence
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
Definition:CommandLine.cpp:1863
llvm::cl::Option::setDescription
void setDescription(StringRef S)
Definition:CommandLine.h:323
llvm::cl::Option::setFormattingFlag
void setFormattingFlag(enum FormattingFlags V)
Definition:CommandLine.h:328
llvm::cl::Option::setHiddenFlag
void setHiddenFlag(enum OptionHidden Val)
Definition:CommandLine.h:327
llvm::cl::Option::setMiscFlag
void setMiscFlag(enum MiscFlags M)
Definition:CommandLine.h:329
llvm::cl::Option::getFormattingFlag
enum FormattingFlags getFormattingFlag() const
Definition:CommandLine.h:301
llvm::cl::Option::printOptionInfo
virtual void printOptionInfo(size_t GlobalWidth) const =0
llvm::cl::Option::getNumOccurrencesFlag
enum NumOccurrencesFlag getNumOccurrencesFlag() const
Definition:CommandLine.h:289
llvm::cl::Option::reset
void reset()
Definition:CommandLine.cpp:458
llvm::cl::Option::Categories
SmallVector< OptionCategory *, 1 > Categories
Definition:CommandLine.h:286
llvm::cl::Option::isSink
bool isSink() const
Definition:CommandLine.h:312
llvm::cl::Option::addSubCommand
void addSubCommand(SubCommand &S)
Definition:CommandLine.h:332
llvm::cl::Option::addArgument
void addArgument()
Definition:CommandLine.cpp:431
llvm::cl::Option::setArgStr
void setArgStr(StringRef S)
Definition:CommandLine.cpp:438
llvm::cl::Option::hasArgStr
bool hasArgStr() const
Definition:CommandLine.h:310
llvm::cl::Option::isDefaultOption
bool isDefaultOption() const
Definition:CommandLine.h:313
llvm::cl::Option::getMiscFlags
unsigned getMiscFlags() const
Definition:CommandLine.h:305
llvm::cl::Option::setDefault
virtual void setDefault()=0
llvm::cl::Option::printOptionValue
virtual void printOptionValue(size_t GlobalWidth, bool Force) const =0
llvm::cl::Option::~Option
virtual ~Option()=default
llvm::cl::Option::printEnumValHelpStr
static void printEnumValHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
Definition:CommandLine.cpp:1901
llvm::cl::Option::getNumAdditionalVals
unsigned getNumAdditionalVals() const
Definition:CommandLine.h:307
llvm::cl::Option::removeArgument
void removeArgument()
Unregisters this option from the CommandLine system.
Definition:CommandLine.cpp:436
llvm::cl::Option::Option
Option(enum NumOccurrencesFlag OccurrencesFlag, enum OptionHidden Hidden)
Definition:CommandLine.h:335
llvm::cl::Option::getOptionHiddenFlag
enum OptionHidden getOptionHiddenFlag() const
Definition:CommandLine.h:297
llvm::cl::Option::error
bool error(const Twine &Message, raw_ostream &Errs)
Definition:CommandLine.h:395
llvm::cl::Option::printHelpStr
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
Definition:CommandLine.cpp:1889
llvm::cl::Option::getOptionWidth
virtual size_t getOptionWidth() const =0
llvm::cl::Option::HelpStr
StringRef HelpStr
Definition:CommandLine.h:283
llvm::cl::Option::getPosition
unsigned getPosition() const
Definition:CommandLine.h:306
llvm::cl::SubCommandGroup
Definition:CommandLine.h:239
llvm::cl::SubCommandGroup::SubCommandGroup
SubCommandGroup(std::initializer_list< SubCommand * > IL)
Definition:CommandLine.h:243
llvm::cl::SubCommandGroup::getSubCommands
ArrayRef< SubCommand * > getSubCommands() const
Definition:CommandLine.h:245
llvm::cl::SubCommand
Definition:CommandLine.h:202
llvm::cl::SubCommand::getName
StringRef getName() const
Definition:CommandLine.h:229
llvm::cl::SubCommand::SubCommand
SubCommand()=default
llvm::cl::SubCommand::SubCommand
SubCommand(StringRef Name, StringRef Description="")
Definition:CommandLine.h:212
llvm::cl::SubCommand::SinkOpts
SmallVector< Option *, 4 > SinkOpts
Definition:CommandLine.h:233
llvm::cl::SubCommand::getTopLevel
static SubCommand & getTopLevel()
Definition:CommandLine.cpp:479
llvm::cl::SubCommand::unregisterSubCommand
void unregisterSubCommand()
Definition:CommandLine.cpp:487
llvm::cl::SubCommand::getAll
static SubCommand & getAll()
Definition:CommandLine.cpp:481
llvm::cl::SubCommand::reset
void reset()
Definition:CommandLine.cpp:491
llvm::cl::SubCommand::registerSubCommand
void registerSubCommand()
Definition:CommandLine.cpp:483
llvm::cl::SubCommand::ConsumeAfterOpt
Option * ConsumeAfterOpt
Definition:CommandLine.h:236
llvm::cl::SubCommand::PositionalOpts
SmallVector< Option *, 4 > PositionalOpts
Definition:CommandLine.h:232
llvm::cl::SubCommand::OptionsMap
StringMap< Option * > OptionsMap
Definition:CommandLine.h:234
llvm::cl::SubCommand::getDescription
StringRef getDescription() const
Definition:CommandLine.h:230
llvm::cl::ValuesClass
Definition:CommandLine.h:692
llvm::cl::ValuesClass::apply
void apply(Opt &O) const
Definition:CommandLine.h:702
llvm::cl::ValuesClass::ValuesClass
ValuesClass(std::initializer_list< OptionEnumValue > Options)
Definition:CommandLine.h:699
llvm::cl::alias
Definition:CommandLine.h:1913
llvm::cl::alias::alias
alias(const alias &)=delete
llvm::cl::alias::setAliasFor
void setAliasFor(Option &O)
Definition:CommandLine.h:1957
llvm::cl::alias::operator=
alias & operator=(const alias &)=delete
llvm::cl::alias::alias
alias(const Mods &... Ms)
Definition:CommandLine.h:1964
llvm::cl::basic_parser_impl
Definition:CommandLine.h:893
llvm::cl::basic_parser_impl::printOptionInfo
void printOptionInfo(const Option &O, size_t GlobalWidth) const
Definition:CommandLine.cpp:1944
llvm::cl::basic_parser_impl::getValueExpectedFlagDefault
enum ValueExpected getValueExpectedFlagDefault() const
Definition:CommandLine.h:899
llvm::cl::basic_parser_impl::anchor
virtual void anchor()
Definition:CommandLine.cpp:83
llvm::cl::basic_parser_impl::getExtraOptionNames
void getExtraOptionNames(SmallVectorImpl< StringRef > &)
Definition:CommandLine.h:903
llvm::cl::basic_parser_impl::getValueName
virtual StringRef getValueName() const
Definition:CommandLine.h:919
llvm::cl::basic_parser_impl::~basic_parser_impl
virtual ~basic_parser_impl()=default
llvm::cl::basic_parser_impl::printOptionNoValue
void printOptionNoValue(const Option &O, size_t GlobalWidth) const
Definition:CommandLine.cpp:2245
llvm::cl::basic_parser_impl::basic_parser_impl
basic_parser_impl(Option &)
Definition:CommandLine.h:895
llvm::cl::basic_parser_impl::getOptionWidth
size_t getOptionWidth(const Option &O) const
Definition:CommandLine.cpp:1928
llvm::cl::basic_parser_impl::printOptionName
void printOptionName(const Option &O, size_t GlobalWidth) const
Definition:CommandLine.cpp:1963
llvm::cl::basic_parser_impl::initialize
void initialize()
Definition:CommandLine.h:905
llvm::cl::basic_parser
Definition:CommandLine.h:932
llvm::cl::basic_parser::basic_parser
basic_parser(Option &O)
Definition:CommandLine.h:937
llvm::cl::basic_parser::OptVal
OptionValue< DataType > OptVal
Definition:CommandLine.h:935
llvm::cl::basic_parser::parser_data_type
DataType parser_data_type
Definition:CommandLine.h:934
llvm::cl::bits_storage< DataType, bool >::isSet
bool isSet(const T &V)
Definition:CommandLine.h:1828
llvm::cl::bits_storage< DataType, bool >::addValue
void addValue(const T &V)
Definition:CommandLine.h:1822
llvm::cl::bits_storage< DataType, bool >::getBits
unsigned getBits()
Definition:CommandLine.h:1824
llvm::cl::bits_storage< DataType, bool >::clear
void clear()
Definition:CommandLine.h:1826
llvm::cl::bits_storage
Definition:CommandLine.h:1769
llvm::cl::bits_storage::getBits
unsigned getBits()
Definition:CommandLine.h:1796
llvm::cl::bits_storage::isSet
bool isSet(const T &V)
Definition:CommandLine.h:1803
llvm::cl::bits_storage::addValue
void addValue(const T &V)
Definition:CommandLine.h:1789
llvm::cl::bits_storage::clear
void clear()
Definition:CommandLine.h:1798
llvm::cl::bits_storage::setLocation
bool setLocation(Option &O, unsigned &L)
Definition:CommandLine.h:1782
llvm::cl::bits_storage::bits_storage
bits_storage()=default
llvm::cl::bits
Definition:CommandLine.h:1836
llvm::cl::bits::operator=
bits & operator=(const bits &)=delete
llvm::cl::bits::bits
bits(const Mods &... Ms)
Definition:CommandLine.h:1894
llvm::cl::bits::getParser
ParserClass & getParser()
Definition:CommandLine.h:1886
llvm::cl::bits::getPosition
unsigned getPosition(unsigned optnum) const
Definition:CommandLine.h:1888
llvm::cl::bits::setCallback
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
Definition:CommandLine.h:1900
llvm::cl::bits::Callback
std::function< void(const typename ParserClass::parser_data_type &)> Callback
Definition:CommandLine.h:1905
llvm::cl::bits::bits
bits(const bits &)=delete
llvm::cl::generic_parser_base::GenericOptionInfo
Definition:CommandLine.h:729
llvm::cl::generic_parser_base::GenericOptionInfo::GenericOptionInfo
GenericOptionInfo(StringRef name, StringRef helpStr)
Definition:CommandLine.h:731
llvm::cl::generic_parser_base::GenericOptionInfo::Name
StringRef Name
Definition:CommandLine.h:733
llvm::cl::generic_parser_base::GenericOptionInfo::HelpStr
StringRef HelpStr
Definition:CommandLine.h:734
llvm::cl::generic_parser_base
Definition:CommandLine.h:727
llvm::cl::generic_parser_base::getOptionWidth
virtual size_t getOptionWidth(const Option &O) const
Definition:CommandLine.cpp:2093
llvm::cl::generic_parser_base::generic_parser_base
generic_parser_base(Option &O)
Definition:CommandLine.h:738
llvm::cl::generic_parser_base::getDescription
virtual StringRef getDescription(unsigned N) const =0
llvm::cl::generic_parser_base::Owner
Option & Owner
Definition:CommandLine.h:814
llvm::cl::generic_parser_base::getOptionValue
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
llvm::cl::generic_parser_base::initialize
void initialize()
Definition:CommandLine.h:779
llvm::cl::generic_parser_base::getNumOptions
virtual unsigned getNumOptions() const =0
llvm::cl::generic_parser_base::getOption
virtual StringRef getOption(unsigned N) const =0
llvm::cl::generic_parser_base::printOptionDiff
void printOptionDiff(const Option &O, const AnyOptionValue &V, const AnyOptionValue &Default, size_t GlobalWidth) const
Definition:CommandLine.h:773
llvm::cl::generic_parser_base::printGenericOptionDiff
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
Definition:CommandLine.cpp:2169
llvm::cl::generic_parser_base::printOptionInfo
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
Definition:CommandLine.cpp:2116
llvm::cl::generic_parser_base::findOption
unsigned findOption(StringRef Name)
Definition:CommandLine.cpp:2069
llvm::cl::generic_parser_base::~generic_parser_base
virtual ~generic_parser_base()=default
llvm::cl::generic_parser_base::getExtraOptionNames
void getExtraOptionNames(SmallVectorImpl< StringRef > &OptionNames)
Definition:CommandLine.h:781
llvm::cl::generic_parser_base::getValueExpectedFlagDefault
enum ValueExpected getValueExpectedFlagDefault() const
Definition:CommandLine.h:790
llvm::cl::list_storage< DataType, bool >::push_back
void push_back(DataType &&value)
Definition:CommandLine.h:1591
llvm::cl::list_storage< DataType, bool >::end
iterator end()
Definition:CommandLine.h:1577
llvm::cl::list_storage< DataType, bool >::clear
void clear()
Definition:CommandLine.h:1599
llvm::cl::list_storage< DataType, bool >::assignDefault
void assignDefault()
Definition:CommandLine.h:1645
llvm::cl::list_storage< DataType, bool >::begin
iterator begin()
Definition:CommandLine.h:1576
llvm::cl::list_storage< DataType, bool >::isDefaultAssigned
bool isDefaultAssigned()
Definition:CommandLine.h:1647
llvm::cl::list_storage< DataType, bool >::const_iterator
typename std::vector< DataType >::const_iterator const_iterator
Definition:CommandLine.h:1579
llvm::cl::list_storage< DataType, bool >::const_reference
typename std::vector< DataType >::const_reference const_reference
Definition:CommandLine.h:1594
llvm::cl::list_storage< DataType, bool >::begin
const_iterator begin() const
Definition:CommandLine.h:1581
llvm::cl::list_storage< DataType, bool >::erase
iterator erase(const_iterator first, const_iterator last)
Definition:CommandLine.h:1604
llvm::cl::list_storage< DataType, bool >::insert
iterator insert(const_iterator pos, const DataType &value)
Definition:CommandLine.h:1613
llvm::cl::list_storage< DataType, bool >::erase
iterator erase(iterator first, iterator last)
Definition:CommandLine.h:1609
llvm::cl::list_storage< DataType, bool >::operator[]
const_reference operator[](size_type pos) const
Definition:CommandLine.h:1597
llvm::cl::list_storage< DataType, bool >::empty
bool empty() const
Definition:CommandLine.h:1588
llvm::cl::list_storage< DataType, bool >::addValue
void addValue(const T &V, bool initial=false)
Definition:CommandLine.h:1635
llvm::cl::list_storage< DataType, bool >::push_back
void push_back(const DataType &value)
Definition:CommandLine.h:1590
llvm::cl::list_storage< DataType, bool >::reference
typename std::vector< DataType >::reference reference
Definition:CommandLine.h:1593
llvm::cl::list_storage< DataType, bool >::operator[]
reference operator[](size_type pos)
Definition:CommandLine.h:1596
llvm::cl::list_storage< DataType, bool >::overwriteDefault
void overwriteDefault()
Definition:CommandLine.h:1646
llvm::cl::list_storage< DataType, bool >::operator&
const std::vector< DataType > * operator&() const
Definition:CommandLine.h:1633
llvm::cl::list_storage< DataType, bool >::insert
iterator insert(iterator pos, const DataType &value)
Definition:CommandLine.h:1620
llvm::cl::list_storage< DataType, bool >::size_type
typename std::vector< DataType >::size_type size_type
Definition:CommandLine.h:1584
llvm::cl::list_storage< DataType, bool >::front
const_reference front() const
Definition:CommandLine.h:1628
llvm::cl::list_storage< DataType, bool >::end
const_iterator end() const
Definition:CommandLine.h:1582
llvm::cl::list_storage< DataType, bool >::insert
iterator insert(const_iterator pos, DataType &&value)
Definition:CommandLine.h:1616
llvm::cl::list_storage< DataType, bool >::erase
iterator erase(iterator pos)
Definition:CommandLine.h:1608
llvm::cl::list_storage< DataType, bool >::operator&
std::vector< DataType > * operator&()
Definition:CommandLine.h:1632
llvm::cl::list_storage< DataType, bool >::getDefault
const std::vector< OptionValue< DataType > > & getDefault() const
Definition:CommandLine.h:1641
llvm::cl::list_storage< DataType, bool >::erase
iterator erase(const_iterator pos)
Definition:CommandLine.h:1603
llvm::cl::list_storage< DataType, bool >::insert
iterator insert(iterator pos, DataType &&value)
Definition:CommandLine.h:1623
llvm::cl::list_storage< DataType, bool >::size
size_type size() const
Definition:CommandLine.h:1586
llvm::cl::list_storage< DataType, bool >::iterator
typename std::vector< DataType >::iterator iterator
Definition:CommandLine.h:1574
llvm::cl::list_storage< DataType, bool >::front
reference front()
Definition:CommandLine.h:1627
llvm::cl::list_storage
Definition:CommandLine.h:1524
llvm::cl::list_storage::getDefault
const std::vector< OptionValue< DataType > > & getDefault() const
Definition:CommandLine.h:1551
llvm::cl::list_storage::overwriteDefault
void overwriteDefault()
Definition:CommandLine.h:1556
llvm::cl::list_storage::isDefaultAssigned
bool isDefaultAssigned()
Definition:CommandLine.h:1557
llvm::cl::list_storage::clear
void clear()
Definition:CommandLine.h:1533
llvm::cl::list_storage::addValue
void addValue(const T &V, bool initial=false)
Definition:CommandLine.h:1542
llvm::cl::list_storage::assignDefault
void assignDefault()
Definition:CommandLine.h:1555
llvm::cl::list_storage::setLocation
bool setLocation(Option &O, StorageClass &L)
Definition:CommandLine.h:1535
llvm::cl::list_storage::list_storage
list_storage()=default
llvm::cl::list
Definition:CommandLine.h:1655
llvm::cl::list::list
list(const Mods &... Ms)
Definition:CommandLine.h:1738
llvm::cl::list::setCallback
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
Definition:CommandLine.h:1744
llvm::cl::list::list
list(const list &)=delete
llvm::cl::list::setInitialValues
void setInitialValues(ArrayRef< DataType > Vs)
Definition:CommandLine.h:1727
llvm::cl::list::Callback
std::function< void(const typename ParserClass::parser_data_type &)> Callback
Definition:CommandLine.h:1749
llvm::cl::list::clear
void clear()
Definition:CommandLine.h:1721
llvm::cl::list::operator=
list & operator=(const list &)=delete
llvm::cl::list::getParser
ParserClass & getParser()
Definition:CommandLine.h:1714
llvm::cl::list::getPosition
unsigned getPosition(unsigned optnum) const
Definition:CommandLine.h:1716
llvm::cl::list::setNumAdditionalVals
void setNumAdditionalVals(unsigned n)
Definition:CommandLine.h:1735
llvm::cl::opt_storage< DataType, false, false >::Default
OptionValue< DataType > Default
Definition:CommandLine.h:1394
llvm::cl::opt_storage< DataType, false, false >::operator->
DataType operator->() const
Definition:CommandLine.h:1413
llvm::cl::opt_storage< DataType, false, false >::opt_storage
opt_storage()
Definition:CommandLine.h:1398
llvm::cl::opt_storage< DataType, false, false >::getDefault
const OptionValue< DataType > & getDefault() const
Definition:CommandLine.h:1408
llvm::cl::opt_storage< DataType, false, false >::setValue
void setValue(const T &V, bool initial=false)
Definition:CommandLine.h:1400
llvm::cl::opt_storage< DataType, false, false >::getValue
DataType & getValue()
Definition:CommandLine.h:1405
llvm::cl::opt_storage< DataType, false, false >::Value
DataType Value
Definition:CommandLine.h:1393
llvm::cl::opt_storage< DataType, false, false >::getValue
DataType getValue() const
Definition:CommandLine.h:1406
llvm::cl::opt_storage< DataType, false, true >::setValue
void setValue(const T &V, bool initial=false)
Definition:CommandLine.h:1375
llvm::cl::opt_storage< DataType, false, true >::Default
OptionValue< DataType > Default
Definition:CommandLine.h:1373
llvm::cl::opt_storage< DataType, false, true >::getValue
DataType & getValue()
Definition:CommandLine.h:1381
llvm::cl::opt_storage< DataType, false, true >::getValue
const DataType & getValue() const
Definition:CommandLine.h:1382
llvm::cl::opt_storage< DataType, false, true >::getDefault
const OptionValue< DataType > & getDefault() const
Definition:CommandLine.h:1384
llvm::cl::opt_storage
Definition:CommandLine.h:1324
llvm::cl::opt_storage::getValue
const DataType & getValue() const
Definition:CommandLine.h:1356
llvm::cl::opt_storage::opt_storage
opt_storage()=default
llvm::cl::opt_storage::setLocation
bool setLocation(Option &O, DataType &L)
Definition:CommandLine.h:1337
llvm::cl::opt_storage::setValue
void setValue(const T &V, bool initial=false)
Definition:CommandLine.h:1345
llvm::cl::opt_storage::getDefault
const OptionValue< DataType > & getDefault() const
Definition:CommandLine.h:1363
llvm::cl::opt_storage::getValue
DataType & getValue()
Definition:CommandLine.h:1352
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::cl::opt::getParser
ParserClass & getParser()
Definition:CommandLine.h:1489
llvm::cl::opt::operator=
opt & operator=(const opt &)=delete
llvm::cl::opt::setInitialValue
void setInitialValue(const DataType &V)
Definition:CommandLine.h:1487
llvm::cl::opt::setCallback
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
Definition:CommandLine.h:1504
llvm::cl::opt::opt
opt(const opt &)=delete
llvm::cl::opt::operator=
DataType & operator=(const T &Val)
Definition:CommandLine.h:1491
llvm::cl::opt::opt
opt(const Mods &... Ms)
Definition:CommandLine.h:1498
llvm::cl::opt::Callback
std::function< void(const typename ParserClass::parser_data_type &)> Callback
Definition:CommandLine.h:1509
llvm::cl::parser::OptionInfo
Definition:CommandLine.h:825
llvm::cl::parser::OptionInfo::OptionInfo
OptionInfo(StringRef name, DataType v, StringRef helpStr)
Definition:CommandLine.h:827
llvm::cl::parser::OptionInfo::V
OptionValue< DataType > V
Definition:CommandLine.h:830
llvm::cl::parser< boolOrDefault >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val)
llvm::cl::parser< boolOrDefault >::anchor
void anchor() override
llvm::cl::parser< boolOrDefault >::printOptionDiff
void printOptionDiff(const Option &O, boolOrDefault V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< boolOrDefault >::parser
parser(Option &O)
Definition:CommandLine.h:973
llvm::cl::parser< boolOrDefault >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:983
llvm::cl::parser< boolOrDefault >::getValueExpectedFlagDefault
enum ValueExpected getValueExpectedFlagDefault() const
Definition:CommandLine.h:978
llvm::cl::parser< bool >::parser
parser(Option &O)
Definition:CommandLine.h:946
llvm::cl::parser< bool >::getValueExpectedFlagDefault
enum ValueExpected getValueExpectedFlagDefault() const
Definition:CommandLine.h:953
llvm::cl::parser< bool >::printOptionDiff
void printOptionDiff(const Option &O, bool V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< bool >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val)
llvm::cl::parser< bool >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:958
llvm::cl::parser< bool >::anchor
void anchor() override
llvm::cl::parser< bool >::initialize
void initialize()
Definition:CommandLine.h:951
llvm::cl::parser< char >::parse
bool parse(Option &, StringRef, StringRef Arg, char &Value)
Definition:CommandLine.h:1196
llvm::cl::parser< char >::printOptionDiff
void printOptionDiff(const Option &O, char V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< char >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1202
llvm::cl::parser< char >::anchor
void anchor() override
llvm::cl::parser< char >::parser
parser(Option &O)
Definition:CommandLine.h:1193
llvm::cl::parser< double >::printOptionDiff
void printOptionDiff(const Option &O, double V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< double >::anchor
void anchor() override
llvm::cl::parser< double >::parser
parser(Option &O)
Definition:CommandLine.h:1127
llvm::cl::parser< double >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1133
llvm::cl::parser< double >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val)
llvm::cl::parser< float >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val)
llvm::cl::parser< float >::anchor
void anchor() override
llvm::cl::parser< float >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1154
llvm::cl::parser< float >::printOptionDiff
void printOptionDiff(const Option &O, float V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< float >::parser
parser(Option &O)
Definition:CommandLine.h:1148
llvm::cl::parser< int >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1004
llvm::cl::parser< int >::printOptionDiff
void printOptionDiff(const Option &O, int V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< int >::anchor
void anchor() override
llvm::cl::parser< int >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val)
llvm::cl::parser< int >::parser
parser(Option &O)
Definition:CommandLine.h:998
llvm::cl::parser< long >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1025
llvm::cl::parser< long >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, long &Val)
llvm::cl::parser< long >::parser
parser(Option &O)
Definition:CommandLine.h:1019
llvm::cl::parser< long >::printOptionDiff
void printOptionDiff(const Option &O, long V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< long >::anchor
void anchor() override
llvm::cl::parser< long long >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, long long &Val)
llvm::cl::parser< long long >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1046
llvm::cl::parser< long long >::printOptionDiff
void printOptionDiff(const Option &O, long long V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< long long >::anchor
void anchor() override
llvm::cl::parser< long long >::parser
parser(Option &O)
Definition:CommandLine.h:1040
llvm::cl::parser< std::string >::parser
parser(Option &O)
Definition:CommandLine.h:1169
llvm::cl::parser< std::string >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1178
llvm::cl::parser< std::string >::printOptionDiff
void printOptionDiff(const Option &O, StringRef V, const OptVal &Default, size_t GlobalWidth) const
llvm::cl::parser< std::string >::parse
bool parse(Option &, StringRef, StringRef Arg, std::string &Value)
Definition:CommandLine.h:1172
llvm::cl::parser< std::string >::anchor
void anchor() override
llvm::cl::parser< unsigned >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val)
llvm::cl::parser< unsigned >::printOptionDiff
void printOptionDiff(const Option &O, unsigned V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< unsigned >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1067
llvm::cl::parser< unsigned >::parser
parser(Option &O)
Definition:CommandLine.h:1061
llvm::cl::parser< unsigned >::anchor
void anchor() override
llvm::cl::parser< unsigned long >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1089
llvm::cl::parser< unsigned long >::printOptionDiff
void printOptionDiff(const Option &O, unsigned long V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< unsigned long >::anchor
void anchor() override
llvm::cl::parser< unsigned long >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long &Val)
llvm::cl::parser< unsigned long >::parser
parser(Option &O)
Definition:CommandLine.h:1083
llvm::cl::parser< unsigned long long >::getValueName
StringRef getValueName() const override
Definition:CommandLine.h:1112
llvm::cl::parser< unsigned long long >::parser
parser(Option &O)
Definition:CommandLine.h:1105
llvm::cl::parser< unsigned long long >::printOptionDiff
void printOptionDiff(const Option &O, unsigned long long V, OptVal Default, size_t GlobalWidth) const
llvm::cl::parser< unsigned long long >::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long long &Val)
llvm::cl::parser< unsigned long long >::anchor
void anchor() override
llvm::cl::parser
Definition:CommandLine.h:823
llvm::cl::parser::parser_data_type
DataType parser_data_type
Definition:CommandLine.h:837
llvm::cl::parser::Values
SmallVector< OptionInfo, 8 > Values
Definition:CommandLine.h:832
llvm::cl::parser::parser
parser(Option &O)
Definition:CommandLine.h:835
llvm::cl::parser::removeLiteralOption
void removeLiteralOption(StringRef Name)
Remove the specified option.
Definition:CommandLine.h:883
llvm::cl::parser::getDescription
StringRef getDescription(unsigned N) const override
Definition:CommandLine.h:842
llvm::cl::parser::addLiteralOption
void addLiteralOption(StringRef Name, const DT &V, StringRef HelpStr)
Add an entry to the mapping table.
Definition:CommandLine.h:871
llvm::cl::parser::getOptionValue
const GenericOptionValue & getOptionValue(unsigned N) const override
Definition:CommandLine.h:847
llvm::cl::parser::getOption
StringRef getOption(unsigned N) const override
Definition:CommandLine.h:841
llvm::cl::parser::parse
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
Definition:CommandLine.h:852
llvm::cl::parser::getNumOptions
unsigned getNumOptions() const override
Definition:CommandLine.h:840
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition:iterator_range.h:42
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
llvm::vfs::FileSystem
The virtual file system interface.
Definition:VirtualFileSystem.h:266
uint16_t
unsigned
iterator_range.h
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
detail
Definition:ClauseT.h:112
false
Definition:StackSlotColoring.cpp:193
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::XCOFF::StorageClass
StorageClass
Definition:XCOFF.h:170
llvm::cl::VersionPrinterTy
std::function< void(raw_ostream &)> VersionPrinterTy
Definition:CommandLine.h:75
llvm::cl::TokenizerCallback
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
Definition:CommandLine.h:2130
llvm::cl::PrintVersionMessage
void PrintVersionMessage()
Utility function for printing version number.
Definition:CommandLine.cpp:2776
llvm::cl::ExpandResponseFiles
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv)
A convenience helper which supports the typical use case of expansion function call.
Definition:CommandLine.cpp:1376
llvm::cl::expandResponseFiles
bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, SmallVectorImpl< const char * > &NewArgv)
A convenience helper which concatenates the options specified by the environment variable EnvVar and ...
llvm::cl::TokenizeWindowsCommandLine
void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a string of Windows command line arguments, which may contain quotes and escaped quotes.
Definition:CommandLine.cpp:1041
llvm::cl::list_init
list_initializer< Ty > list_init(ArrayRef< Ty > Vals)
Definition:CommandLine.h:448
llvm::cl::getGeneralCategory
OptionCategory & getGeneralCategory()
Definition:CommandLine.cpp:2662
llvm::cl::NumOccurrencesFlag
NumOccurrencesFlag
Definition:CommandLine.h:112
llvm::cl::ConsumeAfter
@ ConsumeAfter
Definition:CommandLine.h:125
llvm::cl::ZeroOrMore
@ ZeroOrMore
Definition:CommandLine.h:114
llvm::cl::Optional
@ Optional
Definition:CommandLine.h:113
llvm::cl::OneOrMore
@ OneOrMore
Definition:CommandLine.h:116
llvm::cl::Required
@ Required
Definition:CommandLine.h:115
llvm::cl::ValueExpected
ValueExpected
Definition:CommandLine.h:128
llvm::cl::ValueOptional
@ ValueOptional
Definition:CommandLine.h:130
llvm::cl::ValueDisallowed
@ ValueDisallowed
Definition:CommandLine.h:132
llvm::cl::ValueRequired
@ ValueRequired
Definition:CommandLine.h:131
llvm::cl::ResetAllOptionOccurrences
void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
Definition:CommandLine.cpp:1472
llvm::cl::SetVersionPrinter
void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Override the default (LLV...
Definition:CommandLine.cpp:2780
llvm::cl::tokenizeConfigFile
void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
Definition:CommandLine.cpp:1073
llvm::cl::OptionHidden
OptionHidden
Definition:CommandLine.h:135
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::NotHidden
@ NotHidden
Definition:CommandLine.h:136
llvm::cl::ReallyHidden
@ ReallyHidden
Definition:CommandLine.h:138
llvm::cl::getRegisteredOptions
StringMap< Option * > & getRegisteredOptions(SubCommand &Sub=SubCommand::getTopLevel())
Use this to get a StringMap to all registered named options (e.g.
Definition:CommandLine.cpp:2788
llvm::cl::ResetCommandLineParser
void ResetCommandLineParser()
Reset the command line parser back to its initial state.
Definition:CommandLine.cpp:2829
llvm::cl::ParseCommandLineOptions
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
Definition:CommandLine.cpp:1444
llvm::cl::PrintOptionValues
void PrintOptionValues()
Definition:CommandLine.cpp:2699
llvm::cl::getRegisteredSubcommands
iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
Definition:CommandLine.cpp:2797
llvm::cl::apply
void apply(Opt *O, const Mod &M, const Mods &... Ms)
Definition:CommandLine.h:1309
llvm::cl::AddLiteralOption
void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
Definition:CommandLine.cpp:423
llvm::cl::printOptionDiff
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
Definition:CommandLine.h:1217
llvm::cl::TokenizeWindowsCommandLineNoCopy
void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
Definition:CommandLine.cpp:1053
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition:CommandLine.h:711
llvm::cl::boolOrDefault
boolOrDefault
Definition:CommandLine.h:637
llvm::cl::BOU_FALSE
@ BOU_FALSE
Definition:CommandLine.h:637
llvm::cl::BOU_UNSET
@ BOU_UNSET
Definition:CommandLine.h:637
llvm::cl::BOU_TRUE
@ BOU_TRUE
Definition:CommandLine.h:637
llvm::cl::printBuildConfig
void printBuildConfig(raw_ostream &OS)
Prints the compiler build configuration.
Definition:CommandLine.cpp:2767
llvm::cl::ProvidePositionalOption
bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
Definition:CommandLine.cpp:707
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm::cl::MiscFlags
MiscFlags
Definition:CommandLine.h:162
llvm::cl::Sink
@ Sink
Definition:CommandLine.h:165
llvm::cl::CommaSeparated
@ CommaSeparated
Definition:CommandLine.h:163
llvm::cl::Grouping
@ Grouping
Definition:CommandLine.h:171
llvm::cl::DefaultOption
@ DefaultOption
Definition:CommandLine.h:174
llvm::cl::PositionalEatsArgs
@ PositionalEatsArgs
Definition:CommandLine.h:164
llvm::cl::getCompilerBuildConfig
ArrayRef< StringRef > getCompilerBuildConfig()
An array of optional enabled settings in the LLVM build configuration, which may be of interest to co...
Definition:CommandLine.cpp:2729
llvm::cl::location
LocationClass< Ty > location(Ty &L)
Definition:CommandLine.h:463
llvm::cl::callback
cb< typename detail::callback_traits< F >::result_type, typename detail::callback_traits< F >::arg_type > callback(F CB)
Definition:CommandLine.h:523
llvm::cl::HideUnrelatedOptions
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=SubCommand::getTopLevel())
Mark all options not part of this category as cl::ReallyHidden.
Definition:CommandLine.cpp:2801
llvm::cl::AddExtraVersionPrinter
void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Add an extra printer to u...
Definition:CommandLine.cpp:2784
llvm::cl::PrintHelpMessage
void PrintHelpMessage(bool Hidden=false, bool Categorized=false)
This function just prints the help message, exactly the same way as if the -help or -help-hidden opti...
Definition:CommandLine.cpp:2718
llvm::cl::TokenizeWindowsCommandLineFull
void TokenizeWindowsCommandLineFull(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows full command line, including command name at the start.
Definition:CommandLine.cpp:1061
llvm::cl::FormattingFlags
FormattingFlags
Definition:CommandLine.h:155
llvm::cl::NormalFormatting
@ NormalFormatting
Definition:CommandLine.h:156
llvm::cl::Positional
@ Positional
Definition:CommandLine.h:157
llvm::cl::Prefix
@ Prefix
Definition:CommandLine.h:158
llvm::cl::AlwaysPrefix
@ AlwaysPrefix
Definition:CommandLine.h:159
llvm::cl::TokenizeGNUCommandLine
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
Definition:CommandLine.cpp:821
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition:STLExtras.h:1697
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition:raw_ostream.cpp:907
llvm::ModRefInfo::Mod
@ Mod
The access may modify the value stored in memory.
llvm::InstructionUniformity::Default
@ Default
The result values are uniform if and only if all operands are uniform.
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858
raw_ostream.h
N
#define N
llvm::DWARFExpression::Operation::Description
Description of the encoding of one expression Op.
Definition:DWARFExpression.h:66
llvm::cl::GenericOptionValue
Definition:CommandLine.h:532
llvm::cl::GenericOptionValue::GenericOptionValue
GenericOptionValue()=default
llvm::cl::GenericOptionValue::GenericOptionValue
GenericOptionValue(const GenericOptionValue &)=default
llvm::cl::GenericOptionValue::operator=
GenericOptionValue & operator=(const GenericOptionValue &)=default
llvm::cl::GenericOptionValue::~GenericOptionValue
~GenericOptionValue()=default
llvm::cl::GenericOptionValue::compare
virtual bool compare(const GenericOptionValue &V) const =0
llvm::cl::LocationClass
Definition:CommandLine.h:455
llvm::cl::LocationClass::Loc
Ty & Loc
Definition:CommandLine.h:456
llvm::cl::LocationClass::apply
void apply(Opt &O) const
Definition:CommandLine.h:460
llvm::cl::LocationClass::LocationClass
LocationClass(Ty &L)
Definition:CommandLine.h:458
llvm::cl::OptionDiffPrinter< DT, DT >::print
void print(const Option &O, const parser< DT > &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
Definition:CommandLine.h:1235
llvm::cl::OptionDiffPrinter
Definition:CommandLine.h:1225
llvm::cl::OptionDiffPrinter::print
void print(const Option &O, const parser< ParserDT > &P, const ValDT &, const OptionValue< ValDT > &, size_t GlobalWidth)
Definition:CommandLine.h:1226
llvm::cl::OptionEnumValue
Definition:CommandLine.h:678
llvm::cl::OptionEnumValue::Value
int Value
Definition:CommandLine.h:680
llvm::cl::OptionEnumValue::Description
StringRef Description
Definition:CommandLine.h:681
llvm::cl::OptionEnumValue::Name
StringRef Name
Definition:CommandLine.h:679
llvm::cl::OptionValueBase< DataType, false >::~OptionValueBase
~OptionValueBase()=default
llvm::cl::OptionValueBase< DataType, false >::operator=
OptionValueBase & operator=(const OptionValueBase &)=default
llvm::cl::OptionValueBase< DataType, false >::OptionValueBase
OptionValueBase(const OptionValueBase &)=default
llvm::cl::OptionValueBase< DataType, false >::WrapperType
DataType WrapperType
Definition:CommandLine.h:612
llvm::cl::OptionValueBase< DataType, false >::OptionValueBase
OptionValueBase()=default
llvm::cl::OptionValueBase
Definition:CommandLine.h:550
llvm::cl::OptionValueBase::compare
bool compare(const DataType &) const
Definition:CommandLine.h:562
llvm::cl::OptionValueBase::getValue
const DataType & getValue() const
Definition:CommandLine.h:556
llvm::cl::OptionValueBase::hasValue
bool hasValue() const
Definition:CommandLine.h:554
llvm::cl::OptionValueBase::~OptionValueBase
~OptionValueBase()=default
llvm::cl::OptionValueBase::compare
bool compare(const GenericOptionValue &) const override
Definition:CommandLine.h:564
llvm::cl::OptionValueBase::WrapperType
OptionValue< DataType > WrapperType
Definition:CommandLine.h:552
llvm::cl::OptionValueBase::setValue
void setValue(const DT &)
Definition:CommandLine.h:559
llvm::cl::OptionValue< cl::boolOrDefault >::OptionValue
OptionValue()=default
llvm::cl::OptionValue< cl::boolOrDefault >::operator=
OptionValue< cl::boolOrDefault > & operator=(const cl::boolOrDefault &V)
Definition:CommandLine.h:647
llvm::cl::OptionValue< cl::boolOrDefault >::OptionValue
OptionValue(const cl::boolOrDefault &V)
Definition:CommandLine.h:645
llvm::cl::OptionValue< std::string >
Definition:CommandLine.h:657
llvm::cl::OptionValue< std::string >::operator=
OptionValue< std::string > & operator=(const std::string &V)
Definition:CommandLine.h:664
llvm::cl::OptionValue< std::string >::OptionValue
OptionValue()=default
llvm::cl::OptionValue< std::string >::OptionValue
OptionValue(const std::string &V)
Definition:CommandLine.h:662
llvm::cl::OptionValue
Definition:CommandLine.h:624
llvm::cl::OptionValue::OptionValue
OptionValue(const DataType &V)
Definition:CommandLine.h:627
llvm::cl::OptionValue::OptionValue
OptionValue()=default
llvm::cl::OptionValue::operator=
OptionValue< DataType > & operator=(const DT &V)
Definition:CommandLine.h:630
llvm::cl::aliasopt
Definition:CommandLine.h:1972
llvm::cl::aliasopt::apply
void apply(alias &A) const
Definition:CommandLine.h:1977
llvm::cl::aliasopt::Opt
Option & Opt
Definition:CommandLine.h:1973
llvm::cl::aliasopt::aliasopt
aliasopt(Option &O)
Definition:CommandLine.h:1975
llvm::cl::applicator< FormattingFlags >::opt
static void opt(FormattingFlags FF, Option &O)
Definition:CommandLine.h:1296
llvm::cl::applicator< MiscFlags >::opt
static void opt(MiscFlags MF, Option &O)
Definition:CommandLine.h:1300
llvm::cl::applicator< NumOccurrencesFlag >::opt
static void opt(NumOccurrencesFlag N, Option &O)
Definition:CommandLine.h:1282
llvm::cl::applicator< OptionHidden >::opt
static void opt(OptionHidden OH, Option &O)
Definition:CommandLine.h:1292
llvm::cl::applicator< StringRef >::opt
static void opt(StringRef Str, Opt &O)
Definition:CommandLine.h:1276
llvm::cl::applicator< ValueExpected >::opt
static void opt(ValueExpected VE, Option &O)
Definition:CommandLine.h:1288
llvm::cl::applicator< char[n]>::opt
static void opt(StringRef Str, Opt &O)
Definition:CommandLine.h:1266
llvm::cl::applicator< const char[n]>::opt
static void opt(StringRef Str, Opt &O)
Definition:CommandLine.h:1271
llvm::cl::applicator
Definition:CommandLine.h:1260
llvm::cl::applicator::opt
static void opt(const Mod &M, Opt &O)
Definition:CommandLine.h:1261
llvm::cl::cat
Definition:CommandLine.h:468
llvm::cl::cat::apply
void apply(Opt &O) const
Definition:CommandLine.h:473
llvm::cl::cat::cat
cat(OptionCategory &c)
Definition:CommandLine.h:471
llvm::cl::cat::Category
OptionCategory & Category
Definition:CommandLine.h:469
llvm::cl::cb
Definition:CommandLine.h:495
llvm::cl::cb::apply
void apply(Opt &O) const
Definition:CommandLine.h:500
llvm::cl::cb::cb
cb(std::function< R(Ty)> CB)
Definition:CommandLine.h:498
llvm::cl::cb::CB
std::function< R(Ty)> CB
Definition:CommandLine.h:496
llvm::cl::desc
Definition:CommandLine.h:409
llvm::cl::desc::desc
desc(StringRef Str)
Definition:CommandLine.h:412
llvm::cl::desc::apply
void apply(Option &O) const
Definition:CommandLine.h:414
llvm::cl::desc::Desc
StringRef Desc
Definition:CommandLine.h:410
llvm::cl::detail::callback_traits< R(C::*)(Args...) const >::arg_type
std::tuple_element_t< 0, std::tuple< Args... > > arg_type
Definition:CommandLine.h:510
llvm::cl::detail::callback_traits< R(C::*)(Args...) const >::result_type
R result_type
Definition:CommandLine.h:509
llvm::cl::detail::callback_traits
Definition:CommandLine.h:505
llvm::cl::extrahelp
Definition:CommandLine.h:1983
llvm::cl::extrahelp::morehelp
StringRef morehelp
Definition:CommandLine.h:1984
llvm::cl::initializer
Definition:CommandLine.h:429
llvm::cl::initializer::Init
const Ty & Init
Definition:CommandLine.h:430
llvm::cl::initializer::initializer
initializer(const Ty &Val)
Definition:CommandLine.h:431
llvm::cl::initializer::apply
void apply(Opt &O) const
Definition:CommandLine.h:433
llvm::cl::list_initializer
Definition:CommandLine.h:436
llvm::cl::list_initializer::list_initializer
list_initializer(ArrayRef< Ty > Vals)
Definition:CommandLine.h:438
llvm::cl::list_initializer::Inits
ArrayRef< Ty > Inits
Definition:CommandLine.h:437
llvm::cl::list_initializer::apply
void apply(Opt &O) const
Definition:CommandLine.h:440
llvm::cl::multi_val
Definition:CommandLine.h:1754
llvm::cl::multi_val::AdditionalVals
unsigned AdditionalVals
Definition:CommandLine.h:1755
llvm::cl::multi_val::multi_val
multi_val(unsigned N)
Definition:CommandLine.h:1756
llvm::cl::multi_val::apply
void apply(list< D, S, P > &L) const
Definition:CommandLine.h:1759
llvm::cl::sub
Definition:CommandLine.h:477
llvm::cl::sub::sub
sub(SubCommand &S)
Definition:CommandLine.h:481
llvm::cl::sub::Sub
SubCommand * Sub
Definition:CommandLine.h:478
llvm::cl::sub::sub
sub(SubCommandGroup &G)
Definition:CommandLine.h:482
llvm::cl::sub::apply
void apply(Opt &O) const
Definition:CommandLine.h:484
llvm::cl::sub::Group
SubCommandGroup * Group
Definition:CommandLine.h:479
llvm::cl::value_desc
Definition:CommandLine.h:418
llvm::cl::value_desc::Desc
StringRef Desc
Definition:CommandLine.h:419
llvm::cl::value_desc::apply
void apply(Option &O) const
Definition:CommandLine.h:423
llvm::cl::value_desc::value_desc
value_desc(StringRef Str)
Definition:CommandLine.h:421

Generated on Thu Jul 17 2025 10:16:17 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp