30 #include "llvm/Config/config.h"
47 #define DEBUG_TYPE "commandline"
49 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
84 void GenericOptionValue::anchor() {}
87 void Option::anchor() {}
103 class CommandLineParser {
107 std::string ProgramName;
111 std::vector<StringRef> MoreHelp;
119 CommandLineParser() : ActiveSubCommand(nullptr) {
132 if (!SC->
OptionsMap.insert(std::make_pair(Name, &Opt)).second) {
133 errs() << ProgramName <<
": CommandLine Error: Option '" << Name
134 <<
"' registered more than once!\n";
141 for (
const auto &Sub : RegisteredSubCommands) {
144 addLiteralOption(Opt, Sub, Name);
150 if (Opt.
Subs.empty())
153 for (
auto SC : Opt.
Subs)
154 addLiteralOption(Opt, SC, Name);
159 bool HadErrors =
false;
163 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr
164 <<
"' registered more than once!\n";
176 O->
error(
"Cannot specify more than one option with cl::ConsumeAfter!");
192 for (
const auto &Sub : RegisteredSubCommands) {
200 void addOption(
Option *O) {
201 if (O->
Subs.empty()) {
204 for (
auto SC : O->
Subs)
216 for (
auto Name : OptionNames)
238 void removeOption(
Option *O) {
243 for (
auto SC : RegisteredSubCommands)
246 for (
auto SC : O->
Subs)
252 bool hasOptions(
const SubCommand &Sub)
const {
257 bool hasOptions()
const {
258 for (
const auto &S : RegisteredSubCommands) {
265 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
269 if (!Sub.
OptionsMap.insert(std::make_pair(NewName, O)).second) {
270 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr
271 <<
"' registered more than once!\n";
281 for (
auto SC : O->
Subs)
282 updateArgStr(O, NewName, SC);
286 void printOptionValues();
293 "Duplicate option categories");
295 RegisteredOptionCategories.
insert(cat);
304 "Duplicate subcommands");
305 RegisteredSubCommands.insert(sub);
316 addLiteralOption(*O, sub,
E.first());
322 RegisteredSubCommands.erase(sub);
327 return make_range(RegisteredSubCommands.begin(),
328 RegisteredSubCommands.end());
332 ActiveSubCommand =
nullptr;
337 RegisteredOptionCategories.
clear();
340 RegisteredSubCommands.clear();
377 assert((S.
empty() || S[0] !=
'-') &&
"Option can't start with '-");
384 void OptionCategory::registerCategory() {
410 SubCommand::operator
bool()
const {
428 size_t EqualPos = Arg.
find(
'=');
446 Value = Arg.
substr(EqualPos + 1);
447 Arg = Arg.
substr(0, EqualPos);
454 for (
auto S : RegisteredSubCommands) {
457 if (S->getName().empty())
472 std::string &NearestString) {
478 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
484 unsigned BestDistance = 0;
486 ie = OptionsMap.
end();
496 for (
auto Name : OptionNames) {
498 Flag,
true, BestDistance);
499 if (!Best || Distance < BestDistance) {
501 BestDistance = Distance;
502 if (RHS.
empty() || !PermitValue)
503 NearestString = Name;
505 NearestString = (
Twine(Name) +
"=" + RHS).str();
517 bool MultiArg =
false) {
529 Val = Val.
substr(Pos + 1);
537 return Handler->
addOccurrence(pos, ArgName, Value, MultiArg);
545 const char *
const *
argv,
int &i) {
554 return Handler->
error(
"requires a value!");
556 assert(argv &&
"null check");
561 if (NumAdditionalVals > 0)
562 return Handler->
error(
"multi-valued option specified"
563 " with ValueDisallowed modifier!");
566 return Handler->
error(
"does not allow a value! '" +
Twine(Value) +
574 if (NumAdditionalVals == 0)
578 bool MultiArg =
false;
587 while (NumAdditionalVals > 0) {
589 return Handler->
error(
"not enough values!");
590 assert(argv &&
"null check");
621 bool (*Pred)(
const Option *),
629 while (OMI == OptionsMap.
end() && Name.
size() > 1) {
631 OMI = OptionsMap.
find(Name);
634 if (OMI != OptionsMap.
end() && Pred(OMI->second)) {
635 Length = Name.
size();
662 Value = Arg.
substr(Length);
663 Arg = Arg.
substr(0, Length);
664 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
680 "Option can not be cl::Grouping AND cl::ValueRequired!");
687 }
while (PGOpt && Length != Arg.
size());
705 static bool isQuote(
char C) {
return C ==
'\"' || C ==
'\''; }
711 for (
size_t I = 0,
E = Src.
size();
I !=
E; ++
I) {
716 if (MarkEOLs && Src[I] ==
'\n')
725 if (
I + 1 <
E && Src[
I] ==
'\\') {
733 char Quote = Src[I++];
734 while (I !=
E && Src[I] != Quote) {
736 if (Src[I] ==
'\\' && I + 1 !=
E)
784 size_t E = Src.
size();
785 int BackslashCount = 0;
790 }
while (I != E && Src[I] ==
'\\');
792 bool FollowedByDoubleQuote = (I != E && Src[
I] ==
'"');
793 if (FollowedByDoubleQuote) {
794 Token.
append(BackslashCount / 2,
'\\');
795 if (BackslashCount % 2 == 0)
800 Token.
append(BackslashCount,
'\\');
811 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
812 for (
size_t I = 0,
E = Src.
size();
I !=
E; ++
I) {
818 if (MarkEOLs && Src[I] ==
'\n')
826 if (Src[I] ==
'\\') {
838 if (State == UNQUOTED) {
845 if (MarkEOLs && Src[I] ==
'\n')
853 if (Src[I] ==
'\\') {
862 if (State == QUOTED) {
867 if (Src[
I] ==
'\\') {
885 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
891 bool MarkEOLs,
bool RelativeNames) {
911 Str =
StringRef(BufRef.data() + 3, BufRef.size() - 3);
914 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
920 for (
unsigned I = 0;
I < NewArgv.
size(); ++
I)
923 if (Arg.
front() ==
'@') {
927 ResponseFile.
append(1,
'@');
935 NewArgv[
I] = Saver.
save(ResponseFile.
c_str()).data();
947 bool MarkEOLs,
bool RelativeNames) {
948 unsigned RspFiles = 0;
949 bool AllExpanded =
true;
952 for (
unsigned I = 0;
I != Argv.
size();) {
953 const char *Arg = Argv[
I];
955 if (Arg ==
nullptr) {
973 MarkEOLs, RelativeNames)) {
992 const char *Overview) {
994 assert(progName &&
"Program name not specified");
995 assert(envVar &&
"Environment variable name missing");
1012 int newArgc =
static_cast<int>(newArgv.
size());
1018 return GlobalParser->ParseCommandLineOptions(argc, argv, Overview,
1025 for (
auto SC : RegisteredSubCommands) {
1032 const char *
const *
argv,
1035 assert(hasOptions() &&
"No options specified!");
1043 argc =
static_cast<int>(newArgv.size());
1048 ProgramOverview = Overview;
1049 bool IgnoreErrors = Errs;
1052 bool ErrorParsing =
false;
1055 unsigned NumPositionalRequired = 0;
1058 bool HasUnlimitedPositionals =
false;
1062 if (argc >= 2 && argv[FirstArg][0] !=
'-') {
1065 ChosenSubCommand = LookupSubCommand(
StringRef(argv[FirstArg]));
1071 assert(ChosenSubCommand);
1074 auto &SinkOpts = ChosenSubCommand->
SinkOpts;
1075 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1077 if (ConsumeAfterOpt) {
1078 assert(PositionalOpts.size() > 0 &&
1079 "Cannot specify cl::ConsumeAfter without a positional argument!");
1081 if (!PositionalOpts.empty()) {
1084 bool UnboundedFound =
false;
1085 for (
size_t i = 0, e = PositionalOpts.size(); i != e; ++i) {
1086 Option *Opt = PositionalOpts[i];
1088 ++NumPositionalRequired;
1089 else if (ConsumeAfterOpt) {
1092 if (PositionalOpts.size() > 1) {
1094 Opt->
error(
"error - this positional option will never be matched, "
1095 "because it does not Require a value, and a "
1096 "cl::ConsumeAfter option is active!");
1097 ErrorParsing =
true;
1099 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1105 Opt->
error(
"error - option can never match, because "
1106 "another positional argument will match an "
1107 "unbounded number of values, and this option"
1108 " does not require a value!");
1109 *Errs << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr
1110 <<
"' is all messed up!\n";
1111 *Errs << PositionalOpts.size();
1112 ErrorParsing =
true;
1116 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1127 Option *ActivePositionalArg =
nullptr;
1130 bool DashDashFound =
false;
1131 for (
int i = FirstArg; i < argc; ++i) {
1132 Option *Handler =
nullptr;
1133 Option *NearestHandler =
nullptr;
1134 std::string NearestHandlerString;
1142 if (argv[i][0] !=
'-' || argv[i][1] == 0 || DashDashFound) {
1144 if (ActivePositionalArg) {
1149 if (!PositionalOpts.empty()) {
1155 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
1156 for (++i; i < argc; ++i)
1164 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
1166 DashDashFound =
true;
1168 }
else if (ActivePositionalArg &&
1175 while (!ArgName.
empty() && ArgName[0] ==
'-')
1176 ArgName = ArgName.
substr(1);
1178 Handler = LookupOption(*ChosenSubCommand, ArgName, Value);
1187 while (!ArgName.
empty() && ArgName[0] ==
'-')
1188 ArgName = ArgName.
substr(1);
1190 Handler = LookupOption(*ChosenSubCommand, ArgName, Value);
1199 if (!Handler && SinkOpts.empty())
1205 if (SinkOpts.empty()) {
1206 *Errs << ProgramName <<
": Unknown command line argument '" << argv[i]
1207 <<
"'. Try: '" << argv[0] <<
" -help'\n";
1209 if (NearestHandler) {
1211 *Errs << ProgramName <<
": Did you mean '-" << NearestHandlerString
1215 ErrorParsing =
true;
1220 (*I)->addOccurrence(i,
"",
StringRef(argv[i]));
1228 ActivePositionalArg = Handler;
1230 ErrorParsing |=
ProvideOption(Handler, ArgName, Value, argc, argv, i);
1234 if (NumPositionalRequired > PositionalVals.
size()) {
1235 *Errs << ProgramName
1236 <<
": Not enough positional command line arguments specified!\n"
1237 <<
"Must specify at least " << NumPositionalRequired
1238 <<
" positional argument" << (NumPositionalRequired > 1 ?
"s" :
"")
1239 <<
": See: " << argv[0] <<
" -help\n";
1241 ErrorParsing =
true;
1242 }
else if (!HasUnlimitedPositionals &&
1243 PositionalVals.
size() > PositionalOpts.size()) {
1244 *Errs << ProgramName <<
": Too many positional arguments specified!\n"
1245 <<
"Can specify at most " << PositionalOpts.size()
1246 <<
" positional arguments: See: " << argv[0] <<
" -help\n";
1247 ErrorParsing =
true;
1249 }
else if (!ConsumeAfterOpt) {
1251 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1252 for (
size_t i = 0, e = PositionalOpts.size(); i != e; ++i) {
1255 PositionalVals[ValNo].
second);
1257 --NumPositionalRequired;
1264 bool Done = PositionalOpts[i]->getNumOccurrencesFlag() ==
cl::Required;
1265 while (NumVals - ValNo > NumPositionalRequired && !Done) {
1266 switch (PositionalOpts[i]->getNumOccurrencesFlag()) {
1273 PositionalVals[ValNo].
first,
1274 PositionalVals[ValNo].
second);
1279 "positional argument processing!");
1284 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1286 for (
size_t j = 1, e = PositionalOpts.size(); j != e; ++j)
1289 PositionalVals[ValNo].
first,
1290 PositionalVals[ValNo].
second);
1299 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1301 PositionalVals[ValNo].
first,
1302 PositionalVals[ValNo].
second);
1308 for (; ValNo != PositionalVals.
size(); ++ValNo)
1311 PositionalVals[ValNo].
second);
1315 for (
const auto &Opt : OptionsMap) {
1320 Opt.second->
error(
"must be specified at least once!");
1321 ErrorParsing =
true;
1333 for (
int i = 0; i < argc; ++i)
dbgs() << argv[i] <<
' ';
1354 if (!ArgName.
data())
1356 if (ArgName.
empty())
1361 errs() <<
" option: " << Message <<
"\n";
1372 if (NumOccurrences > 1)
1373 return error(
"may only occur zero or one times!", ArgName);
1376 if (NumOccurrences > 1)
1377 return error(
"must occur exactly one time!", ArgName);
1385 return handleOccurrence(pos, ArgName, Value);
1402 size_t alias::getOptionWidth()
const {
return ArgStr.
size() + 6; }
1405 size_t FirstLineIndentedBy) {
1406 std::pair<StringRef, StringRef>
Split = HelpStr.
split(
'\n');
1407 outs().
indent(Indent - FirstLineIndentedBy) <<
" - " << Split.first <<
"\n";
1408 while (!Split.second.empty()) {
1409 Split = Split.second.split(
'\n');
1410 outs().
indent(Indent) << Split.first <<
"\n";
1415 void alias::printOptionInfo(
size_t GlobalWidth)
const {
1431 if (!ValName.empty())
1441 size_t GlobalWidth)
const {
1445 if (!ValName.empty())
1452 size_t GlobalWidth)
const {
1461 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1467 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1471 return O.
error(
"'" + Arg +
1472 "' is invalid value for boolean argument! Try 0 or 1");
1479 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1484 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1489 return O.
error(
"'" + Arg +
1490 "' is invalid value for boolean argument! Try 0 or 1");
1498 return O.
error(
"'" + Arg +
"' value invalid for integer argument!");
1508 return O.
error(
"'" + Arg +
"' value invalid for uint argument!");
1516 unsigned long long &Value) {
1519 return O.
error(
"'" + Arg +
"' value invalid for uint argument!");
1528 return O.
error(
"'" + Arg +
"' value invalid for floating point argument!");
1554 for (
unsigned i = 0; i != e; ++i) {
1569 size_t BaseSize = 0;
1580 size_t GlobalWidth)
const {
1613 for (
unsigned i = 0; i != NumOpts; ++i) {
1621 for (
unsigned j = 0; j != NumOpts; ++j) {
1630 outs() <<
"= *unknown option value*\n";
1635 #define PRINT_OPT_DIFF(T) \
1636 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
1637 size_t GlobalWidth) const { \
1638 printOptionName(O, GlobalWidth); \
1641 raw_string_ostream SS(Str); \
1644 outs() << "= " << Str; \
1645 size_t NumSpaces = \
1646 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
1647 outs().indent(NumSpaces) << " (default: "; \
1649 outs() << D.getValue(); \
1651 outs() << "*no default*"; \
1666 size_t GlobalWidth)
const {
1667 printOptionName(O, GlobalWidth);
1668 outs() <<
"= " << V;
1672 outs() << D.getValue();
1674 outs() <<
"*no default*";
1680 size_t GlobalWidth)
const {
1682 outs() <<
"= *cannot print option value*\n";
1690 const std::pair<const char *, Option *> *RHS) {
1691 return strcmp(LHS->first, RHS->first);
1695 const std::pair<const char *, SubCommand *> *RHS) {
1696 return strcmp(LHS->first, RHS->first);
1712 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
1716 if (!OptionSet.
insert(
I->second).second)
1720 std::pair<const char *, Option *>(
I->getKey().data(),
I->second));
1730 for (
const auto &S : SubMap) {
1731 if (S->getName().empty())
1733 Subs.push_back(std::make_pair(S->getName().data(), S));
1742 const bool ShowHidden;
1744 StrOptionPairVector;
1746 StrSubCommandPairVector;
1748 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
1749 for (
size_t i = 0, e = Opts.size(); i != e; ++i)
1750 Opts[i].
second->printOptionInfo(MaxArgLen);
1753 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
1754 for (
const auto &S : Subs) {
1755 outs() <<
" " << S.first;
1756 if (!S.second->getDescription().empty()) {
1758 outs() <<
" - " << S.second->getDescription();
1765 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
1766 virtual ~HelpPrinter() {}
1769 void operator=(
bool Value) {
1778 StrOptionPairVector Opts;
1779 sortOpts(OptionsMap, Opts, ShowHidden);
1781 StrSubCommandPairVector Subs;
1789 if (Subs.size() > 2)
1790 outs() <<
" [subcommand]";
1791 outs() <<
" [options]";
1801 for (
auto Opt : PositionalOpts) {
1808 if (ConsumeAfterOpt)
1809 outs() <<
" " << ConsumeAfterOpt->HelpStr;
1813 size_t MaxSubLen = 0;
1814 for (
size_t i = 0, e = Subs.size(); i != e; ++i)
1818 outs() <<
"SUBCOMMANDS:\n\n";
1819 printSubCommands(Subs, MaxSubLen);
1822 <<
" <subcommand> -help\" to get more help on a specific "
1829 size_t MaxArgLen = 0;
1830 for (
size_t i = 0, e = Opts.size(); i != e; ++i)
1831 MaxArgLen =
std::max(MaxArgLen, Opts[i].
second->getOptionWidth());
1833 outs() <<
"OPTIONS:\n";
1834 printOptions(Opts, MaxArgLen);
1846 class CategorizedHelpPrinter :
public HelpPrinter {
1848 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
1856 return (*A)->getName().compare((*B)->getName());
1860 using HelpPrinter::operator=;
1863 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
1864 std::vector<OptionCategory *> SortedCategories;
1865 std::map<OptionCategory *, std::vector<Option *>> CategorizedOptions;
1869 for (
auto I =
GlobalParser->RegisteredOptionCategories.begin(),
1872 SortedCategories.push_back(*
I);
1876 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
1878 OptionCategoryCompare);
1881 for (std::vector<OptionCategory *>::const_iterator
1882 I = SortedCategories.begin(),
1883 E = SortedCategories.end();
1885 CategorizedOptions[*
I] = std::vector<Option *>();
1890 for (
size_t I = 0,
E = Opts.size();
I !=
E; ++
I) {
1893 "Option has an unregistered category");
1894 CategorizedOptions[Opt->
Category].push_back(Opt);
1898 for (std::vector<OptionCategory *>::const_iterator
1899 Category = SortedCategories.begin(),
1900 E = SortedCategories.end();
1903 const auto &CategoryOptions = CategorizedOptions[*
Category];
1904 bool IsEmptyCategory = CategoryOptions.empty();
1905 if (!ShowHidden && IsEmptyCategory)
1910 outs() << (*Category)->getName() <<
":\n";
1913 if (!(*Category)->getDescription().empty())
1914 outs() << (*Category)->getDescription() <<
"\n\n";
1920 if (IsEmptyCategory) {
1921 outs() <<
" This option category has no options.\n";
1925 for (
const Option *Opt : CategoryOptions)
1933 class HelpPrinterWrapper {
1935 HelpPrinter &UncategorizedPrinter;
1936 CategorizedHelpPrinter &CategorizedPrinter;
1939 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
1940 CategorizedHelpPrinter &CategorizedPrinter)
1941 : UncategorizedPrinter(UncategorizedPrinter),
1942 CategorizedPrinter(CategorizedPrinter) {}
1945 void operator=(
bool Value);
1972 cl::desc(
"Display list of available options (-help-list-hidden for more)"),
1977 HLHOp(
"help-list-hidden",
cl::desc(
"Display list of all available options"),
1986 HOp(
"help",
cl::desc(
"Display available options (-help-hidden for more)"),
1991 HHOp(
"help-hidden",
cl::desc(
"Display all available options"),
1997 cl::desc(
"Print non-default options after command line parsing"),
2002 "print-all-options",
2006 void HelpPrinterWrapper::operator=(
bool Value) {
2013 if (
GlobalParser->RegisteredOptionCategories.size() > 1) {
2018 CategorizedPrinter =
true;
2020 UncategorizedPrinter =
true;
2026 void CommandLineParser::printOptionValues() {
2030 SmallVector<std::pair<const char *, Option *>, 128> Opts;
2031 sortOpts(ActiveSubCommand->OptionsMap, Opts,
true);
2034 size_t MaxArgLen = 0;
2035 for (
size_t i = 0, e = Opts.
size(); i != e; ++i)
2036 MaxArgLen =
std::max(MaxArgLen, Opts[i].
second->getOptionWidth());
2038 for (
size_t i = 0, e = Opts.
size(); i != e; ++i)
2047 class VersionPrinter {
2051 #ifdef PACKAGE_VENDOR
2052 OS << PACKAGE_VENDOR <<
" ";
2054 OS <<
"LLVM (http://llvm.org/):\n ";
2056 OS << PACKAGE_NAME <<
" version " << PACKAGE_VERSION;
2057 #ifdef LLVM_VERSION_INFO
2058 OS <<
" " << LLVM_VERSION_INFO;
2061 #ifndef __OPTIMIZE__
2062 OS <<
"DEBUG build";
2064 OS <<
"Optimized build";
2067 OS <<
" with assertions";
2069 #if LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO
2071 if (CPU ==
"generic")
2075 <<
" Host CPU: " << CPU;
2079 void operator=(
bool OptionWasSpecified) {
2080 if (!OptionWasSpecified)
2084 (*OverrideVersionPrinter)();
2108 VersOp(
"version",
cl::desc(
"Display the version of this program"),
2121 if (!Hidden && !Categorized)
2123 else if (!Hidden && Categorized)
2125 else if (Hidden && !Categorized)
2157 if (
I.second->Category != &Category &&
2165 auto CategoriesBegin = Categories.
begin();
2166 auto CategoriesEnd = Categories.
end();
2168 if (
std::find(CategoriesBegin, CategoriesEnd,
I.second->Category) ==
2181 const char *Overview) {
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
bool isPositional() const
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
bool hasUTF16ByteOrderMark(ArrayRef< char > SrcBytes)
Returns true if a blob of text starts with a UTF-16 big or little endian byte order mark...
void push_back(const T &Elt)
StringRef getName() const
void ResetCommandLineParser()
Reset the command line parser back to its initial state.
Represents either an error or a value T.
static bool isQuote(char C)
static bool ExpandResponseFile(StringRef FName, StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs, bool RelativeNames)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual StringRef getValueName() const
OptionCategory GeneralCategory
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static Option * HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value, bool &ErrorParsing, const StringMap< Option * > &OptionsMap)
HandlePrefixedOrGroupedOption - The specified argument string (which started with at least one '-') d...
static void Help(ArrayRef< SubtargetFeatureKV > CPUTable, ArrayRef< SubtargetFeatureKV > FeatTable)
Display help for feature choices.
static bool isPrefixedOrGrouping(const Option *O)
static bool parseDouble(Option &O, StringRef Arg, double &Value)
const char * getBufferStart() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
static bool isGrouping(const Option *O)
static cl::opt< bool > PrintAllOptions("print-all-options", cl::desc("Print all option values after command line parsing"), cl::Hidden, cl::init(false), cl::cat(GenericCategory), cl::sub(*AllSubCommands))
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
void setArgStr(StringRef S)
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
void PrintVersionMessage()
Utility function for printing version number.
static cl::opt< VersionPrinter, true, parser< bool > > VersOp("version", cl::desc("Display the version of this program"), cl::location(VersionPrinterInstance), cl::ValueDisallowed, cl::cat(GenericCategory))
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
#define PRINT_OPT_DIFF(T)
void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
iterator find(StringRef Key)
void printOptionName(const Option &O, size_t GlobalWidth) const
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
void unregisterSubCommand()
void ParseEnvironmentOptions(const char *progName, const char *envvar, const char *Overview="")
ParseEnvironmentOptions - An alternative entry point to the CommandLine library, which allows you to ...
SmallVector< Option *, 4 > SinkOpts
void SetVersionPrinter(void(*func)())
===------------------------------------------------------------------—===// SetVersionPrinter - Overr...
static HelpPrinter UncategorizedHiddenPrinter(true)
static cl::opt< HelpPrinter, true, parser< bool > > HLHOp("help-list-hidden", cl::desc("Display list of all available options"), cl::location(UncategorizedHiddenPrinter), cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory), cl::sub(*AllSubCommands))
static void sortSubCommands(const SmallPtrSetImpl< SubCommand * > &SubMap, SmallVectorImpl< std::pair< const char *, SubCommand * >> &Subs)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
static StringRef getValueStr(const Option &O, StringRef DefaultMsg)
static cl::opt< HelpPrinter, true, parser< bool > > HLOp("help-list", cl::desc("Display list of available options (-help-list-hidden for more)"), cl::location(UncategorizedNormalPrinter), cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory), cl::sub(*AllSubCommands))
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
void LLVMParseCommandLineOptions(int argc, const char *const *argv, const char *Overview)
This function parses the given arguments using the LLVM command line parser.
virtual void printOptionInfo(size_t GlobalWidth) const =0
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static const size_t MaxOptWidth
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
static VersionPrinter VersionPrinterInstance
static cl::OptionCategory GenericCategory("Generic Options")
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
static int OptNameCompare(const std::pair< const char *, Option * > *LHS, const std::pair< const char *, Option * > *RHS)
virtual bool compare(const GenericOptionValue &V) const =0
LLVM_NODISCARD bool empty() const
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
void printOptionInfo(const Option &O, size_t GlobalWidth) const
static cl::opt< bool > PrintOptions("print-options", cl::desc("Print non-default options after command line parsing"), cl::Hidden, cl::init(false), cl::cat(GenericCategory), cl::sub(*AllSubCommands))
void AddExtraVersionPrinter(void(*func)())
===------------------------------------------------------------------—===// AddExtraVersionPrinter - ...
static size_t parseBackslash(StringRef Src, size_t I, SmallString< 128 > &Token)
Backslashes are interpreted in a rather complicated way in the Windows-style command line...
static HelpPrinter UncategorizedNormalPrinter(false)
SmallVector< Option *, 4 > PositionalOpts
bool isConsumeAfter() const
static ManagedStatic< CommandLineParser > GlobalParser
virtual StringRef getDescription(unsigned N) const =0
int getNumOccurrences() const
bool to_float(const Twine &T, float &Num)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD char front() const
front - Get the first character in the string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
size_t size() const
size - Get the array size.
ManagedStatic< SubCommand > AllSubCommands
static bool hasUTF8ByteOrderMark(ArrayRef< char > S)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
StringMap< Option * > OptionsMap
ManagedStatic< SubCommand > TopLevelSubCommand
static bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
void append(in_iter S, in_iter E)
Append from an iterator pair.
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
initializer< Ty > init(const Ty &Val)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
StringRef getName() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
StringMap< Option * > & getRegisteredOptions(SubCommand &Sub=*TopLevelSubCommand)
Use this to get a StringMap to all registered named options (e.g.
size_t getOptionWidth(const Option &O) const
Allocate memory in an ever growing pool, as if by bump-pointer.
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static void sortOpts(StringMap< Option * > &OptMap, SmallVectorImpl< std::pair< const char *, Option * >> &Opts, bool ShowHidden)
enum NumOccurrencesFlag getNumOccurrencesFlag() const
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...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void registerSubCommand()
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows command line which may contain quotes and escaped quotes.
virtual unsigned getNumOptions() const =0
static Option * LookupNearestOption(StringRef Arg, const StringMap< Option * > &OptionsMap, std::string &NearestString)
LookupNearestOption - Lookup the closest match to the option specified by the specified option on the...
OptionCategory * Category
static bool EatsUnboundedNumberOfValues(const Option *O)
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
virtual StringRef getOption(unsigned N) const =0
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr)
static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling ...
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
iterator erase(const_iterator CI)
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
LLVM_NODISCARD unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
void printOptionNoValue(const Option &O, size_t GlobalWidth) const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
enum FormattingFlags getFormattingFlag() const
static HelpPrinterWrapper WrappedNormalPrinter(UncategorizedNormalPrinter, CategorizedNormalPrinter)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static ManagedStatic< CodeViewErrorCategory > Category
CHAIN = SC CHAIN, Imm128 - System call.
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv, bool MarkEOLs=false, bool RelativeNames=false)
Expand response files on a command line recursively using the given StringSaver and tokenization stra...
static bool ProvideOption(Option *Handler, StringRef ArgName, StringRef Value, int argc, const char *const *argv, int &i)
ProvideOption - For Value, this differentiates between an empty value ("") and a null value (StringRe...
virtual size_t getOptionWidth(const Option &O) const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static int SubNameCompare(const std::pair< const char *, SubCommand * > *LHS, const std::pair< const char *, SubCommand * > *RHS)
A range adaptor for a pair of iterators.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool isInAllSubCommands() const
static bool isWhitespace(char C)
StringRef save(const char *S)
static void(* OverrideVersionPrinter)()
StringRef str() const
Explicit conversion to StringRef.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
typename SuperClass::iterator iterator
void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
static bool RequiresValue(const Option *O)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
iterator insert(iterator I, T &&Elt)
size_t getBufferSize() const
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=*TopLevelSubCommand)
Mark all options not part of this category as cl::ReallyHidden.
llvm_unreachable("Unknown RegBank!")
unsigned getNumAdditionalVals() const
enum ValueExpected getValueExpectedFlag() const
Saves strings in the inheritor's stable storage and returns a StringRef with a stable character point...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Provides a library for accessing information about this process and other processes on the operating ...
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
static CategorizedHelpPrinter CategorizedNormalPrinter(false)
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
static cl::opt< HelpPrinterWrapper, true, parser< bool > > HOp("help", cl::desc("Display available options (-help-hidden for more)"), cl::location(WrappedNormalPrinter), cl::ValueDisallowed, cl::cat(GenericCategory), cl::sub(*AllSubCommands))
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
virtual void getExtraOptionNames(SmallVectorImpl< StringRef > &)
void removeArgument()
Unregisters this option from the CommandLine system.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
SmallPtrSet< SubCommand *, 4 > Subs
const char * getBufferEnd() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef getDescription() const
static cl::opt< HelpPrinterWrapper, true, parser< bool > > HHOp("help-hidden", cl::desc("Display all available options"), cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory), cl::sub(*AllSubCommands))
LLVM Value Representation.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static Option * getOptionPred(StringRef Name, size_t &Length, bool(*Pred)(const Option *), const StringMap< Option * > &OptionsMap)
static CategorizedHelpPrinter CategorizedHiddenPrinter(true)
static std::vector< void(*)()> * ExtraVersionPrinters
bool error(const Twine &Message, StringRef ArgName=StringRef())
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
unsigned findOption(StringRef Name)
iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
static Optional< std::string > GetEnv(StringRef name)
static HelpPrinterWrapper WrappedHiddenPrinter(UncategorizedHiddenPrinter, CategorizedHiddenPrinter)
LocationClass< Ty > location(Ty &L)
unsigned getMiscFlags() const
auto count_if(R &&Range, UnaryPredicate P) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.