1//===- llvm/Support/CommandLine.h - Command line handler --------*- C++ -*-===// 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 7//===----------------------------------------------------------------------===// 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. 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 17//===----------------------------------------------------------------------===// 19#ifndef LLVM_SUPPORT_COMMANDLINE_H 20#define LLVM_SUPPORT_COMMANDLINE_H 37#include <initializer_list> 50/// This namespace contains all of the command line option processing machinery. 51/// It is intentionally a short name to make qualified usage concise. 54//===----------------------------------------------------------------------===// 55// Command line option processing entry point. 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. 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. 71constchar *EnvVar =
nullptr,
72bool LongOptionsUseDoubleDash =
false);
74// Function pointer type for printing version information. 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. 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. 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.) 96// Forward declaration - AddLiteralOption needs to be up here to make gcc happy. 99/// Adds a new option for parsing and provides the option it refers to. 101/// \param O pointer to the option 102/// \param Name the string name for the option to handle during parsing 104/// Literal options are used by some parsers to register special option values. 105/// This is how the PassNameParser registers pass names for opt. 108//===----------------------------------------------------------------------===// 109// Flags permitted to be passed to command line arguments 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. 129// zero reserved for the unspecified value 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 141// This controls special features that the option might have that cause it to be 142// parsed differently... 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 151// AlwaysPrefix - Only allow the behavior enabled by the Prefix flag and reject 152// the Option=Value form. 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? 165Sink = 0x04,
// Should this cl::list eat all unknown options? 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 177//===----------------------------------------------------------------------===// 184void registerCategory();
189 : Name(Name), Description(Description) {
197// The general Option Category (used as default category). 200//===----------------------------------------------------------------------===// 213 : Name(Name), Description(Description) {
218// Get the special subcommand representing no subcommand. 221// Get the special subcommand that can be used to put an option into all 227explicitoperatorbool()
const;
248//===----------------------------------------------------------------------===// 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 257virtualbool handleOccurrence(
unsigned pos,
StringRef ArgName,
264// Out of line virtual function to provide home for the class. 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 274uint16_t HiddenFlag : 2;
// enum OptionHidden 275uint16_t Formatting : 2;
// enum FormattingFlags 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. 309// Return true if the argstr != "" 319//-------------------------------------------------------------------------=== 320// Accessor functions set by OptionModifiers 337 : NumOccurrences(0), Occurrences(OccurrencesFlag),
Value(0),
339 FullyInitialized(
false), Position(0), AdditionalVals(0) {
348// Register this argument with the commandline system. 352 /// Unregisters this option from the CommandLine system. 354 /// This option must have been the last option registered. 355 /// For testing purposes only. 358// Return the width of the option tag for printing... 361// Print out information about this option. The to-be-maintained width is 370// Prints the help string for an option. 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>. 376size_t FirstLineIndentedBy);
378// Prints the help string for an enum value. 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>. 384size_t FirstLineIndentedBy);
388// Wrapper around handleOccurrence that enforces Flags. 391bool MultiArg =
false);
393// Prints option name followed by message. Always returns true. 403//===----------------------------------------------------------------------===// 404// Command line option modifiers that can be used to modify the behavior of 405// command line option parsers... 408// Modifier to set the description shown in the -help output... 417// Modifier to set the value description shown in the -help output... 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. 433template <
class Opt>
voidapply(Opt &O)
const{ O.setInitialValue(
Init); }
440template <
class Opt>
voidapply(Opt &O)
const{ O.setInitialValues(
Inits); }
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. 460template <
class Opt>
voidapply(Opt &O)
const{ O.setLocation(O,
Loc); }
467// Specify the Option category for the command line argument to belong to. 476// Specify the subcommand that this option belongs to. 484template <
class Opt>
voidapply(Opt &O)
const{
486 O.addSubCommand(*
Sub);
489 O.addSubCommand(*SC);
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;
500template <
typename Opt>
voidapply(Opt &O)
const{ O.setCallback(
CB); }
507template <
typename R,
typenameC,
typename... Args>
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");
529//===----------------------------------------------------------------------===// 531// Support value comparison outside the template. 547// The default value safely does nothing. Option value printing is only 549template <
class DataType,
bool isClass>
551// Temporary storage for argument passing. 558// Some options may take their value from a different data type. 561// Returns whether this instance matches the argument. 562boolcompare(
const DataType &
/*V*/)
const{
returnfalse; }
572// Simple copy of the option value. 588assert(Valid &&
"invalid option value");
597// Returns whether this instance matches V. 609// Non-class option values. 610template <
class DataType>
621// Top-level option class. 622template <
class DataType>
629// Some options may take their value from a different data type. 636// Other safe-to-copy-by-value common option types. 653void anchor()
override;
670void anchor()
override;
673//===----------------------------------------------------------------------===// 674// Enum valued command line option 677// This represents a single enum value, using "int" as the underlying type. 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 } 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. 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. 702template <
class Opt>
voidapply(Opt &O)
const{
703for (
constauto &
Value : Values)
709/// Helper to build a ValuesClass by forwarding a variable number of arguments 710/// as an initializer list to the ValuesClass constructor. 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. 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 741// Base class should have virtual-destructor 743// Virtual function implemented by generic subclass to indicate how many 744// entries are in Values. 748// Return option name N. 751// Return description N 754// Return the width of the option tag for printing... 759// Print out information about this option. The to-be-maintained width is 766size_t GlobalWidth)
const;
768// Print the value of an option and it's default. 770// Template definition ensures that the option and default have the same 771// DataType (via the same AnyOptionValue). 772template <
class AnyOptionValue>
775size_t GlobalWidth)
const{
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 791// If there is an ArgStr specified, then we are of the form: 793// -opt=O2 or -opt O2 or -optO2 795// In which case, the value is required. Otherwise if an arg str has not 796// been specified, we are of the form: 798// -O2 or O2 or -la (where -l and -a are separate options) 800// If this is the case, we cannot allow a value. 808// Return the option number corresponding to the specified 809// argument string. If the option is not found, getNumOptions() is returned. 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. 839// Implement virtual functions needed by generic_parser_base 846// Return the value of option name N. 851// Return true on error. 859for (
size_t i = 0, e =
Values.size(); i != e; ++i)
861 V =
Values[i].V.getValue();
865return O.error(
"Cannot find option named '" + ArgVal +
"'!");
868 /// Add an entry to the mapping table. 881 /// Remove the specified option. 890//-------------------------------------------------- 891// Super class of parsers to provide boilerplate code 907// Return the width of the option tag for printing... 910// Print out information about this option. The to-be-maintained width is 915// Print a placeholder for options that don't yet support printOptionDiff(). 918// Overload in subclass to provide a better default value. 921// An out-of-line virtual method to provide a 'home' for this class. 925// A helper for basic_parser::printOptionDiff. 929// The real basic parser is just a template wrapper that provides a typedef for 930// the provided data type. 940//-------------------------------------------------- 942externtemplateclassbasic_parser<bool>;
948// Return true on error. 957// Do not print =<value> at all. 961size_t GlobalWidth)
const;
963// An out-of-line virtual method to provide a 'home' for this class. 967//-------------------------------------------------- 975// Return true on error. 982// Do not print =<value> at all. 986size_t GlobalWidth)
const;
988// An out-of-line virtual method to provide a 'home' for this class. 992//-------------------------------------------------- 1000// Return true on error. 1003// Overload in subclass to provide a better default value. 1007size_t GlobalWidth)
const;
1009// An out-of-line virtual method to provide a 'home' for this class. 1013//-------------------------------------------------- 1021// Return true on error. 1024// Overload in subclass to provide a better default value. 1028size_t GlobalWidth)
const;
1030// An out-of-line virtual method to provide a 'home' for this class. 1034//-------------------------------------------------- 1042// Return true on error. 1045// Overload in subclass to provide a better default value. 1049size_t GlobalWidth)
const;
1051// An out-of-line virtual method to provide a 'home' for this class. 1055//-------------------------------------------------- 1063// Return true on error. 1066// Overload in subclass to provide a better default value. 1070size_t GlobalWidth)
const;
1072// An out-of-line virtual method to provide a 'home' for this class. 1076//-------------------------------------------------- 1085// Return true on error. 1088// Overload in subclass to provide a better default value. 1092size_t GlobalWidth)
const;
1094// An out-of-line virtual method to provide a 'home' for this class. 1098//-------------------------------------------------- 1107// Return true on error. 1109unsignedlonglong &Val);
1111// Overload in subclass to provide a better default value. 1115size_t GlobalWidth)
const;
1117// An out-of-line virtual method to provide a 'home' for this class. 1121//-------------------------------------------------- 1129// Return true on error. 1132// Overload in subclass to provide a better default value. 1136size_t GlobalWidth)
const;
1138// An out-of-line virtual method to provide a 'home' for this class. 1142//-------------------------------------------------- 1150// Return true on error. 1153// Overload in subclass to provide a better default value. 1157size_t GlobalWidth)
const;
1159// An out-of-line virtual method to provide a 'home' for this class. 1163//-------------------------------------------------- 1171// Return true on error. 1177// Overload in subclass to provide a better default value. 1181size_t GlobalWidth)
const;
1183// An out-of-line virtual method to provide a 'home' for this class. 1187//-------------------------------------------------- 1195// Return true on error. 1201// Overload in subclass to provide a better default value. 1205size_t GlobalWidth)
const;
1207// An out-of-line virtual method to provide a 'home' for this class. 1211//-------------------------------------------------- 1212// This collection of wrappers is the intermediary between class opt and class 1213// parser to handle all the template nastiness. 1215// This overloaded function is selected by the generic parser. 1216template <
class ParserClass,
class DT>
1220P.printOptionDiff(O, OV,
Default, GlobalWidth);
1223// This is instantiated for basic parsers when the parsed value has a different 1224// type than the option value. e.g. HelpPrinter. 1228P.printOptionNoValue(O, GlobalWidth);
1232// This is instantiated for basic parsers when the parsed value has the same 1233// type as the option value. 1237P.printOptionDiff(O, V,
Default, GlobalWidth);
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>
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... 1261template <
class Opt>
staticvoidopt(
constMod &M, Opt &O) { M.apply(O); }
1264// Handle const char* as a special case... 1283 O.setNumOccurrencesFlag(
N);
1302"cl::Grouping can only apply to single character Options.");
1307// Apply modifiers to an option in a type safe way. 1308template <
classOpt,
classMod,
class... Mods>
1314template <
class Opt,
class Mod>
voidapply(Opt *O,
constMod &M) {
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. 1323template <
class DataType,
bool ExternalStorage,
bool isClass>
1325 DataType *Location =
nullptr;
// Where to store the object... 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()!!");
1339return O.error(
"cl::location(x) specified more than once!");
1345template <
class T>
voidsetValue(
constT &V,
bool initial =
false) {
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. 1370template <
class DataType>
1375template <
class T>
voidsetValue(
constT &V,
bool initial =
false) {
1376 DataType::operator=(V);
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. 1396// Make sure we initialize the value with the default constructor for the 1400template <
class T>
voidsetValue(
constT &V,
bool initial =
false) {
1412// If the datatype is a pointer, support -> on it. 1416//===----------------------------------------------------------------------===// 1417// A scalar command line option. 1419template <
classDataType,
bool ExternalStorage =
false,
1420classParserClass = parser<DataType>>
1423publicopt_storage<DataType, ExternalStorage, std::is_class_v<DataType>> {
1426bool handleOccurrence(
unsigned pos,
StringRef ArgName,
1428typename ParserClass::parser_data_type Val =
1429typename ParserClass::parser_data_type();
1430if (Parser.parse(*
this, ArgName, Arg, Val))
1431returntrue;
// Parse error! 1438enumValueExpected getValueExpectedFlagDefault()
const override{
1439return Parser.getValueExpectedFlagDefault();
1443return Parser.getExtraOptionNames(OptionNames);
1446// Forward printing stuff to the parser... 1447size_t getOptionWidth()
const override{
1448return Parser.getOptionWidth(*
this);
1451void printOptionInfo(
size_t GlobalWidth)
const override{
1452 Parser.printOptionInfo(*
this, GlobalWidth);
1455void printOptionValue(
size_t GlobalWidth,
bool Force)
const override{
1457 cl::printOptionDiff<ParserClass>(*
this, Parser, this->
getValue(),
1462template <
class T,
class = std::enable_if_t<std::is_assignable_v<T &, T>>>
1463void setDefaultImpl() {
1471template <
class T,
class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
1472void setDefaultImpl(...) {}
1474void setDefault()
override{ setDefaultImpl<DataType>(); }
1478 Parser.initialize();
1482// Command line options should not be copyable 1486// setInitialValue - Used by the cl::init modifier... 1497template <
class... Mods>
1498explicitopt(
const Mods &... Ms)
1505 std::function<
void(
consttypename ParserClass::parser_data_type &)> CB) {
1509 std::function<void(
consttypename ParserClass::parser_data_type &)>
Callback =
1510 [](
consttypename ParserClass::parser_data_type &) {};
1513externtemplateclassopt<unsigned>;
1514externtemplateclassopt<int>;
1515externtemplateclassopt<std::string>;
1516externtemplateclassopt<char>;
1517externtemplateclassopt<bool>;
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. 1525StorageClass *Location =
nullptr;
// Where to store the object... 1526 std::vector<OptionValue<DataType>>
Default =
1527 std::vector<OptionValue<DataType>>();
1528bool DefaultAssigned =
false;
1537return O.error(
"cl::location(x) specified more than once!");
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);
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. 1566// FIXME: Reduce this API to a more narrow subset of std::vector 1569 std::vector<DataType> Storage;
1570 std::vector<OptionValue<DataType>> Default;
1571bool DefaultAssigned =
false;
1574usingiterator =
typename std::vector<DataType>::iterator;
1588boolempty()
const{
return Storage.empty(); }
1605return Storage.erase(first, last);
1610return Storage.erase(first, last);
1614return Storage.insert(pos,
value);
1617return Storage.insert(pos,
value);
1621return Storage.insert(pos,
value);
1624return Storage.insert(pos,
value);
1630operator std::vector<DataType> &() {
return Storage; }
1633const std::vector<DataType> *
operator&()
const{
return &Storage; }
1635template <
class T>
voidaddValue(
constT &V,
bool initial =
false) {
1636 Storage.push_back(V);
1650//===----------------------------------------------------------------------===// 1651// A list of command line options. 1654classParserClass = parser<DataType>>
1656 std::vector<unsigned> Positions;
1659enumValueExpected getValueExpectedFlagDefault()
const override{
1660return Parser.getValueExpectedFlagDefault();
1664return Parser.getExtraOptionNames(OptionNames);
1667bool handleOccurrence(
unsigned pos,
StringRef ArgName,
1669typename ParserClass::parser_data_type Val =
1670typename ParserClass::parser_data_type();
1675if (Parser.parse(*
this, ArgName, Arg, Val))
1676returntrue;
// Parse Error! 1679 Positions.push_back(pos);
1684// Forward printing stuff to the parser... 1685size_t getOptionWidth()
const override{
1686return Parser.getOptionWidth(*
this);
1689void printOptionInfo(
size_t GlobalWidth)
const override{
1690 Parser.printOptionInfo(*
this, GlobalWidth);
1693// Unimplemented: list options don't currently store their default value. 1694void printOptionValue(
size_t/*GlobalWidth*/,
bool/*Force*/)
const override{
1697void setDefault()
override{
1706 Parser.initialize();
1710// Command line options should not be copyable 1717assert(optnum < this->
size() &&
"Invalid option index");
1718return Positions[optnum];
1726// setInitialValues - Used by the cl::list_init modifier... 1729"Cannot have two default values");
1737template <
class... Mods>
1745 std::function<
void(
consttypename ParserClass::parser_data_type &)> CB) {
1749 std::function<void(
consttypename ParserClass::parser_data_type &)>
Callback =
1750 [](
consttypename ParserClass::parser_data_type &) {};
1753// Modifier to set the number of additional values. 1758template <
typename D,
typename S,
typename P>
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. 1770unsigned *Location =
nullptr;
// Where to store the bits... 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!");
1784return O.error(
"cl::location(x) specified more than once!");
1790assert(Location !=
nullptr &&
1791"cl::location(...) not specified for a command " 1792"line option with external storage!");
1793 *Location |= Bit(V);
1804return (*Location & Bit(V)) != 0;
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. 1812unsigned Bits{0};
// Where to store the bits... 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!");
1822template <
class T>
voidaddValue(
constT &V) { Bits |= Bit(V); }
1828template <
class T>
boolisSet(
constT &V) {
return (Bits & Bit(V)) != 0; }
1831//===----------------------------------------------------------------------===// 1832// A bit vector of command options. 1834template <
classDataType,
classStorage =
bool,
1835classParserClass = parser<DataType>>
1837 std::vector<unsigned> Positions;
1840enumValueExpected getValueExpectedFlagDefault()
const override{
1841return Parser.getValueExpectedFlagDefault();
1845return Parser.getExtraOptionNames(OptionNames);
1848bool handleOccurrence(
unsigned pos,
StringRef ArgName,
1850typename ParserClass::parser_data_type Val =
1851typename ParserClass::parser_data_type();
1852if (Parser.parse(*
this, ArgName, Arg, Val))
1853returntrue;
// Parse Error! 1856 Positions.push_back(pos);
1861// Forward printing stuff to the parser... 1862size_t getOptionWidth()
const override{
1863return Parser.getOptionWidth(*
this);
1866void printOptionInfo(
size_t GlobalWidth)
const override{
1867 Parser.printOptionInfo(*
this, GlobalWidth);
1870// Unimplemented: bits options don't currently store their default values. 1871void printOptionValue(
size_t/*GlobalWidth*/,
bool/*Force*/)
const override{
1878 Parser.initialize();
1882// Command line options should not be copyable 1889assert(optnum < this->
size() &&
"Invalid option index");
1890return Positions[optnum];
1893template <
class... Mods>
1901 std::function<
void(
consttypename ParserClass::parser_data_type &)> CB) {
1905 std::function<void(
consttypename ParserClass::parser_data_type &)>
Callback =
1906 [](
consttypename ParserClass::parser_data_type &) {};
1909//===----------------------------------------------------------------------===// 1910// Aliased command line option (alias this name to a preexisting name) 1916bool handleOccurrence(
unsigned pos,
StringRef/*ArgName*/,
1918return AliasFor->handleOccurrence(pos, AliasFor->
ArgStr, Arg);
1922bool MultiArg =
false)
override{
1926// Handle printing stuff... 1927size_t getOptionWidth()
const override;
1928void printOptionInfo(
size_t GlobalWidth)
const override;
1930// Aliases do not need to print their values. 1931void printOptionValue(
size_t/*GlobalWidth*/,
bool/*Force*/)
const override{
1934void setDefault()
override{ AliasFor->
setDefault(); }
1942error(
"cl::alias must have argument name specified!");
1944error(
"cl::alias must have an cl::aliasopt(option) specified!");
1946error(
"cl::alias must not have cl::sub(), aliased option's cl::sub() will be used!");
1953// Command line options should not be copyable 1959error(
"cl::alias must only have one cl::aliasopt(...) specified!");
1963template <
class... Mods>
1971// Modifier to set the option an alias aliases. 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. 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. 1994/// \param Hidden if true will print hidden options 1995/// \param Categorized if true print options in categories 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. 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. 2008//===----------------------------------------------------------------------===// 2009// Public interface for accessing registered options. 2012/// Use this to get a StringMap to all registered named options 2015/// \return A reference to the StringMap used by the cl APIs to parse options. 2017/// Access to unnamed arguments (i.e. positional) are not provided because 2018/// it is expected that the client already has access to these. 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") 2027/// llvm::cl::ParseCommandLineOptions(argc,argv); 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(). 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. 2042/// Use this to get all registered SubCommands from the provided parser. 2044/// \return A range of all SubCommand pointers registered with the parser. 2048/// main(int argc, char* argv[]) { 2049/// llvm::cl::ParseCommandLineOptions(argc, argv); 2050/// for (auto* S : llvm::cl::getRegisteredSubcommands()) { 2052/// std::cout << "Executing subcommand: " << S->getName() << std::endl; 2053/// // Execute some function based on the name... 2059/// This interface is useful for defining subcommands in libraries and 2060/// the dispatch from a single point (like in the main function). 2064//===----------------------------------------------------------------------===// 2065// Standalone command line processing utilities. 2068/// Tokenizes a command line that can contain escapes and quotes. 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. 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. 2082bool MarkEOLs =
false);
2084/// Tokenizes a string of Windows command line arguments, which may contain 2085/// quotes and escaped quotes. 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 2090/// For handling a full Windows command line including the executable name at 2091/// the start, see TokenizeWindowsCommandLineFull below. 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. 2100bool MarkEOLs =
false);
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 2109/// Tokenizes a Windows full command line, including command name at the start. 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). 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. 2124bool MarkEOLs =
false);
2126/// String tokenization function type. Should be compatible with either 2127/// Windows or Unix command line tokenizers. 2132/// Tokenizes content of configuration file. 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. 2139/// It works like TokenizeGNUCommandLine with ability to skip comment lines. 2143bool MarkEOLs =
false);
2145/// Contains options that control response file expansion. 2147 /// Provides persistent storage for parsed strings. 2150 /// Tokenization strategy. Typically Unix or Windows. 2153 /// File system used for all file access when running the expansion. 2156 /// Path used to resolve relative rsp files. If empty, the file system 2157 /// current directory is used instead. 2160 /// Directories used for search of config files. 2163 /// True if names of nested response files must be resolved relative to 2165bool RelativeNames =
false;
2167 /// If true, mark end of lines and the end of the response file with nullptrs 2168 /// in the Argv vector. 2169bool MarkEOLs =
false;
2171 /// If true, body of config file is expanded. 2172bool InConfigFile =
false;
2205 /// Looks for the specified configuration file. 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. 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. 2216 /// Reads command line options from the given configuration file. 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. 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. 2228 /// Expands constructs "@file" in the provided array of arguments recursively. 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. 2239/// A convenience helper which supports the typical use case of expansion 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. 2252/// Mark all options not part of this category as cl::ReallyHidden. 2254/// \param Category the category of options to keep displaying 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. 2262/// Mark all options not part of the categories as cl::ReallyHidden. 2264/// \param Categories the categories of options to keep displaying. 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. 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). 2277/// Reset the command line parser back to its initial state. This 2279/// all options, categories, and subcommands and returns the parser to a state 2280/// where no options are supported. 2283/// Parses `Arg` into the option handler `Handler`. 2288}
// end namespace llvm 2290#endif// LLVM_SUPPORT_COMMANDLINE_H This file defines the StringMap class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Given that RA is a live value
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Allocate memory in an ever growing pool, as if by bump-pointer.
Lightweight error class with error context and mandatory checking.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
Value(Type *Ty, unsigned scid)
Contains options that control response file expansion.
ExpansionContext & setCurrentDir(StringRef X)
ExpansionContext & setVFS(vfs::FileSystem *X)
ExpansionContext & setMarkEOLs(bool X)
ExpansionContext & setSearchDirs(ArrayRef< StringRef > X)
ExpansionContext & setRelativeNames(bool X)
bool findConfigFile(StringRef FileName, SmallVectorImpl< char > &FilePath)
Looks for the specified configuration file.
Error expandResponseFiles(SmallVectorImpl< const char * > &Argv)
Expands constructs "@file" in the provided array of arguments recursively.
Error readConfigFile(StringRef CfgFile, SmallVectorImpl< const char * > &Argv)
Reads command line options from the given configuration file.
OptionCategory(StringRef const Name, StringRef const Description="")
StringRef getDescription() const
StringRef getName() const
OptionValueCopy & operator=(const OptionValueCopy &)=default
OptionValueCopy()=default
bool compare(const GenericOptionValue &V) const override
void setValue(const DataType &V)
~OptionValueCopy()=default
const DataType & getValue() const
OptionValueCopy(const OptionValueCopy &)=default
bool compare(const DataType &V) const
bool isPositional() const
virtual void getExtraOptionNames(SmallVectorImpl< StringRef > &)
void setValueExpectedFlag(enum ValueExpected Val)
void setPosition(unsigned pos)
bool isConsumeAfter() const
SmallPtrSet< SubCommand *, 1 > Subs
int getNumOccurrences() const
enum ValueExpected getValueExpectedFlag() const
void addCategory(OptionCategory &C)
void setValueStr(StringRef S)
void setNumOccurrencesFlag(enum NumOccurrencesFlag Val)
void setNumAdditionalVals(unsigned n)
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
void setDescription(StringRef S)
void setFormattingFlag(enum FormattingFlags V)
void setHiddenFlag(enum OptionHidden Val)
void setMiscFlag(enum MiscFlags M)
enum FormattingFlags getFormattingFlag() const
virtual void printOptionInfo(size_t GlobalWidth) const =0
enum NumOccurrencesFlag getNumOccurrencesFlag() const
SmallVector< OptionCategory *, 1 > Categories
void addSubCommand(SubCommand &S)
void setArgStr(StringRef S)
bool isDefaultOption() const
unsigned getMiscFlags() const
virtual void setDefault()=0
virtual void printOptionValue(size_t GlobalWidth, bool Force) const =0
virtual ~Option()=default
static void printEnumValHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
unsigned getNumAdditionalVals() const
void removeArgument()
Unregisters this option from the CommandLine system.
Option(enum NumOccurrencesFlag OccurrencesFlag, enum OptionHidden Hidden)
enum OptionHidden getOptionHiddenFlag() const
bool error(const Twine &Message, raw_ostream &Errs)
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
virtual size_t getOptionWidth() const =0
unsigned getPosition() const
SubCommandGroup(std::initializer_list< SubCommand * > IL)
ArrayRef< SubCommand * > getSubCommands() const
StringRef getName() const
SubCommand(StringRef Name, StringRef Description="")
SmallVector< Option *, 4 > SinkOpts
static SubCommand & getTopLevel()
void unregisterSubCommand()
static SubCommand & getAll()
void registerSubCommand()
SmallVector< Option *, 4 > PositionalOpts
StringMap< Option * > OptionsMap
StringRef getDescription() const
ValuesClass(std::initializer_list< OptionEnumValue > Options)
alias(const alias &)=delete
void setAliasFor(Option &O)
alias & operator=(const alias &)=delete
alias(const Mods &... Ms)
void printOptionInfo(const Option &O, size_t GlobalWidth) const
enum ValueExpected getValueExpectedFlagDefault() const
void getExtraOptionNames(SmallVectorImpl< StringRef > &)
virtual StringRef getValueName() const
virtual ~basic_parser_impl()=default
void printOptionNoValue(const Option &O, size_t GlobalWidth) const
basic_parser_impl(Option &)
size_t getOptionWidth(const Option &O) const
void printOptionName(const Option &O, size_t GlobalWidth) const
OptionValue< DataType > OptVal
DataType parser_data_type
void addValue(const T &V)
void addValue(const T &V)
bool setLocation(Option &O, unsigned &L)
bits & operator=(const bits &)=delete
ParserClass & getParser()
unsigned getPosition(unsigned optnum) const
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
std::function< void(const typename ParserClass::parser_data_type &)> Callback
bits(const bits &)=delete
GenericOptionInfo(StringRef name, StringRef helpStr)
virtual size_t getOptionWidth(const Option &O) const
generic_parser_base(Option &O)
virtual StringRef getDescription(unsigned N) const =0
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
virtual unsigned getNumOptions() const =0
virtual StringRef getOption(unsigned N) const =0
void printOptionDiff(const Option &O, const AnyOptionValue &V, const AnyOptionValue &Default, size_t GlobalWidth) const
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
unsigned findOption(StringRef Name)
virtual ~generic_parser_base()=default
void getExtraOptionNames(SmallVectorImpl< StringRef > &OptionNames)
enum ValueExpected getValueExpectedFlagDefault() const
void push_back(DataType &&value)
typename std::vector< DataType >::const_iterator const_iterator
typename std::vector< DataType >::const_reference const_reference
const_iterator begin() const
iterator erase(const_iterator first, const_iterator last)
iterator insert(const_iterator pos, const DataType &value)
iterator erase(iterator first, iterator last)
const_reference operator[](size_type pos) const
void addValue(const T &V, bool initial=false)
void push_back(const DataType &value)
typename std::vector< DataType >::reference reference
reference operator[](size_type pos)
const std::vector< DataType > * operator&() const
iterator insert(iterator pos, const DataType &value)
typename std::vector< DataType >::size_type size_type
const_reference front() const
const_iterator end() const
iterator insert(const_iterator pos, DataType &&value)
iterator erase(iterator pos)
std::vector< DataType > * operator&()
const std::vector< OptionValue< DataType > > & getDefault() const
iterator erase(const_iterator pos)
iterator insert(iterator pos, DataType &&value)
typename std::vector< DataType >::iterator iterator
const std::vector< OptionValue< DataType > > & getDefault() const
void addValue(const T &V, bool initial=false)
bool setLocation(Option &O, StorageClass &L)
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
list(const list &)=delete
void setInitialValues(ArrayRef< DataType > Vs)
std::function< void(const typename ParserClass::parser_data_type &)> Callback
list & operator=(const list &)=delete
ParserClass & getParser()
unsigned getPosition(unsigned optnum) const
void setNumAdditionalVals(unsigned n)
OptionValue< DataType > Default
DataType operator->() const
const OptionValue< DataType > & getDefault() const
void setValue(const T &V, bool initial=false)
DataType getValue() const
void setValue(const T &V, bool initial=false)
OptionValue< DataType > Default
const DataType & getValue() const
const OptionValue< DataType > & getDefault() const
const DataType & getValue() const
bool setLocation(Option &O, DataType &L)
void setValue(const T &V, bool initial=false)
const OptionValue< DataType > & getDefault() const
ParserClass & getParser()
opt & operator=(const opt &)=delete
void setInitialValue(const DataType &V)
void setCallback(std::function< void(const typename ParserClass::parser_data_type &)> CB)
DataType & operator=(const T &Val)
std::function< void(const typename ParserClass::parser_data_type &)> Callback
OptionInfo(StringRef name, DataType v, StringRef helpStr)
OptionValue< DataType > V
bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val)
void printOptionDiff(const Option &O, boolOrDefault V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
enum ValueExpected getValueExpectedFlagDefault() const
enum ValueExpected getValueExpectedFlagDefault() const
void printOptionDiff(const Option &O, bool V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val)
StringRef getValueName() const override
bool parse(Option &, StringRef, StringRef Arg, char &Value)
void printOptionDiff(const Option &O, char V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
void printOptionDiff(const Option &O, double V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val)
bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val)
StringRef getValueName() const override
void printOptionDiff(const Option &O, float V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
void printOptionDiff(const Option &O, int V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val)
StringRef getValueName() const override
bool parse(Option &O, StringRef ArgName, StringRef Arg, long &Val)
void printOptionDiff(const Option &O, long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, long long &Val)
StringRef getValueName() const override
void printOptionDiff(const Option &O, long long V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
void printOptionDiff(const Option &O, StringRef V, const OptVal &Default, size_t GlobalWidth) const
bool parse(Option &, StringRef, StringRef Arg, std::string &Value)
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val)
void printOptionDiff(const Option &O, unsigned V, OptVal Default, size_t GlobalWidth) const
StringRef getValueName() const override
StringRef getValueName() const override
void printOptionDiff(const Option &O, unsigned long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long &Val)
StringRef getValueName() const override
void printOptionDiff(const Option &O, unsigned long long V, OptVal Default, size_t GlobalWidth) const
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long long &Val)
DataType parser_data_type
SmallVector< OptionInfo, 8 > Values
void removeLiteralOption(StringRef Name)
Remove the specified option.
StringRef getDescription(unsigned N) const override
void addLiteralOption(StringRef Name, const DT &V, StringRef HelpStr)
Add an entry to the mapping table.
const GenericOptionValue & getOptionValue(unsigned N) const override
StringRef getOption(unsigned N) const override
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
unsigned getNumOptions() const override
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
The virtual file system interface.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
std::function< void(raw_ostream &)> VersionPrinterTy
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
void PrintVersionMessage()
Utility function for printing version number.
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv)
A convenience helper which supports the typical use case of expansion function call.
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 ...
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.
list_initializer< Ty > list_init(ArrayRef< Ty > Vals)
OptionCategory & getGeneralCategory()
void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Override the default (LLV...
void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
StringMap< Option * > & getRegisteredOptions(SubCommand &Sub=SubCommand::getTopLevel())
Use this to get a StringMap to all registered named options (e.g.
void ResetCommandLineParser()
Reset the command line parser back to its initial state.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
void apply(Opt *O, const Mod &M, const Mods &... Ms)
void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
void printBuildConfig(raw_ostream &OS)
Prints the compiler build configuration.
bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
initializer< Ty > init(const Ty &Val)
ArrayRef< StringRef > getCompilerBuildConfig()
An array of optional enabled settings in the LLVM build configuration, which may be of interest to co...
LocationClass< Ty > location(Ty &L)
cb< typename detail::callback_traits< F >::result_type, typename detail::callback_traits< F >::arg_type > callback(F CB)
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=SubCommand::getTopLevel())
Mark all options not part of this category as cl::ReallyHidden.
void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Add an extra printer to u...
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...
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.
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
This is an optimization pass for GlobalISel generic memory operations.
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.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Mod
The access may modify the value stored in memory.
@ Default
The result values are uniform if and only if all operands are uniform.
Implement std::hash so that hash_code can be used in STL containers.
Description of the encoding of one expression Op.
GenericOptionValue()=default
GenericOptionValue(const GenericOptionValue &)=default
GenericOptionValue & operator=(const GenericOptionValue &)=default
~GenericOptionValue()=default
virtual bool compare(const GenericOptionValue &V) const =0
void print(const Option &O, const parser< DT > &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
void print(const Option &O, const parser< ParserDT > &P, const ValDT &, const OptionValue< ValDT > &, size_t GlobalWidth)
~OptionValueBase()=default
OptionValueBase & operator=(const OptionValueBase &)=default
OptionValueBase(const OptionValueBase &)=default
OptionValueBase()=default
bool compare(const DataType &) const
const DataType & getValue() const
~OptionValueBase()=default
bool compare(const GenericOptionValue &) const override
OptionValue< DataType > WrapperType
void setValue(const DT &)
OptionValue< cl::boolOrDefault > & operator=(const cl::boolOrDefault &V)
OptionValue(const cl::boolOrDefault &V)
OptionValue< std::string > & operator=(const std::string &V)
OptionValue(const std::string &V)
OptionValue(const DataType &V)
OptionValue< DataType > & operator=(const DT &V)
void apply(alias &A) const
static void opt(FormattingFlags FF, Option &O)
static void opt(MiscFlags MF, Option &O)
static void opt(NumOccurrencesFlag N, Option &O)
static void opt(OptionHidden OH, Option &O)
static void opt(StringRef Str, Opt &O)
static void opt(ValueExpected VE, Option &O)
static void opt(StringRef Str, Opt &O)
static void opt(StringRef Str, Opt &O)
static void opt(const Mod &M, Opt &O)
OptionCategory & Category
cb(std::function< R(Ty)> CB)
void apply(Option &O) const
std::tuple_element_t< 0, std::tuple< Args... > > arg_type
initializer(const Ty &Val)
list_initializer(ArrayRef< Ty > Vals)
void apply(list< D, S, P > &L) const
void apply(Option &O) const
value_desc(StringRef Str)