30 #include "llvm/Config/config.h" 50 #define DEBUG_TYPE "commandline" 79 void GenericOptionValue::anchor() {}
82 void Option::anchor() {}
106 size_t Len = ArgName.
size();
108 return Len + Pad + ArgPrefix.
size() + ArgHelpPrefix.
size();
109 return Len + Pad + ArgPrefixLong.
size() + ArgHelpPrefix.
size();
114 for (
size_t I = 0;
I < Pad; ++
I) {
142 OS <<
argPrefix(Arg.ArgName, Arg.Pad) << Arg.ArgName;
146 class CommandLineParser {
150 std::string ProgramName;
154 std::vector<StringRef> MoreHelp;
167 CommandLineParser() : ActiveSubCommand(
nullptr) {
176 bool LongOptionsUseDoubleDash =
false);
181 if (!SC->
OptionsMap.insert(std::make_pair(Name, &Opt)).second) {
182 errs() << ProgramName <<
": CommandLine Error: Option '" << Name
183 <<
"' registered more than once!\n";
190 for (
auto *Sub : RegisteredSubCommands) {
193 addLiteralOption(Opt, Sub, Name);
199 if (Opt.
Subs.empty())
202 for (
auto SC : Opt.
Subs)
203 addLiteralOption(Opt, SC, Name);
208 bool HadErrors =
false;
217 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr 218 <<
"' registered more than once!\n";
230 O->
error(
"Cannot specify more than one option with cl::ConsumeAfter!");
246 for (
auto *Sub : RegisteredSubCommands) {
254 void addOption(
Option *O,
bool ProcessDefaultOption =
false) {
260 if (O->
Subs.empty()) {
263 for (
auto SC : O->
Subs)
276 for (
auto Name : OptionNames) {
278 if (
I != End &&
I->getValue() ==
O)
301 void removeOption(
Option *O) {
306 for (
auto SC : RegisteredSubCommands)
309 for (
auto SC : O->
Subs)
315 bool hasOptions(
const SubCommand &Sub)
const {
320 bool hasOptions()
const {
321 for (
const auto *S : RegisteredSubCommands) {
328 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
332 if (!Sub.
OptionsMap.insert(std::make_pair(NewName, O)).second) {
333 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr 334 <<
"' registered more than once!\n";
345 for (
auto SC : RegisteredSubCommands)
346 updateArgStr(O, NewName, SC);
348 for (
auto SC : O->
Subs)
349 updateArgStr(O, NewName, SC);
354 void printOptionValues();
361 "Duplicate option categories");
363 RegisteredOptionCategories.
insert(cat);
372 "Duplicate subcommands");
373 RegisteredSubCommands.
insert(sub);
384 addLiteralOption(*O, sub,
E.first());
390 RegisteredSubCommands.
erase(sub);
396 RegisteredSubCommands.
end());
400 ActiveSubCommand =
nullptr;
405 RegisteredOptionCategories.
clear();
408 RegisteredSubCommands.
clear();
415 DefaultOptions.
clear();
423 bool LongOptionsUseDoubleDash,
bool HaveDoubleDash) {
424 Option *Opt = LookupOption(Sub, Arg, Value);
425 if (Opt && LongOptionsUseDoubleDash && !HaveDoubleDash && !
isGrouping(Opt))
437 GlobalParser->addLiteralOption(O, Name);
441 GlobalParser->MoreHelp.push_back(Help);
445 GlobalParser->addOption(
this);
446 FullyInitialized =
true;
452 if (FullyInitialized)
453 GlobalParser->updateArgStr(
this, S);
454 assert((S.
empty() || S[0] !=
'-') &&
"Option can't start with '-");
456 if (ArgStr.size() == 1)
461 assert(!Categories.empty() &&
"Categories cannot be empty.");
467 else if (
find(Categories, &C) == Categories.end())
468 Categories.push_back(&C);
474 if (isDefaultOption())
481 void OptionCategory::registerCategory() {
482 GlobalParser->registerCategory(
this);
496 GlobalParser->registerSubCommand(
this);
500 GlobalParser->unregisterSubCommand(
this);
504 PositionalOpts.clear();
508 ConsumeAfterOpt =
nullptr;
511 SubCommand::operator
bool()
const {
512 return (GlobalParser->getActiveSubCommand() ==
this);
529 size_t EqualPos = Arg.
find(
'=');
552 Value = Arg.
substr(EqualPos + 1);
553 Arg = Arg.
substr(0, EqualPos);
560 for (
auto S : RegisteredSubCommands) {
563 if (S->getName().empty())
578 std::string &NearestString) {
584 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
590 unsigned BestDistance = 0;
592 ie = OptionsMap.
end();
602 for (
auto Name : OptionNames) {
604 Flag,
true, BestDistance);
605 if (!Best || Distance < BestDistance) {
607 BestDistance = Distance;
608 if (RHS.
empty() || !PermitValue)
609 NearestString = Name;
611 NearestString = (
Twine(Name) +
"=" + RHS).str();
623 bool MultiArg =
false) {
635 Val = Val.
substr(Pos + 1);
643 return Handler->
addOccurrence(pos, ArgName, Value, MultiArg);
651 const char *
const *argv,
int &i) {
662 return Handler->
error(
"requires a value!");
664 assert(argv &&
"null check");
669 if (NumAdditionalVals > 0)
670 return Handler->
error(
"multi-valued option specified" 671 " with ValueDisallowed modifier!");
674 return Handler->
error(
"does not allow a value! '" +
Twine(Value) +
682 if (NumAdditionalVals == 0)
686 bool MultiArg =
false;
695 while (NumAdditionalVals > 0) {
697 return Handler->
error(
"not enough values!");
698 assert(argv &&
"null check");
721 bool (*Pred)(
const Option *),
724 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
725 OMI = OptionsMap.
end();
730 while (OMI == OptionsMap.
end() && Name.
size() > 1) {
732 OMI = OptionsMap.
find(Name);
733 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
734 OMI = OptionsMap.
end();
737 if (OMI != OptionsMap.
end() && Pred(OMI->second)) {
738 Length = Name.
size();
764 Arg = Arg.
substr(0, Length);
765 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
775 if (MaybeValue[0] ==
'=') {
776 Value = MaybeValue.
substr(1);
785 ErrorParsing |= PGOpt->
error(
"may not occur within a group!");
814 return C ==
' ' || C ==
'\t' || C ==
'\r' || C ==
'\n';
821 static bool isQuote(
char C) {
return C ==
'\"' || C ==
'\''; }
827 for (
size_t I = 0,
E = Src.
size();
I !=
E; ++
I) {
832 if (MarkEOLs && Src[I] ==
'\n')
843 if (
I + 1 <
E && C ==
'\\') {
852 while (
I !=
E && Src[
I] != C) {
854 if (Src[
I] ==
'\\' &&
I + 1 !=
E)
902 size_t E = Src.
size();
903 int BackslashCount = 0;
908 }
while (I != E && Src[I] ==
'\\');
910 bool FollowedByDoubleQuote = (I != E && Src[
I] ==
'"');
911 if (FollowedByDoubleQuote) {
912 Token.
append(BackslashCount / 2,
'\\');
913 if (BackslashCount % 2 == 0)
918 Token.
append(BackslashCount,
'\\');
929 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
930 for (
size_t I = 0,
E = Src.
size();
I !=
E; ++
I) {
938 if (MarkEOLs && C ==
'\n')
958 if (State == UNQUOTED) {
965 if (MarkEOLs && C ==
'\n')
982 if (State == QUOTED) {
984 if (
I < (
E - 1) && Src[
I + 1] ==
'"') {
1012 for (
const char *Cur = Source.
begin(); Cur != Source.
end();) {
1021 while (Cur != Source.
end() && *Cur !=
'\n')
1026 const char *Start = Cur;
1027 for (
const char *End = Source.
end(); Cur != End; ++Cur) {
1029 if (Cur + 1 != End) {
1032 (*Cur ==
'\r' && (Cur + 1 != End) && Cur[1] ==
'\n')) {
1033 Line.
append(Start, Cur - 1);
1039 }
else if (*Cur ==
'\n')
1051 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
1065 StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
1068 ArrayRef<char> BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd());
1069 std::string UTF8Buf;
1073 "Could not convert UTF16 to UTF8");
1080 Str =
StringRef(BufRef.data() + 3, BufRef.size() - 3);
1083 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
1091 for (
auto &Arg : NewArgv) {
1093 if (!Arg || Arg[0] !=
'@')
1103 ResponseFile.
append(BasePath);
1105 Arg = Saver.
save(ResponseFile.
c_str()).data();
1116 bool AllExpanded =
true;
1117 struct ResponseFileRecord {
1132 for (
unsigned I = 0;
I != Argv.
size();) {
1133 while (
I == FileStack.
back().End) {
1139 const char *Arg = Argv[
I];
1141 if (Arg ==
nullptr) {
1146 if (Arg[0] !=
'@') {
1151 const char *FName = Arg + 1;
1159 CurrDir = *CurrentDir;
1161 FName = CurrDir.
c_str();
1163 auto IsEquivalent = [FName, &
FS](
const ResponseFileRecord &RFile) {
1176 return LHS->equivalent(*RHS);
1183 AllExpanded =
false;
1193 RelativeNames, FS)) {
1198 AllExpanded =
false;
1203 for (ResponseFileRecord &
Record : FileStack) {
1209 FileStack.push_back({FName,
I + ExpandedArgv.
size()});
1229 CfgFile = AbsPath.
str();
1249 const char *Overview) {
1251 assert(progName &&
"Program name not specified");
1252 assert(envVar &&
"Environment variable name missing");
1269 int newArgc =
static_cast<int>(newArgv.
size());
1276 bool LongOptionsUseDoubleDash) {
1290 for (
int I = 1;
I < argc; ++
I)
1292 int NewArgc =
static_cast<int>(NewArgv.
size());
1295 return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
1296 Errs, LongOptionsUseDoubleDash);
1302 for (
auto SC : RegisteredSubCommands) {
1303 for (
auto &
O :
SC->OptionsMap)
1309 const char *
const *argv,
1312 bool LongOptionsUseDoubleDash) {
1313 assert(hasOptions() &&
"No options specified!");
1324 argc =
static_cast<int>(newArgv.
size());
1329 ProgramOverview = Overview;
1330 bool IgnoreErrors = Errs;
1333 bool ErrorParsing =
false;
1336 unsigned NumPositionalRequired = 0;
1339 bool HasUnlimitedPositionals =
false;
1343 if (argc >= 2 && argv[FirstArg][0] !=
'-') {
1346 ChosenSubCommand = LookupSubCommand(
StringRef(argv[FirstArg]));
1350 GlobalParser->ActiveSubCommand = ChosenSubCommand;
1352 assert(ChosenSubCommand);
1355 auto &SinkOpts = ChosenSubCommand->
SinkOpts;
1356 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1358 for (
auto O: DefaultOptions) {
1362 if (ConsumeAfterOpt) {
1363 assert(PositionalOpts.size() > 0 &&
1364 "Cannot specify cl::ConsumeAfter without a positional argument!");
1366 if (!PositionalOpts.empty()) {
1369 bool UnboundedFound =
false;
1370 for (
size_t i = 0,
e = PositionalOpts.size(); i !=
e; ++i) {
1371 Option *Opt = PositionalOpts[i];
1373 ++NumPositionalRequired;
1374 else if (ConsumeAfterOpt) {
1377 if (PositionalOpts.size() > 1) {
1379 Opt->
error(
"error - this positional option will never be matched, " 1380 "because it does not Require a value, and a " 1381 "cl::ConsumeAfter option is active!");
1382 ErrorParsing =
true;
1384 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1390 Opt->
error(
"error - option can never match, because " 1391 "another positional argument will match an " 1392 "unbounded number of values, and this option" 1393 " does not require a value!");
1394 *Errs << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr 1395 <<
"' is all messed up!\n";
1396 *Errs << PositionalOpts.size();
1397 ErrorParsing =
true;
1401 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1412 Option *ActivePositionalArg =
nullptr;
1415 bool DashDashFound =
false;
1416 for (
int i = FirstArg; i < argc; ++i) {
1417 Option *Handler =
nullptr;
1418 Option *NearestHandler =
nullptr;
1419 std::string NearestHandlerString;
1422 bool HaveDoubleDash =
false;
1428 if (argv[i][0] !=
'-' || argv[i][1] == 0 || DashDashFound) {
1430 if (ActivePositionalArg) {
1435 if (!PositionalOpts.empty()) {
1441 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
1442 for (++i; i < argc; ++i)
1450 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
1452 DashDashFound =
true;
1454 }
else if (ActivePositionalArg &&
1461 if (!ArgName.
empty() && ArgName[0] ==
'-') {
1462 HaveDoubleDash =
true;
1463 ArgName = ArgName.
substr(1);
1466 Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
1467 LongOptionsUseDoubleDash, HaveDoubleDash);
1475 if (!ArgName.
empty() && ArgName[0] ==
'-') {
1476 HaveDoubleDash =
true;
1477 ArgName = ArgName.
substr(1);
1480 Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
1481 LongOptionsUseDoubleDash, HaveDoubleDash);
1484 if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
1490 if (!Handler && SinkOpts.empty())
1496 if (SinkOpts.empty()) {
1497 *Errs << ProgramName <<
": Unknown command line argument '" << argv[i]
1498 <<
"'. Try: '" << argv[0] <<
" --help'\n";
1500 if (NearestHandler) {
1502 *Errs << ProgramName <<
": Did you mean '" 1503 << PrintArg(NearestHandlerString, 0) <<
"'?\n";
1506 ErrorParsing =
true;
1511 (*I)->addOccurrence(i,
"",
StringRef(argv[i]));
1520 Handler->
error(
"This argument does not take a value.\n" 1521 "\tInstead, it consumes any positional arguments until " 1522 "the next recognized option.", *Errs);
1523 ErrorParsing =
true;
1525 ActivePositionalArg = Handler;
1528 ErrorParsing |=
ProvideOption(Handler, ArgName, Value, argc, argv, i);
1532 if (NumPositionalRequired > PositionalVals.
size()) {
1533 *Errs << ProgramName
1534 <<
": Not enough positional command line arguments specified!\n" 1535 <<
"Must specify at least " << NumPositionalRequired
1536 <<
" positional argument" << (NumPositionalRequired > 1 ?
"s" :
"")
1537 <<
": See: " << argv[0] <<
" --help\n";
1539 ErrorParsing =
true;
1540 }
else if (!HasUnlimitedPositionals &&
1541 PositionalVals.
size() > PositionalOpts.size()) {
1542 *Errs << ProgramName <<
": Too many positional arguments specified!\n" 1543 <<
"Can specify at most " << PositionalOpts.size()
1544 <<
" positional arguments: See: " << argv[0] <<
" --help\n";
1545 ErrorParsing =
true;
1547 }
else if (!ConsumeAfterOpt) {
1549 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1550 for (
size_t i = 0,
e = PositionalOpts.size(); i !=
e; ++i) {
1553 PositionalVals[ValNo].
second);
1555 --NumPositionalRequired;
1562 bool Done = PositionalOpts[i]->getNumOccurrencesFlag() ==
cl::Required;
1563 while (NumVals - ValNo > NumPositionalRequired && !Done) {
1564 switch (PositionalOpts[i]->getNumOccurrencesFlag()) {
1571 PositionalVals[ValNo].
first,
1572 PositionalVals[ValNo].
second);
1577 "positional argument processing!");
1582 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1584 for (
size_t j = 1,
e = PositionalOpts.size(); j !=
e; ++j)
1587 PositionalVals[ValNo].
first,
1588 PositionalVals[ValNo].
second);
1597 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1599 PositionalVals[ValNo].
first,
1600 PositionalVals[ValNo].
second);
1606 for (; ValNo != PositionalVals.
size(); ++ValNo)
1609 PositionalVals[ValNo].
second);
1613 for (
const auto &Opt : OptionsMap) {
1614 switch (Opt.second->getNumOccurrencesFlag()) {
1617 if (Opt.second->getNumOccurrences() == 0) {
1618 Opt.second->error(
"must be specified at least once!");
1619 ErrorParsing =
true;
1631 for (
int i = 0; i < argc; ++i)
dbgs() << argv[i] <<
' ';
1652 if (!ArgName.
data())
1654 if (ArgName.
empty())
1657 Errs << GlobalParser->ProgramName <<
": for the " << PrintArg(ArgName, 0);
1659 Errs <<
" option: " << Message <<
"\n";
1668 switch (getNumOccurrencesFlag()) {
1670 if (NumOccurrences > 1)
1671 return error(
"may only occur zero or one times!", ArgName);
1674 if (NumOccurrences > 1)
1675 return error(
"must occur exactly one time!", ArgName);
1683 return handleOccurrence(pos, ArgName, Value);
1700 size_t alias::getOptionWidth()
const {
1705 size_t FirstLineIndentedBy) {
1706 assert(Indent >= FirstLineIndentedBy);
1707 std::pair<StringRef, StringRef> Split = HelpStr.
split(
'\n');
1709 << ArgHelpPrefix << Split.first <<
"\n";
1710 while (!Split.second.empty()) {
1711 Split = Split.second.
split(
'\n');
1712 outs().
indent(Indent) << Split.first <<
"\n";
1717 void alias::printOptionInfo(
size_t GlobalWidth)
const {
1718 outs() << PrintArg(ArgStr);
1732 auto ValName = getValueName();
1733 if (!ValName.empty()) {
1734 size_t FormattingLen = 3;
1747 size_t GlobalWidth)
const {
1750 auto ValName = getValueName();
1751 if (!ValName.empty()) {
1763 size_t GlobalWidth)
const {
1772 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1778 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1782 return O.
error(
"'" + Arg +
1783 "' is invalid value for boolean argument! Try 0 or 1");
1790 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1795 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1800 return O.
error(
"'" + Arg +
1801 "' is invalid value for boolean argument! Try 0 or 1");
1809 return O.
error(
"'" + Arg +
"' value invalid for integer argument!");
1818 return O.
error(
"'" + Arg +
"' value invalid for long argument!");
1827 return O.
error(
"'" + Arg +
"' value invalid for llong argument!");
1837 return O.
error(
"'" + Arg +
"' value invalid for uint argument!");
1844 unsigned long &Value) {
1847 return O.
error(
"'" + Arg +
"' value invalid for ulong argument!");
1855 unsigned long long &Value) {
1858 return O.
error(
"'" + Arg +
"' value invalid for ullong argument!");
1867 return O.
error(
"'" + Arg +
"' value invalid for floating point argument!");
1891 unsigned e = getNumOptions();
1893 for (
unsigned i = 0; i !=
e; ++i) {
1894 if (getOption(i) == Name)
1908 !Description.
empty();
1916 for (
unsigned i = 0,
e = getNumOptions(); i !=
e; ++i) {
1921 Size =
std::max(Size, NameSize + OptionPrefixesSize);
1925 size_t BaseSize = 0;
1926 for (
unsigned i = 0,
e = getNumOptions(); i !=
e; ++i)
1927 BaseSize =
std::max(BaseSize, getOption(i).
size() + 8);
1936 size_t GlobalWidth)
const {
1941 for (
unsigned i = 0,
e = getNumOptions(); i !=
e; ++i) {
1942 if (getOption(i).empty()) {
1955 for (
unsigned i = 0,
e = getNumOptions(); i !=
e; ++i) {
1962 outs() << OptionPrefix << OptionName;
1963 if (OptionName.empty()) {
1966 NumSpaces -= EmptyOption.
size();
1968 if (!Description.
empty())
1969 outs().
indent(NumSpaces) << ArgHelpPrefix <<
" " << Description;
1975 for (
unsigned i = 0,
e = getNumOptions(); i !=
e; ++i) {
1977 outs() <<
" " << PrintArg(Option);
1994 unsigned NumOpts = getNumOptions();
1995 for (
unsigned i = 0; i != NumOpts; ++i) {
1996 if (Value.
compare(getOptionValue(i)))
1999 outs() <<
"= " << getOption(i);
2000 size_t L = getOption(i).size();
2001 size_t NumSpaces = MaxOptWidth > L ? MaxOptWidth - L : 0;
2003 for (
unsigned j = 0; j != NumOpts; ++j) {
2004 if (Default.
compare(getOptionValue(j)))
2006 outs() << getOption(j);
2012 outs() <<
"= *unknown option value*\n";
2017 #define PRINT_OPT_DIFF(T) \ 2018 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \ 2019 size_t GlobalWidth) const { \ 2020 printOptionName(O, GlobalWidth); \ 2023 raw_string_ostream SS(Str); \ 2026 outs() << "= " << Str; \ 2027 size_t NumSpaces = \ 2028 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \ 2029 outs().indent(NumSpaces) << " (default: "; \ 2031 outs() << D.getValue(); \ 2033 outs() << "*no default*"; \ 2051 size_t GlobalWidth)
const {
2052 printOptionName(O, GlobalWidth);
2053 outs() <<
"= " << V;
2054 size_t NumSpaces = MaxOptWidth > V.
size() ? MaxOptWidth - V.
size() : 0;
2059 outs() <<
"*no default*";
2065 size_t GlobalWidth)
const {
2066 printOptionName(O, GlobalWidth);
2067 outs() <<
"= *cannot print option value*\n";
2075 const std::pair<const char *, Option *> *RHS) {
2076 return strcmp(LHS->first, RHS->first);
2080 const std::pair<const char *, SubCommand *> *RHS) {
2081 return strcmp(LHS->first, RHS->first);
2097 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
2101 if (!OptionSet.
insert(
I->second).second)
2105 std::pair<const char *, Option *>(
I->getKey().data(),
I->second));
2115 for (
auto *S : SubMap) {
2116 if (S->getName().empty())
2118 Subs.push_back(std::make_pair(S->getName().data(), S));
2127 const bool ShowHidden;
2129 StrOptionPairVector;
2131 StrSubCommandPairVector;
2133 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
2134 for (
size_t i = 0,
e = Opts.size(); i !=
e; ++i)
2135 Opts[i].
second->printOptionInfo(MaxArgLen);
2138 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
2139 for (
const auto &S : Subs) {
2140 outs() <<
" " << S.first;
2141 if (!S.second->getDescription().empty()) {
2143 outs() <<
" - " << S.second->getDescription();
2150 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
2151 virtual ~HelpPrinter() {}
2154 void operator=(
bool Value) {
2164 SubCommand *Sub = GlobalParser->getActiveSubCommand();
2169 StrOptionPairVector Opts;
2170 sortOpts(OptionsMap, Opts, ShowHidden);
2172 StrSubCommandPairVector Subs;
2175 if (!GlobalParser->ProgramOverview.empty())
2176 outs() <<
"OVERVIEW: " << GlobalParser->ProgramOverview <<
"\n";
2179 outs() <<
"USAGE: " << GlobalParser->ProgramName;
2180 if (Subs.size() > 2)
2181 outs() <<
" [subcommand]";
2182 outs() <<
" [options]";
2188 outs() <<
"USAGE: " << GlobalParser->ProgramName <<
" " << Sub->
getName()
2192 for (
auto Opt : PositionalOpts) {
2193 if (Opt->hasArgStr())
2194 outs() <<
" --" << Opt->ArgStr;
2195 outs() <<
" " << Opt->HelpStr;
2199 if (ConsumeAfterOpt)
2200 outs() <<
" " << ConsumeAfterOpt->HelpStr;
2204 size_t MaxSubLen = 0;
2205 for (
size_t i = 0,
e = Subs.size(); i !=
e; ++i)
2209 outs() <<
"SUBCOMMANDS:\n\n";
2210 printSubCommands(Subs, MaxSubLen);
2212 outs() <<
" Type \"" << GlobalParser->ProgramName
2213 <<
" <subcommand> --help\" to get more help on a specific " 2220 size_t MaxArgLen = 0;
2221 for (
size_t i = 0,
e = Opts.size(); i !=
e; ++i)
2222 MaxArgLen =
std::max(MaxArgLen, Opts[i].
second->getOptionWidth());
2224 outs() <<
"OPTIONS:\n";
2225 printOptions(Opts, MaxArgLen);
2228 for (
auto I : GlobalParser->MoreHelp)
2230 GlobalParser->MoreHelp.clear();
2234 class CategorizedHelpPrinter :
public HelpPrinter {
2236 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
2244 return (*A)->getName().compare((*B)->getName());
2248 using HelpPrinter::operator=;
2251 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
2252 std::vector<OptionCategory *> SortedCategories;
2253 std::map<OptionCategory *, std::vector<Option *>> CategorizedOptions;
2257 for (
auto I = GlobalParser->RegisteredOptionCategories.begin(),
2258 E = GlobalParser->RegisteredOptionCategories.end();
2260 SortedCategories.push_back(*
I);
2264 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
2266 OptionCategoryCompare);
2269 for (std::vector<OptionCategory *>::const_iterator
2270 I = SortedCategories.begin(),
2271 E = SortedCategories.end();
2273 CategorizedOptions[*
I] = std::vector<Option *>();
2278 for (
size_t I = 0,
E = Opts.size();
I !=
E; ++
I) {
2281 assert(CategorizedOptions.count(Cat) > 0 &&
2282 "Option has an unregistered category");
2283 CategorizedOptions[Cat].push_back(Opt);
2288 for (std::vector<OptionCategory *>::const_iterator
2289 Category = SortedCategories.begin(),
2290 E = SortedCategories.end();
2291 Category !=
E; ++Category) {
2293 const auto &CategoryOptions = CategorizedOptions[*Category];
2294 bool IsEmptyCategory = CategoryOptions.empty();
2295 if (!ShowHidden && IsEmptyCategory)
2300 outs() << (*Category)->getName() <<
":\n";
2303 if (!(*Category)->getDescription().empty())
2304 outs() << (*Category)->getDescription() <<
"\n\n";
2310 if (IsEmptyCategory) {
2311 outs() <<
" This option category has no options.\n";
2315 for (
const Option *Opt : CategoryOptions)
2316 Opt->printOptionInfo(MaxArgLen);
2323 class HelpPrinterWrapper {
2325 HelpPrinter &UncategorizedPrinter;
2326 CategorizedHelpPrinter &CategorizedPrinter;
2329 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
2330 CategorizedHelpPrinter &CategorizedPrinter)
2331 : UncategorizedPrinter(UncategorizedPrinter),
2332 CategorizedPrinter(CategorizedPrinter) {}
2335 void operator=(
bool Value);
2350 CategorizedNormalPrinter);
2352 CategorizedHiddenPrinter);
2362 cl::desc(
"Display list of available options (--help-list-hidden for more)"),
2367 HLHOp(
"help-list-hidden",
cl::desc(
"Display list of all available options"),
2376 HOp(
"help",
cl::desc(
"Display available options (--help-hidden for more)"),
2384 HHOp(
"help-hidden",
cl::desc(
"Display all available options"),
2390 cl::desc(
"Print non-default options after command line parsing"),
2395 "print-all-options",
2399 void HelpPrinterWrapper::operator=(
bool Value) {
2406 if (GlobalParser->RegisteredOptionCategories.size() > 1) {
2411 CategorizedPrinter =
true;
2413 UncategorizedPrinter =
true;
2419 void CommandLineParser::printOptionValues() {
2420 if (!PrintOptions && !PrintAllOptions)
2424 sortOpts(ActiveSubCommand->OptionsMap, Opts,
true);
2427 size_t MaxArgLen = 0;
2428 for (
size_t i = 0,
e = Opts.
size(); i !=
e; ++i)
2429 MaxArgLen =
std::max(MaxArgLen, Opts[i].
second->getOptionWidth());
2431 for (
size_t i = 0,
e = Opts.
size(); i !=
e; ++i)
2432 Opts[i].
second->printOptionValue(MaxArgLen, PrintAllOptions);
2439 #if defined(__GNUC__) 2442 # if defined(__OPTIMIZE__) 2443 # define LLVM_IS_DEBUG_BUILD 0 2445 # define LLVM_IS_DEBUG_BUILD 1 2447 #elif defined(_MSC_VER) 2451 # if defined(_DEBUG) 2452 # define LLVM_IS_DEBUG_BUILD 1 2454 # define LLVM_IS_DEBUG_BUILD 0 2458 # define LLVM_IS_DEBUG_BUILD 0 2462 class VersionPrinter {
2466 #ifdef PACKAGE_VENDOR 2467 OS << PACKAGE_VENDOR <<
" ";
2469 OS <<
"LLVM (http://llvm.org/):\n ";
2471 OS << PACKAGE_NAME <<
" version " << PACKAGE_VERSION;
2472 #ifdef LLVM_VERSION_INFO 2473 OS <<
" " << LLVM_VERSION_INFO;
2476 #if LLVM_IS_DEBUG_BUILD 2477 OS <<
"DEBUG build";
2479 OS <<
"Optimized build";
2482 OS <<
" with assertions";
2484 #if LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO 2486 if (CPU ==
"generic")
2490 <<
" Host CPU: " << CPU;
2494 void operator=(
bool OptionWasSpecified) {
2495 if (!OptionWasSpecified)
2498 if (OverrideVersionPrinter !=
nullptr) {
2506 if (ExtraVersionPrinters !=
nullptr) {
2508 for (
auto I : *ExtraVersionPrinters)
2521 VersOp(
"version",
cl::desc(
"Display the version of this program"),
2527 if (!Hidden && !Categorized)
2528 UncategorizedNormalPrinter.printHelp();
2529 else if (!Hidden && Categorized)
2530 CategorizedNormalPrinter.printHelp();
2531 else if (Hidden && !Categorized)
2532 UncategorizedHiddenPrinter.printHelp();
2534 CategorizedHiddenPrinter.printHelp();
2543 if (!ExtraVersionPrinters)
2544 ExtraVersionPrinters =
new std::vector<VersionPrinterTy>;
2546 ExtraVersionPrinters->push_back(func);
2550 auto &Subs = GlobalParser->RegisteredSubCommands;
2558 return GlobalParser->getRegisteredSubcommands();
2563 for (
auto &Cat :
I.second->Categories) {
2564 if (Cat != &Category &&
2565 Cat != &GenericCategory)
2574 for (
auto &Cat :
I.second->Categories) {
2583 GlobalParser->ResetAllOptionOccurrences();
2587 const char *Overview) {
bool hasUTF16ByteOrderMark(ArrayRef< char > SrcBytes)
Returns true if a blob of text starts with a UTF-16 big or little endian byte order mark...
bool isPositional() const
static cl::alias HOpA("h", cl::desc("Alias for --help"), cl::aliasopt(HOp), cl::DefaultOption)
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)
enum ValueExpected getValueExpectedFlag() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
OptionCategory GeneralCategory
static void sortOpts(StringMap< Option *> &OptMap, SmallVectorImpl< std::pair< const char *, Option *>> &Opts, bool ShowHidden)
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
static bool isPrefixedOrGrouping(const Option *O)
static bool parseDouble(Option &O, StringRef Arg, double &Value)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
static int OptNameCompare(const std::pair< const char *, Option *> *LHS, const std::pair< const char *, Option *> *RHS)
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)
bool isConsumeAfter() const
void setArgStr(StringRef S)
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static StringRef ArgPrefix
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))
void push_back(const T &Elt)
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...
size_t getOptionWidth(const Option &O) const
iterator find(StringRef Key)
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
This is a convenience method that opens a file, gets its content and then closes the file...
enum NumOccurrencesFlag getNumOccurrencesFlag() const
void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char *> &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
auto count_if(R &&Range, UnaryPredicate P) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
void unregisterSubCommand()
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 ParseEnvironmentOptions(const char *progName, const char *envvar, const char *Overview="")
ParseEnvironmentOptions - An alternative entry point to the CommandLine library, which allows you to ...
static StringRef ArgPrefixLong
SmallVector< Option *, 4 > SinkOpts
static HelpPrinter UncategorizedHiddenPrinter(true)
LLVM_NODISCARD unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that they are constant initial...
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))
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
void printOptionInfo(const Option &O, size_t GlobalWidth) const
StringMap< Option * > & getRegisteredOptions(SubCommand &Sub= *TopLevelSubCommand)
Use this to get a StringMap to all registered named options (e.g.
bool readConfigFile(StringRef CfgFileName, StringSaver &Saver, SmallVectorImpl< const char *> &Argv)
Reads command line options from the given configuration file.
static StringRef getValueStr(const Option &O, StringRef DefaultMsg)
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
void addCategory(OptionCategory &C)
void LLVMParseCommandLineOptions(int argc, const char *const *argv, const char *Overview)
This function parses the given arguments using the LLVM command line parser.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
static const size_t MaxOptWidth
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char *> &Argv, bool MarkEOLs=false, bool RelativeNames=false, llvm::vfs::FileSystem &FS= *llvm::vfs::getRealFileSystem(), llvm::Optional< llvm::StringRef > CurrentDir=llvm::None)
Expand response files on a command line recursively using the given StringSaver and tokenization stra...
static VersionPrinter VersionPrinterInstance
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
static cl::OptionCategory GenericCategory("Generic Options")
LLVM_NODISCARD 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.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
virtual bool compare(const GenericOptionValue &V) 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...
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
StringRef str() const
Explicit conversion to StringRef.
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))
std::function< void(raw_ostream &)> VersionPrinterTy
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
static ManagedStatic< CommandLineParser > GlobalParser
void printOptionNoValue(const Option &O, size_t GlobalWidth) 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 size_t size() const
size - Get the string size.
static std::string getDescription(const CallGraphSCC &SCC)
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
StringRef getName() const
static SmallString< 8 > argPrefix(StringRef ArgName, size_t Pad=DefaultPad)
ManagedStatic< SubCommand > AllSubCommands
static std::vector< VersionPrinterTy > * ExtraVersionPrinters
static bool hasUTF8ByteOrderMark(ArrayRef< char > S)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
static llvm::Error ExpandResponseFile(StringRef FName, StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char *> &NewArgv, bool MarkEOLs, bool RelativeNames, llvm::vfs::FileSystem &FS)
StringMap< Option * > OptionsMap
void append(in_iter S, in_iter E)
Append from an iterator pair.
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub= *TopLevelSubCommand)
Mark all options not part of this category as cl::ReallyHidden.
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
const DataType & getValue() const
static int SubNameCompare(const std::pair< const char *, SubCommand *> *LHS, const std::pair< const char *, SubCommand *> *RHS)
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.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Allocate memory in an ever growing pool, as if by bump-pointer.
Instrumentation for Order File
virtual llvm::ErrorOr< Status > status(const Twine &Path)=0
Get the status of the entry at Path, if one exists.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
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))
unsigned getNumAdditionalVals() 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::error_code getError() const
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()
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...
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
void setHiddenFlag(enum OptionHidden Val)
static void sortSubCommands(const SmallPtrSetImpl< SubCommand *> &SubMap, SmallVectorImpl< std::pair< const char *, SubCommand *>> &Subs)
static StringRef ArgHelpPrefix
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
static bool EatsUnboundedNumberOfValues(const Option *O)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// SetVersionPrinter - Over...
StringRef getDescription() const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
bool isInAllSubCommands() const
static StringRef OptionPrefix
static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling ...
iterator erase(const_iterator CI)
static size_t OptionPrefixesSize
void consumeError(Error Err)
Consume a Error without doing anything.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
static size_t argPlusPrefixesSize(StringRef ArgName, size_t Pad=DefaultPad)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
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.
static void Help(ArrayRef< SubtargetSubTypeKV > CPUTable, ArrayRef< SubtargetFeatureKV > FeatTable)
Display help for feature and mcpu choices.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static ErrorSuccess success()
Create a success value.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Align max(MaybeAlign Lhs, Align Rhs)
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
bool isDefaultOption() const
static HelpPrinterWrapper WrappedNormalPrinter(UncategorizedNormalPrinter, CategorizedNormalPrinter)
static bool isWhitespaceOrNull(char C)
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 a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
The virtual file system interface.
CHAIN = SC CHAIN, Imm128 - System call.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static VersionPrinterTy OverrideVersionPrinter
static bool shouldPrintOption(StringRef Name, StringRef Description, const Option &O)
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...
bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
void printOptionDiff(const Option &O, const AnyOptionValue &V, const AnyOptionValue &Default, size_t GlobalWidth) 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.
A range adaptor for a pair of iterators.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static bool isWhitespace(char C)
StringRef save(const char *S)
SmallPtrSet< SubCommand *, 1 > Subs
enum FormattingFlags getFormattingFlag() const
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)
iterator insert(iterator I, T &&Elt)
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
static StringRef EmptyOption
Defines the virtual file system interface vfs::FileSystem.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer...
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.
LLVM_NODISCARD bool empty() const
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.
static Option * getOptionPred(StringRef Name, size_t &Length, bool(*Pred)(const Option *), const StringMap< Option *> &OptionsMap)
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
bool error(const Twine &Message, StringRef ArgName=StringRef(), raw_ostream &Errs=llvm::errs())
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void printOptionName(const Option &O, size_t GlobalWidth) 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.
void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// AddExtraVersionPrinter -...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Lightweight error class with error context and mandatory checking.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
ManagedStatic< SubCommand > TopLevelSubCommand
This class implements an extremely fast bulk output stream that can only output to a stream...
static CategorizedHelpPrinter CategorizedHiddenPrinter(true)
unsigned getMiscFlags() const
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
virtual size_t getOptionWidth(const Option &O) const
unsigned findOption(StringRef Name)
SmallVector< OptionCategory *, 1 > Categories
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)
static const size_t DefaultPad
LocationClass< Ty > location(Ty &L)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
StringRef getName() const
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.