29 #include "llvm/Config/config.h"
46 #define DEBUG_TYPE "commandline"
48 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
83 void GenericOptionValue::anchor() {}
86 void Option::anchor() {}
102 class CommandLineParser {
106 std::string ProgramName;
110 std::vector<StringRef> MoreHelp;
118 CommandLineParser() : ActiveSubCommand(nullptr) {
131 if (!SC->
OptionsMap.insert(std::make_pair(Name, &Opt)).second) {
132 errs() << ProgramName <<
": CommandLine Error: Option '" << Name
133 <<
"' registered more than once!\n";
140 for (
const auto &Sub : RegisteredSubCommands) {
143 addLiteralOption(Opt, Sub, Name);
149 if (Opt.
Subs.empty())
152 for (
auto SC : Opt.
Subs)
153 addLiteralOption(Opt, SC, Name);
158 bool HadErrors =
false;
162 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr
163 <<
"' registered more than once!\n";
175 O->
error(
"Cannot specify more than one option with cl::ConsumeAfter!");
191 for (
const auto &Sub : RegisteredSubCommands) {
199 void addOption(
Option *O) {
200 if (O->
Subs.empty()) {
203 for (
auto SC : O->
Subs)
215 for (
auto Name : OptionNames)
237 void removeOption(
Option *O) {
242 for (
auto SC : RegisteredSubCommands)
245 for (
auto SC : O->
Subs)
251 bool hasOptions(
const SubCommand &Sub)
const {
256 bool hasOptions()
const {
257 for (
const auto &S : RegisteredSubCommands) {
264 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
268 if (!Sub.
OptionsMap.insert(std::make_pair(NewName, O)).second) {
269 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr
270 <<
"' registered more than once!\n";
280 for (
auto SC : O->
Subs)
281 updateArgStr(O, NewName, SC);
285 void printOptionValues();
292 "Duplicate option categories");
294 RegisteredOptionCategories.
insert(cat);
303 "Duplicate subcommands");
304 RegisteredSubCommands.insert(sub);
315 addLiteralOption(*O, sub,
E.first());
321 RegisteredSubCommands.erase(sub);
326 return make_range(RegisteredSubCommands.begin(),
327 RegisteredSubCommands.end());
331 ActiveSubCommand =
nullptr;
336 RegisteredOptionCategories.
clear();
339 RegisteredSubCommands.clear();
376 assert((S.
empty() || S[0] !=
'-') &&
"Option can't start with '-");
383 void OptionCategory::registerCategory() {
409 SubCommand::operator
bool()
const {
427 size_t EqualPos = Arg.
find(
'=');
445 Value = Arg.
substr(EqualPos + 1);
446 Arg = Arg.
substr(0, EqualPos);
453 for (
auto S : RegisteredSubCommands) {
456 if (S->getName().empty())
471 std::string &NearestString) {
477 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
483 unsigned BestDistance = 0;
485 ie = OptionsMap.
end();
495 for (
auto Name : OptionNames) {
497 Flag,
true, BestDistance);
498 if (!Best || Distance < BestDistance) {
500 BestDistance = Distance;
501 if (RHS.
empty() || !PermitValue)
502 NearestString = Name;
504 NearestString = (
Twine(Name) +
"=" + RHS).str();
516 bool MultiArg =
false) {
528 Val = Val.
substr(Pos + 1);
536 return Handler->
addOccurrence(pos, ArgName, Value, MultiArg);
544 const char *
const *
argv,
int &
i) {
553 return Handler->
error(
"requires a value!");
555 assert(argv &&
"null check");
560 if (NumAdditionalVals > 0)
561 return Handler->
error(
"multi-valued option specified"
562 " with ValueDisallowed modifier!");
565 return Handler->
error(
"does not allow a value! '" +
Twine(Value) +
573 if (NumAdditionalVals == 0)
577 bool MultiArg =
false;
586 while (NumAdditionalVals > 0) {
588 return Handler->
error(
"not enough values!");
589 assert(argv &&
"null check");
620 bool (*Pred)(
const Option *),
628 while (OMI == OptionsMap.
end() && Name.
size() > 1) {
630 OMI = OptionsMap.
find(Name);
633 if (OMI != OptionsMap.
end() && Pred(OMI->
second)) {
634 Length = Name.
size();
661 Value = Arg.
substr(Length);
662 Arg = Arg.
substr(0, Length);
663 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
679 "Option can not be cl::Grouping AND cl::ValueRequired!");
686 }
while (PGOpt && Length != Arg.
size());
704 static bool isQuote(
char C) {
return C ==
'\"' || C ==
'\''; }
710 for (
size_t I = 0,
E = Src.
size();
I !=
E; ++
I) {
715 if (MarkEOLs && Src[I] ==
'\n')
724 if (
I + 1 <
E && Src[
I] ==
'\\') {
732 char Quote = Src[I++];
733 while (I !=
E && Src[I] != Quote) {
735 if (Src[I] ==
'\\' && I + 1 !=
E)
783 size_t E = Src.
size();
784 int BackslashCount = 0;
789 }
while (I != E && Src[I] ==
'\\');
791 bool FollowedByDoubleQuote = (I != E && Src[
I] ==
'"');
792 if (FollowedByDoubleQuote) {
793 Token.
append(BackslashCount / 2,
'\\');
794 if (BackslashCount % 2 == 0)
799 Token.
append(BackslashCount,
'\\');
810 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
811 for (
size_t I = 0,
E = Src.
size();
I !=
E; ++
I) {
817 if (MarkEOLs && Src[I] ==
'\n')
825 if (Src[I] ==
'\\') {
837 if (State == UNQUOTED) {
844 if (MarkEOLs && Src[I] ==
'\n')
852 if (Src[I] ==
'\\') {
861 if (State == QUOTED) {
866 if (Src[
I] ==
'\\') {
884 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
890 bool MarkEOLs,
bool RelativeNames) {
910 Str =
StringRef(BufRef.data() + 3, BufRef.size() - 3);
913 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
919 for (
unsigned I = 0;
I < NewArgv.
size(); ++
I)
922 if (Arg.
front() ==
'@') {
926 ResponseFile.
append(1,
'@');
934 NewArgv[
I] = Saver.
save(ResponseFile.
c_str()).data();
946 bool MarkEOLs,
bool RelativeNames) {
947 unsigned RspFiles = 0;
948 bool AllExpanded =
true;
951 for (
unsigned I = 0;
I != Argv.
size();) {
952 const char *Arg = Argv[
I];
954 if (Arg ==
nullptr) {
972 MarkEOLs, RelativeNames)) {
991 const char *Overview) {
993 assert(progName &&
"Program name not specified");
994 assert(envVar &&
"Environment variable name missing");
1011 int newArgc =
static_cast<int>(newArgv.
size());
1016 StringRef Overview,
bool IgnoreErrors) {
1017 return GlobalParser->ParseCommandLineOptions(argc, argv, Overview,
1024 for (
auto SC : RegisteredSubCommands) {
1031 const char *
const *
argv,
1033 bool IgnoreErrors) {
1034 assert(hasOptions() &&
"No options specified!");
1042 argc =
static_cast<int>(newArgv.size());
1047 ProgramOverview = Overview;
1048 bool ErrorParsing =
false;
1051 unsigned NumPositionalRequired = 0;
1054 bool HasUnlimitedPositionals =
false;
1058 if (argc >= 2 && argv[FirstArg][0] !=
'-') {
1061 ChosenSubCommand = LookupSubCommand(
StringRef(argv[FirstArg]));
1067 assert(ChosenSubCommand);
1070 auto &SinkOpts = ChosenSubCommand->
SinkOpts;
1071 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1073 if (ConsumeAfterOpt) {
1074 assert(PositionalOpts.size() > 0 &&
1075 "Cannot specify cl::ConsumeAfter without a positional argument!");
1077 if (!PositionalOpts.empty()) {
1080 bool UnboundedFound =
false;
1081 for (
size_t i = 0, e = PositionalOpts.size();
i != e; ++
i) {
1082 Option *Opt = PositionalOpts[
i];
1084 ++NumPositionalRequired;
1085 else if (ConsumeAfterOpt) {
1088 if (PositionalOpts.size() > 1) {
1090 Opt->
error(
"error - this positional option will never be matched, "
1091 "because it does not Require a value, and a "
1092 "cl::ConsumeAfter option is active!");
1093 ErrorParsing =
true;
1095 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1100 if (!IgnoreErrors) {
1101 Opt->
error(
"error - option can never match, because "
1102 "another positional argument will match an "
1103 "unbounded number of values, and this option"
1104 " does not require a value!");
1105 errs() << ProgramName <<
": CommandLine Error: Option '"
1106 << Opt->
ArgStr <<
"' is all messed up!\n";
1107 errs() << PositionalOpts.size();
1109 ErrorParsing =
true;
1113 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1124 Option *ActivePositionalArg =
nullptr;
1127 bool DashDashFound =
false;
1128 for (
int i = FirstArg;
i < argc; ++
i) {
1129 Option *Handler =
nullptr;
1130 Option *NearestHandler =
nullptr;
1131 std::string NearestHandlerString;
1139 if (argv[
i][0] !=
'-' || argv[
i][1] == 0 || DashDashFound) {
1141 if (ActivePositionalArg) {
1146 if (!PositionalOpts.empty()) {
1152 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
1153 for (++i; i < argc; ++
i)
1161 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
1163 DashDashFound =
true;
1165 }
else if (ActivePositionalArg &&
1172 while (!ArgName.
empty() && ArgName[0] ==
'-')
1173 ArgName = ArgName.
substr(1);
1175 Handler = LookupOption(*ChosenSubCommand, ArgName, Value);
1184 while (!ArgName.
empty() && ArgName[0] ==
'-')
1185 ArgName = ArgName.
substr(1);
1187 Handler = LookupOption(*ChosenSubCommand, ArgName, Value);
1196 if (!Handler && SinkOpts.empty())
1202 if (SinkOpts.empty()) {
1203 if (!IgnoreErrors) {
1204 errs() << ProgramName <<
": Unknown command line argument '"
1205 << argv[
i] <<
"'. Try: '" << argv[0] <<
" -help'\n";
1207 if (NearestHandler) {
1209 errs() << ProgramName <<
": Did you mean '-" << NearestHandlerString
1214 ErrorParsing =
true;
1219 (*I)->addOccurrence(i,
"",
StringRef(argv[i]));
1227 ActivePositionalArg = Handler;
1229 ErrorParsing |=
ProvideOption(Handler, ArgName, Value, argc, argv, i);
1233 if (NumPositionalRequired > PositionalVals.
size()) {
1234 if (!IgnoreErrors) {
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";
1242 ErrorParsing =
true;
1243 }
else if (!HasUnlimitedPositionals &&
1244 PositionalVals.
size() > PositionalOpts.size()) {
1245 if (!IgnoreErrors) {
1246 errs() << ProgramName <<
": Too many positional arguments specified!\n"
1247 <<
"Can specify at most " << PositionalOpts.size()
1248 <<
" positional arguments: See: " << argv[0] <<
" -help\n";
1250 ErrorParsing =
true;
1252 }
else if (!ConsumeAfterOpt) {
1254 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1255 for (
size_t i = 0, e = PositionalOpts.size(); i != e; ++
i) {
1258 PositionalVals[ValNo].second);
1260 --NumPositionalRequired;
1267 bool Done = PositionalOpts[
i]->getNumOccurrencesFlag() ==
cl::Required;
1268 while (NumVals - ValNo > NumPositionalRequired && !Done) {
1269 switch (PositionalOpts[i]->getNumOccurrencesFlag()) {
1276 PositionalVals[ValNo].first,
1277 PositionalVals[ValNo].second);
1282 "positional argument processing!");
1287 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1289 for (
size_t j = 1, e = PositionalOpts.size(); j != e; ++j)
1292 PositionalVals[ValNo].first,
1293 PositionalVals[ValNo].second);
1302 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1304 PositionalVals[ValNo].first,
1305 PositionalVals[ValNo].second);
1311 for (; ValNo != PositionalVals.
size(); ++ValNo)
1314 PositionalVals[ValNo].second);
1318 for (
const auto &Opt : OptionsMap) {
1323 Opt.second->
error(
"must be specified at least once!");
1324 ErrorParsing =
true;
1336 for (
int i = 0; i < argc; ++
i)
dbgs() << argv[i] <<
' ';
1357 if (!ArgName.
data())
1359 if (ArgName.
empty())
1364 errs() <<
" option: " << Message <<
"\n";
1375 if (NumOccurrences > 1)
1376 return error(
"may only occur zero or one times!", ArgName);
1379 if (NumOccurrences > 1)
1380 return error(
"must occur exactly one time!", ArgName);
1388 return handleOccurrence(pos, ArgName, Value);
1405 size_t alias::getOptionWidth()
const {
return ArgStr.
size() + 6; }
1408 size_t FirstLineIndentedBy) {
1409 std::pair<StringRef, StringRef>
Split = HelpStr.
split(
'\n');
1410 outs().
indent(Indent - FirstLineIndentedBy) <<
" - " << Split.first <<
"\n";
1411 while (!Split.second.empty()) {
1412 Split = Split.second.split(
'\n');
1413 outs().
indent(Indent) << Split.first <<
"\n";
1418 void alias::printOptionInfo(
size_t GlobalWidth)
const {
1434 if (!ValName.empty())
1444 size_t GlobalWidth)
const {
1448 if (!ValName.empty())
1455 size_t GlobalWidth)
const {
1464 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1470 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1474 return O.
error(
"'" + Arg +
1475 "' is invalid value for boolean argument! Try 0 or 1");
1482 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1487 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1492 return O.
error(
"'" + Arg +
1493 "' is invalid value for boolean argument! Try 0 or 1");
1501 return O.
error(
"'" + Arg +
"' value invalid for integer argument!");
1511 return O.
error(
"'" + Arg +
"' value invalid for uint argument!");
1519 unsigned long long &Value) {
1522 return O.
error(
"'" + Arg +
"' value invalid for uint argument!");
1530 const char *ArgStart = TmpStr.
c_str();
1532 Value = strtod(ArgStart, &End);
1534 return O.
error(
"'" + Arg +
"' value invalid for floating point argument!");
1561 for (
unsigned i = 0; i != e; ++
i) {
1573 Size = std::max(Size,
getOption(i).size() + 8);
1576 size_t BaseSize = 0;
1578 BaseSize = std::max(BaseSize,
getOption(i).size() + 8);
1587 size_t GlobalWidth)
const {
1620 for (
unsigned i = 0; i != NumOpts; ++
i) {
1628 for (
unsigned j = 0; j != NumOpts; ++j) {
1637 outs() <<
"= *unknown option value*\n";
1642 #define PRINT_OPT_DIFF(T) \
1643 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
1644 size_t GlobalWidth) const { \
1645 printOptionName(O, GlobalWidth); \
1648 raw_string_ostream SS(Str); \
1651 outs() << "= " << Str; \
1652 size_t NumSpaces = \
1653 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
1654 outs().indent(NumSpaces) << " (default: "; \
1656 outs() << D.getValue(); \
1658 outs() << "*no default*"; \
1673 size_t GlobalWidth)
const {
1674 printOptionName(O, GlobalWidth);
1675 outs() <<
"= " << V;
1679 outs() << D.getValue();
1681 outs() <<
"*no default*";
1687 size_t GlobalWidth)
const {
1689 outs() <<
"= *cannot print option value*\n";
1697 const std::pair<const char *, Option *> *RHS) {
1698 return strcmp(LHS->first, RHS->first);
1702 const std::pair<const char *, SubCommand *> *RHS) {
1703 return strcmp(LHS->first, RHS->first);
1719 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
1723 if (!OptionSet.
insert(
I->second).second)
1727 std::pair<const char *, Option *>(
I->getKey().data(),
I->second));
1737 for (
const auto &S : SubMap) {
1738 if (S->getName().empty())
1740 Subs.push_back(std::make_pair(S->getName().data(), S));
1749 const bool ShowHidden;
1751 StrOptionPairVector;
1753 StrSubCommandPairVector;
1755 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
1756 for (
size_t i = 0, e = Opts.size(); i != e; ++
i)
1757 Opts[i].second->printOptionInfo(MaxArgLen);
1760 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
1761 for (
const auto &S : Subs) {
1762 outs() <<
" " << S.first;
1763 if (!S.second->getDescription().empty()) {
1765 outs() <<
" - " << S.second->getDescription();
1772 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
1773 virtual ~HelpPrinter() {}
1776 void operator=(
bool Value) {
1785 StrOptionPairVector Opts;
1786 sortOpts(OptionsMap, Opts, ShowHidden);
1788 StrSubCommandPairVector Subs;
1796 if (Subs.size() > 2)
1797 outs() <<
" [subcommand]";
1798 outs() <<
" [options]";
1808 for (
auto Opt : PositionalOpts) {
1815 if (ConsumeAfterOpt)
1816 outs() <<
" " << ConsumeAfterOpt->HelpStr;
1820 size_t MaxSubLen = 0;
1821 for (
size_t i = 0, e = Subs.size(); i != e; ++
i)
1822 MaxSubLen = std::max(MaxSubLen, strlen(Subs[i].first));
1825 outs() <<
"SUBCOMMANDS:\n\n";
1826 printSubCommands(Subs, MaxSubLen);
1829 <<
" <subcommand> -help\" to get more help on a specific "
1836 size_t MaxArgLen = 0;
1837 for (
size_t i = 0, e = Opts.size(); i != e; ++
i)
1838 MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
1840 outs() <<
"OPTIONS:\n";
1841 printOptions(Opts, MaxArgLen);
1853 class CategorizedHelpPrinter :
public HelpPrinter {
1855 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
1862 return (*A)->getName() == (*B)->getName();
1866 using HelpPrinter::operator=;
1869 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
1870 std::vector<OptionCategory *> SortedCategories;
1871 std::map<OptionCategory *, std::vector<Option *>> CategorizedOptions;
1875 for (
auto I =
GlobalParser->RegisteredOptionCategories.begin(),
1878 SortedCategories.push_back(*
I);
1882 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
1884 OptionCategoryCompare);
1887 for (std::vector<OptionCategory *>::const_iterator
1888 I = SortedCategories.begin(),
1889 E = SortedCategories.end();
1891 CategorizedOptions[*
I] = std::vector<Option *>();
1896 for (
size_t I = 0,
E = Opts.size();
I !=
E; ++
I) {
1899 "Option has an unregistered category");
1900 CategorizedOptions[Opt->
Category].push_back(Opt);
1904 for (std::vector<OptionCategory *>::const_iterator
1905 Category = SortedCategories.begin(),
1906 E = SortedCategories.end();
1909 const auto &CategoryOptions = CategorizedOptions[*
Category];
1910 bool IsEmptyCategory = CategoryOptions.empty();
1911 if (!ShowHidden && IsEmptyCategory)
1916 outs() << (*Category)->getName() <<
":\n";
1919 if (!(*Category)->getDescription().empty())
1920 outs() << (*Category)->getDescription() <<
"\n\n";
1926 if (IsEmptyCategory) {
1927 outs() <<
" This option category has no options.\n";
1931 for (
const Option *Opt : CategoryOptions)
1939 class HelpPrinterWrapper {
1941 HelpPrinter &UncategorizedPrinter;
1942 CategorizedHelpPrinter &CategorizedPrinter;
1945 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
1946 CategorizedHelpPrinter &CategorizedPrinter)
1947 : UncategorizedPrinter(UncategorizedPrinter),
1948 CategorizedPrinter(CategorizedPrinter) {}
1951 void operator=(
bool Value);
1978 cl::desc(
"Display list of available options (-help-list-hidden for more)"),
1983 HLHOp(
"help-list-hidden",
cl::desc(
"Display list of all available options"),
1992 HOp(
"help",
cl::desc(
"Display available options (-help-hidden for more)"),
1997 HHOp(
"help-hidden",
cl::desc(
"Display all available options"),
2003 cl::desc(
"Print non-default options after command line parsing"),
2008 "print-all-options",
2012 void HelpPrinterWrapper::operator=(
bool Value) {
2019 if (
GlobalParser->RegisteredOptionCategories.size() > 1) {
2024 CategorizedPrinter =
true;
2026 UncategorizedPrinter =
true;
2032 void CommandLineParser::printOptionValues() {
2036 SmallVector<std::pair<const char *, Option *>, 128> Opts;
2037 sortOpts(ActiveSubCommand->OptionsMap, Opts,
true);
2040 size_t MaxArgLen = 0;
2041 for (
size_t i = 0, e = Opts.
size(); i != e; ++
i)
2042 MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
2044 for (
size_t i = 0, e = Opts.
size(); i != e; ++
i)
2053 class VersionPrinter {
2057 #ifdef PACKAGE_VENDOR
2058 OS << PACKAGE_VENDOR <<
" ";
2060 OS <<
"LLVM (http://llvm.org/):\n ";
2062 OS << PACKAGE_NAME <<
" version " << PACKAGE_VERSION;
2063 #ifdef LLVM_VERSION_INFO
2064 OS <<
" " << LLVM_VERSION_INFO;
2067 #ifndef __OPTIMIZE__
2068 OS <<
"DEBUG build";
2070 OS <<
"Optimized build";
2073 OS <<
" with assertions";
2076 if (CPU ==
"generic")
2080 <<
" Host CPU: " << CPU <<
'\n';
2082 void operator=(
bool OptionWasSpecified) {
2083 if (!OptionWasSpecified)
2087 (*OverrideVersionPrinter)();
2111 VersOp(
"version",
cl::desc(
"Display the version of this program"),
2124 if (!Hidden && !Categorized)
2126 else if (!Hidden && Categorized)
2128 else if (Hidden && !Categorized)
2160 if (
I.second->Category != &Category &&
2168 auto CategoriesBegin = Categories.
begin();
2169 auto CategoriesEnd = Categories.
end();
2171 if (
std::find(CategoriesBegin, CategoriesEnd,
I.second->Category) ==
2184 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(* TokenizerCallback)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs)
String tokenization function type.
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
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))
void setArgStr(StringRef S)
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
void PrintVersionMessage()
Utility function for printing version number.
bool is_relative(const Twine &path)
Is path relative?
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))
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
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...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with strcmp
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
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
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
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", bool IgnoreErrors=false)
ManagedStatic< SubCommand > AllSubCommands
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
StringRef filename(StringRef path)
Get filename.
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 const unsigned End
static bool EatsUnboundedNumberOfValues(const Option *O)
virtual StringRef getOption(unsigned N) const =0
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
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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)
StringRef parent_path(StringRef path)
Get parent path.
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.
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.
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=*TopLevelSubCommand)
Mark all options not part of this category as cl::ReallyHidden.
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)
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))
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
virtual void getExtraOptionNames(SmallVectorImpl< StringRef > &)
void removeArgument()
Unregisters this option from the CommandLine system.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
SmallPtrSet< SubCommand *, 4 > Subs
const char * getBufferEnd() const
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.
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)
Split - 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 GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
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.