Go to the documentation of this file.
33 #include "llvm/Config/config.h"
52 #define DEBUG_TYPE "commandline"
81 void GenericOptionValue::anchor() {}
84 void Option::anchor() {}
108 size_t Len = ArgName.
size();
116 for (
size_t I = 0;
I < Pad; ++
I) {
148 class CommandLineParser {
152 std::string ProgramName;
156 std::vector<StringRef> MoreHelp;
169 CommandLineParser() : ActiveSubCommand(nullptr) {
178 bool LongOptionsUseDoubleDash =
false);
183 if (!
SC->OptionsMap.insert(std::make_pair(
Name, &Opt)).second) {
184 errs() << ProgramName <<
": CommandLine Error: Option '" <<
Name
185 <<
"' registered more than once!\n";
192 for (
auto *Sub : RegisteredSubCommands) {
195 addLiteralOption(Opt, Sub,
Name);
201 if (Opt.
Subs.empty())
205 addLiteralOption(Opt,
SC,
Name);
210 bool HadErrors =
false;
211 if (
O->hasArgStr()) {
213 if (
O->isDefaultOption() &&
214 SC->OptionsMap.find(
O->ArgStr) !=
SC->OptionsMap.end())
218 if (!
SC->OptionsMap.insert(std::make_pair(
O->ArgStr,
O)).second) {
219 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
220 <<
"' registered more than once!\n";
227 SC->PositionalOpts.push_back(
O);
229 SC->SinkOpts.push_back(
O);
231 if (
SC->ConsumeAfterOpt) {
232 O->error(
"Cannot specify more than one option with cl::ConsumeAfter!");
235 SC->ConsumeAfterOpt =
O;
248 for (
auto *Sub : RegisteredSubCommands) {
256 void addOption(
Option *
O,
bool ProcessDefaultOption =
false) {
257 if (!ProcessDefaultOption &&
O->isDefaultOption()) {
258 DefaultOptions.push_back(
O);
262 if (
O->Subs.empty()) {
265 for (
auto *
SC :
O->Subs)
272 O->getExtraOptionNames(OptionNames);
274 OptionNames.push_back(
O->ArgStr);
278 for (
auto Name : OptionNames) {
280 if (
I != End &&
I->getValue() ==
O)
307 if (
O->isInAllSubCommands()) {
308 for (
auto *
SC : RegisteredSubCommands)
311 for (
auto *
SC :
O->Subs)
317 bool hasOptions(
const SubCommand &Sub)
const {
322 bool hasOptions()
const {
323 for (
const auto *
S : RegisteredSubCommands) {
330 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
334 if (!Sub.
OptionsMap.insert(std::make_pair(NewName,
O)).second) {
335 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
336 <<
"' registered more than once!\n";
346 if (
O->isInAllSubCommands()) {
347 for (
auto *
SC : RegisteredSubCommands)
348 updateArgStr(
O, NewName,
SC);
350 for (
auto *
SC :
O->Subs)
351 updateArgStr(
O, NewName,
SC);
356 void printOptionValues();
363 "Duplicate option categories");
371 return (!
sub->getName().empty()) &&
374 "Duplicate subcommands");
375 RegisteredSubCommands.insert(
sub);
382 if ((
O->isPositional() ||
O->isSink() ||
O->isConsumeAfter()) ||
386 addLiteralOption(*
O,
sub,
E.first());
392 RegisteredSubCommands.erase(
sub);
397 return make_range(RegisteredSubCommands.begin(),
398 RegisteredSubCommands.end());
402 ActiveSubCommand =
nullptr;
407 RegisteredOptionCategories.
clear();
410 RegisteredSubCommands.clear();
417 DefaultOptions.
clear();
425 bool LongOptionsUseDoubleDash,
bool HaveDoubleDash) {
427 if (Opt && LongOptionsUseDoubleDash && !HaveDoubleDash && !
isGrouping(Opt))
448 FullyInitialized =
true;
454 if (FullyInitialized)
456 assert((
S.empty() ||
S[0] !=
'-') &&
"Option can't start with '-");
480 void OptionCategory::registerCategory() {
510 SubCommand::operator bool()
const {
528 size_t EqualPos =
Arg.find(
'=');
548 Arg =
Arg.substr(0, EqualPos);
555 for (
auto *
S : RegisteredSubCommands) {
558 if (
S->getName().empty())
573 std::string &NearestString) {
579 std::pair<StringRef, StringRef> SplitArg =
Arg.split(
'=');
585 unsigned BestDistance = 0;
587 ie = OptionsMap.
end();
595 O->getExtraOptionNames(OptionNames);
597 OptionNames.push_back(
O->ArgStr);
601 for (
const auto &
Name : OptionNames) {
603 Flag,
true, BestDistance);
604 if (!Best || Distance < BestDistance) {
606 BestDistance = Distance;
607 if (
RHS.empty() || !PermitValue)
608 NearestString = std::string(
Name);
622 bool MultiArg =
false) {
634 Val = Val.
substr(Pos + 1);
650 const char *
const *argv,
int &
i) {
661 return Handler->
error(
"requires a value!");
663 assert(argv &&
"null check");
668 if (NumAdditionalVals > 0)
669 return Handler->
error(
"multi-valued option specified"
670 " with ValueDisallowed modifier!");
681 if (NumAdditionalVals == 0)
685 bool MultiArg =
false;
694 while (NumAdditionalVals > 0) {
696 return Handler->
error(
"not enough values!");
697 assert(argv &&
"null check");
720 bool (*Pred)(
const Option *),
723 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
724 OMI = OptionsMap.
end();
729 while (OMI == OptionsMap.
end() &&
Name.size() > 1) {
732 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
733 OMI = OptionsMap.
end();
736 if (OMI != OptionsMap.
end() && Pred(OMI->second)) {
737 Length =
Name.size();
763 Arg =
Arg.substr(0, Length);
774 if (MaybeValue[0] ==
'=') {
784 ErrorParsing |= PGOpt->
error(
"may not occur within a group!");
813 return C ==
' ' ||
C ==
'\t' ||
C ==
'\r' ||
C ==
'\n';
820 static bool isQuote(
char C) {
return C ==
'\"' ||
C ==
'\''; }
826 for (
size_t I = 0,
E = Src.size();
I !=
E; ++
I) {
831 if (MarkEOLs && Src[
I] ==
'\n')
832 NewArgv.push_back(
nullptr);
842 if (
I + 1 <
E &&
C ==
'\\') {
844 Token.push_back(Src[
I]);
851 while (
I !=
E && Src[
I] !=
C) {
853 if (Src[
I] ==
'\\' &&
I + 1 !=
E)
855 Token.push_back(Src[
I]);
868 if (MarkEOLs &&
C ==
'\n')
869 NewArgv.push_back(
nullptr);
901 size_t E = Src.size();
902 int BackslashCount = 0;
907 }
while (
I !=
E && Src[
I] ==
'\\');
909 bool FollowedByDoubleQuote = (
I !=
E && Src[
I] ==
'"');
910 if (FollowedByDoubleQuote) {
911 Token.
append(BackslashCount / 2,
'\\');
912 if (BackslashCount % 2 == 0)
914 Token.push_back(
'"');
917 Token.
append(BackslashCount,
'\\');
935 bool AlwaysCopy,
function_ref<
void()> MarkEOL,
bool InitialCommandName) {
944 bool CommandName = InitialCommandName;
947 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
949 for (
size_t I = 0,
E = Src.size();
I <
E; ++
I) {
952 assert(Token.empty() &&
"token should be empty in initial state");
974 AddToken(AlwaysCopy ? Saver.
save(NormalChars) : NormalChars);
975 if (
I <
E && Src[
I] ==
'\n') {
977 CommandName = InitialCommandName;
981 }
else if (Src[
I] ==
'\"') {
982 Token += NormalChars;
984 }
else if (Src[
I] ==
'\\') {
985 assert(!CommandName &&
"or else we'd have treated it as a normal char");
986 Token += NormalChars;
1000 AddToken(Saver.
save(Token.
str()));
1002 if (Src[
I] ==
'\n') {
1003 CommandName = InitialCommandName;
1006 CommandName =
false;
1009 }
else if (Src[
I] ==
'\"') {
1011 }
else if (Src[
I] ==
'\\' && !CommandName) {
1014 Token.push_back(Src[
I]);
1019 if (Src[
I] ==
'\"') {
1020 if (
I < (
E - 1) && Src[
I + 1] ==
'"') {
1023 Token.push_back(
'"');
1029 }
else if (Src[
I] ==
'\\' && !CommandName) {
1032 Token.push_back(Src[
I]);
1039 AddToken(Saver.
save(Token.
str()));
1045 auto AddToken = [&](
StringRef Tok) { NewArgv.push_back(Tok.data()); };
1046 auto OnEOL = [&]() {
1048 NewArgv.push_back(
nullptr);
1051 true, OnEOL,
false);
1056 auto AddToken = [&](
StringRef Tok) { NewArgv.push_back(Tok); };
1057 auto OnEOL = []() {};
1065 auto AddToken = [&](
StringRef Tok) { NewArgv.push_back(Tok.data()); };
1066 auto OnEOL = [&]() {
1068 NewArgv.push_back(
nullptr);
1077 for (
const char *Cur =
Source.begin(); Cur !=
Source.end();) {
1086 while (Cur !=
Source.end() && *Cur !=
'\n')
1091 const char *Start = Cur;
1092 for (
const char *End =
Source.end(); Cur != End; ++Cur) {
1094 if (Cur + 1 != End) {
1097 (*Cur ==
'\r' && (Cur + 1 != End) && Cur[1] ==
'\n')) {
1098 Line.
append(Start, Cur - 1);
1104 }
else if (*Cur ==
'\n')
1116 return (
S.size() >= 3 &&
S[0] ==
'\xef' &&
S[1] ==
'\xbb' &&
S[2] ==
'\xbf');
1130 TokenPos = ArgString.
find(Token, StartPos)) {
1134 if (ResponseFile.empty())
1138 ResponseFile.
append(BasePath);
1139 StartPos = TokenPos + Token.size();
1142 if (!ResponseFile.empty()) {
1145 if (!Remaining.
empty())
1155 bool MarkEOLs,
bool RelativeNames,
1156 bool ExpandBasePath,
1160 FS.getBufferForFile(FName);
1168 std::string UTF8Buf;
1172 "Could not convert UTF16 to UTF8");
1182 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
1190 for (
auto &
Arg : NewArgv) {
1208 ResponseFile.push_back(
'@');
1209 ResponseFile.
append(BasePath);
1220 bool RelativeNames,
bool ExpandBasePath,
1223 bool AllExpanded =
true;
1224 struct ResponseFileRecord {
1236 FileStack.push_back({
"", Argv.size()});
1239 for (
unsigned I = 0;
I != Argv.size();) {
1240 while (
I == FileStack.back().End) {
1243 FileStack.pop_back();
1246 const char *
Arg = Argv[
I];
1248 if (
Arg ==
nullptr) {
1253 if (
Arg[0] !=
'@') {
1258 const char *FName =
Arg + 1;
1266 CurrDir = *CurrentDir;
1268 FName = CurrDir.
c_str();
1270 auto IsEquivalent = [FName, &
FS](
const ResponseFileRecord &RFile) {
1283 return LHS->equivalent(*
RHS);
1290 AllExpanded =
false;
1300 RelativeNames, ExpandBasePath,
FS)) {
1305 AllExpanded =
false;
1310 for (ResponseFileRecord &
Record : FileStack) {
1313 Record.End += ExpandedArgv.size() - 1;
1316 FileStack.push_back({FName,
I + ExpandedArgv.size()});
1317 Argv.
erase(Argv.begin() +
I);
1318 Argv.
insert(Argv.begin() +
I, ExpandedArgv.begin(), ExpandedArgv.end());
1326 assert(FileStack.size() > 0 && Argv.size() == FileStack.back().End);
1332 bool RelativeNames,
bool ExpandBasePath,
1335 RelativeNames, ExpandBasePath,
1348 Tokenize(*EnvValue, Saver, NewArgv,
false);
1351 NewArgv.
append(Argv + 1, Argv + Argc);
1361 CfgFile = AbsPath.
str();
1380 bool LongOptionsUseDoubleDash) {
1385 NewArgv.push_back(argv[0]);
1395 for (
int I = 1;
I < argc; ++
I)
1396 NewArgv.push_back(argv[
I]);
1397 int NewArgc =
static_cast<int>(NewArgv.size());
1400 return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
1401 Errs, LongOptionsUseDoubleDash);
1409 for (
auto *
SC : RegisteredSubCommands) {
1410 for (
auto &
O :
SC->OptionsMap)
1416 if (
SC->ConsumeAfterOpt)
1417 SC->ConsumeAfterOpt->reset();
1422 const char *
const *argv,
1425 bool LongOptionsUseDoubleDash) {
1426 assert(hasOptions() &&
"No options specified!");
1437 argc =
static_cast<int>(newArgv.size());
1442 ProgramOverview = Overview;
1443 bool IgnoreErrors = Errs;
1446 bool ErrorParsing =
false;
1449 unsigned NumPositionalRequired = 0;
1452 bool HasUnlimitedPositionals =
false;
1456 if (argc >= 2 && argv[FirstArg][0] !=
'-') {
1459 ChosenSubCommand = LookupSubCommand(
StringRef(argv[FirstArg]));
1465 assert(ChosenSubCommand);
1468 auto &SinkOpts = ChosenSubCommand->
SinkOpts;
1469 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1471 for (
auto *
O: DefaultOptions) {
1475 if (ConsumeAfterOpt) {
1476 assert(PositionalOpts.size() > 0 &&
1477 "Cannot specify cl::ConsumeAfter without a positional argument!");
1479 if (!PositionalOpts.empty()) {
1482 bool UnboundedFound =
false;
1483 for (
size_t i = 0,
e = PositionalOpts.size();
i !=
e; ++
i) {
1484 Option *Opt = PositionalOpts[
i];
1486 ++NumPositionalRequired;
1487 else if (ConsumeAfterOpt) {
1490 if (PositionalOpts.size() > 1) {
1492 Opt->
error(
"error - this positional option will never be matched, "
1493 "because it does not Require a value, and a "
1494 "cl::ConsumeAfter option is active!");
1495 ErrorParsing =
true;
1497 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1503 Opt->
error(
"error - option can never match, because "
1504 "another positional argument will match an "
1505 "unbounded number of values, and this option"
1506 " does not require a value!");
1507 *Errs << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr
1508 <<
"' is all messed up!\n";
1509 *Errs << PositionalOpts.size();
1510 ErrorParsing =
true;
1514 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1525 Option *ActivePositionalArg =
nullptr;
1528 bool DashDashFound =
false;
1529 for (
int i = FirstArg;
i < argc; ++
i) {
1530 Option *Handler =
nullptr;
1531 Option *NearestHandler =
nullptr;
1532 std::string NearestHandlerString;
1535 bool HaveDoubleDash =
false;
1541 if (argv[
i][0] !=
'-' || argv[
i][1] == 0 || DashDashFound) {
1543 if (ActivePositionalArg) {
1548 if (!PositionalOpts.empty()) {
1549 PositionalVals.push_back(std::make_pair(
StringRef(argv[
i]),
i));
1554 if (PositionalVals.size() >= NumPositionalRequired && ConsumeAfterOpt) {
1555 for (++
i;
i < argc; ++
i)
1556 PositionalVals.push_back(std::make_pair(
StringRef(argv[
i]),
i));
1563 }
else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'-' && argv[
i][2] == 0 &&
1565 DashDashFound =
true;
1567 }
else if (ActivePositionalArg &&
1574 if (!ArgName.
empty() && ArgName[0] ==
'-') {
1575 HaveDoubleDash =
true;
1576 ArgName = ArgName.
substr(1);
1579 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1580 LongOptionsUseDoubleDash, HaveDoubleDash);
1588 if (!ArgName.
empty() && ArgName[0] ==
'-') {
1589 HaveDoubleDash =
true;
1590 ArgName = ArgName.
substr(1);
1593 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1594 LongOptionsUseDoubleDash, HaveDoubleDash);
1597 if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
1603 if (!Handler && SinkOpts.empty())
1609 if (SinkOpts.empty()) {
1610 *Errs << ProgramName <<
": Unknown command line argument '" << argv[
i]
1611 <<
"'. Try: '" << argv[0] <<
" --help'\n";
1613 if (NearestHandler) {
1615 *Errs << ProgramName <<
": Did you mean '"
1616 << PrintArg(NearestHandlerString, 0) <<
"'?\n";
1619 ErrorParsing =
true;
1621 for (
Option *SinkOpt : SinkOpts)
1622 SinkOpt->addOccurrence(
i,
"",
StringRef(argv[
i]));
1631 Handler->
error(
"This argument does not take a value.\n"
1632 "\tInstead, it consumes any positional arguments until "
1633 "the next recognized option.", *Errs);
1634 ErrorParsing =
true;
1636 ActivePositionalArg = Handler;
1643 if (NumPositionalRequired > PositionalVals.size()) {
1644 *Errs << ProgramName
1645 <<
": Not enough positional command line arguments specified!\n"
1646 <<
"Must specify at least " << NumPositionalRequired
1647 <<
" positional argument" << (NumPositionalRequired > 1 ?
"s" :
"")
1648 <<
": See: " << argv[0] <<
" --help\n";
1650 ErrorParsing =
true;
1651 }
else if (!HasUnlimitedPositionals &&
1652 PositionalVals.size() > PositionalOpts.size()) {
1653 *Errs << ProgramName <<
": Too many positional arguments specified!\n"
1654 <<
"Can specify at most " << PositionalOpts.size()
1655 <<
" positional arguments: See: " << argv[0] <<
" --help\n";
1656 ErrorParsing =
true;
1658 }
else if (!ConsumeAfterOpt) {
1660 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.size());
1661 for (
size_t i = 0,
e = PositionalOpts.size();
i !=
e; ++
i) {
1664 PositionalVals[ValNo].second);
1666 --NumPositionalRequired;
1673 bool Done = PositionalOpts[
i]->getNumOccurrencesFlag() ==
cl::Required;
1674 while (NumVals - ValNo > NumPositionalRequired && !Done) {
1675 switch (PositionalOpts[
i]->getNumOccurrencesFlag()) {
1682 PositionalVals[ValNo].first,
1683 PositionalVals[ValNo].second);
1688 "positional argument processing!");
1693 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.size());
1695 for (
size_t J = 0,
E = PositionalOpts.size(); J !=
E; ++J)
1698 PositionalVals[ValNo].first,
1699 PositionalVals[ValNo].second);
1708 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.empty()) {
1710 PositionalVals[ValNo].first,
1711 PositionalVals[ValNo].second);
1717 for (; ValNo != PositionalVals.size(); ++ValNo)
1720 PositionalVals[ValNo].second);
1724 for (
const auto &Opt : OptionsMap) {
1729 Opt.second->
error(
"must be specified at least once!");
1730 ErrorParsing =
true;
1742 for (
int i = 0;
i < argc; ++
i)
dbgs() << argv[
i] <<
' ';
1763 if (!ArgName.
data())
1765 if (ArgName.
empty())
1768 Errs <<
GlobalParser->ProgramName <<
": for the " << PrintArg(ArgName, 0);
1770 Errs <<
" option: " << Message <<
"\n";
1779 return handleOccurrence(pos, ArgName,
Value);
1786 if (
O.ValueStr.empty())
1796 size_t alias::getOptionWidth()
const {
1801 size_t FirstLineIndentedBy) {
1802 assert(Indent >= FirstLineIndentedBy);
1803 std::pair<StringRef, StringRef> Split =
HelpStr.
split(
'\n');
1806 while (!Split.second.empty()) {
1807 Split = Split.second.
split(
'\n');
1808 outs().
indent(Indent) << Split.first <<
"\n";
1813 size_t FirstLineIndentedBy) {
1815 assert(BaseIndent >= FirstLineIndentedBy);
1816 std::pair<StringRef, StringRef> Split =
HelpStr.
split(
'\n');
1817 outs().
indent(BaseIndent - FirstLineIndentedBy)
1819 while (!Split.second.empty()) {
1820 Split = Split.second.
split(
'\n');
1821 outs().
indent(BaseIndent + ValHelpPrefix.
size()) << Split.first <<
"\n";
1826 void alias::printOptionInfo(
size_t GlobalWidth)
const {
1842 if (!ValName.empty()) {
1843 size_t FormattingLen = 3;
1856 size_t GlobalWidth)
const {
1857 outs() << PrintArg(
O.ArgStr);
1860 if (!ValName.empty()) {
1873 size_t GlobalWidth)
const {
1874 outs() << PrintArg(
O.ArgStr);
1882 if (
Arg ==
"" ||
Arg ==
"true" ||
Arg ==
"TRUE" ||
Arg ==
"True" ||
1888 if (
Arg ==
"false" ||
Arg ==
"FALSE" ||
Arg ==
"False" ||
Arg ==
"0") {
1892 return O.error(
"'" +
Arg +
1893 "' is invalid value for boolean argument! Try 0 or 1");
1900 if (
Arg ==
"" ||
Arg ==
"true" ||
Arg ==
"TRUE" ||
Arg ==
"True" ||
1905 if (
Arg ==
"false" ||
Arg ==
"FALSE" ||
Arg ==
"False" ||
Arg ==
"0") {
1910 return O.error(
"'" +
Arg +
1911 "' is invalid value for boolean argument! Try 0 or 1");
1919 return O.error(
"'" +
Arg +
"' value invalid for integer argument!");
1928 return O.error(
"'" +
Arg +
"' value invalid for long argument!");
1937 return O.error(
"'" +
Arg +
"' value invalid for llong argument!");
1947 return O.error(
"'" +
Arg +
"' value invalid for uint argument!");
1954 unsigned long &
Value) {
1957 return O.error(
"'" +
Arg +
"' value invalid for ulong argument!");
1965 unsigned long long &
Value) {
1968 return O.error(
"'" +
Arg +
"' value invalid for ullong argument!");
1977 return O.error(
"'" +
Arg +
"' value invalid for floating point argument!");
2003 for (
unsigned i = 0;
i !=
e; ++
i) {
2020 !Description.
empty();
2025 if (
O.hasArgStr()) {
2037 size_t BaseSize = 0;
2048 size_t GlobalWidth)
const {
2049 if (
O.hasArgStr()) {
2055 outs() << PrintArg(
O.ArgStr);
2074 if (OptionName.empty()) {
2079 if (!Description.
empty())
2085 if (!
O.HelpStr.empty())
2086 outs() <<
" " <<
O.HelpStr <<
'\n';
2103 outs() <<
" " << PrintArg(
O.ArgStr);
2107 for (
unsigned i = 0;
i != NumOpts; ++
i) {
2115 for (
unsigned j = 0;
j != NumOpts; ++
j) {
2124 outs() <<
"= *unknown option value*\n";
2129 #define PRINT_OPT_DIFF(T) \
2130 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
2131 size_t GlobalWidth) const { \
2132 printOptionName(O, GlobalWidth); \
2135 raw_string_ostream SS(Str); \
2138 outs() << "= " << Str; \
2139 size_t NumSpaces = \
2140 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
2141 outs().indent(NumSpaces) << " (default: "; \
2143 outs() << D.getValue(); \
2145 outs() << "*no default*"; \
2163 size_t GlobalWidth)
const {
2164 printOptionName(
O, GlobalWidth);
2165 outs() <<
"= " << V;
2169 outs() <<
D.getValue();
2171 outs() <<
"*no default*";
2177 size_t GlobalWidth)
const {
2179 outs() <<
"= *cannot print option value*\n";
2187 const std::pair<const char *, Option *> *
RHS) {
2188 return strcmp(
LHS->first,
RHS->first);
2192 const std::pair<const char *, SubCommand *> *
RHS) {
2193 return strcmp(
LHS->first,
RHS->first);
2209 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
2213 if (!OptionSet.
insert(
I->second).second)
2217 std::pair<const char *, Option *>(
I->getKey().data(),
I->second));
2227 for (
auto *
S : SubMap) {
2228 if (
S->getName().empty())
2230 Subs.push_back(std::make_pair(
S->getName().data(),
S));
2239 const bool ShowHidden;
2241 StrOptionPairVector;
2243 StrSubCommandPairVector;
2245 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
2246 for (
size_t i = 0,
e = Opts.size();
i !=
e; ++
i)
2247 Opts[
i].second->printOptionInfo(MaxArgLen);
2250 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
2251 for (
const auto &
S : Subs) {
2252 outs() <<
" " <<
S.first;
2253 if (!
S.second->getDescription().empty()) {
2255 outs() <<
" - " <<
S.second->getDescription();
2262 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
2263 virtual ~HelpPrinter() =
default;
2266 void operator=(
bool Value) {
2281 StrOptionPairVector Opts;
2282 sortOpts(OptionsMap, Opts, ShowHidden);
2284 StrSubCommandPairVector Subs;
2292 if (Subs.size() > 2)
2293 outs() <<
" [subcommand]";
2294 outs() <<
" [options]";
2304 for (
auto *Opt : PositionalOpts) {
2311 if (ConsumeAfterOpt)
2312 outs() <<
" " << ConsumeAfterOpt->HelpStr;
2316 size_t MaxSubLen = 0;
2317 for (
size_t i = 0,
e = Subs.size();
i !=
e; ++
i)
2318 MaxSubLen =
std::max(MaxSubLen, strlen(Subs[
i].first));
2321 outs() <<
"SUBCOMMANDS:\n\n";
2322 printSubCommands(Subs, MaxSubLen);
2325 <<
" <subcommand> --help\" to get more help on a specific "
2332 size_t MaxArgLen = 0;
2333 for (
size_t i = 0,
e = Opts.size();
i !=
e; ++
i)
2334 MaxArgLen =
std::max(MaxArgLen, Opts[
i].second->getOptionWidth());
2336 outs() <<
"OPTIONS:\n";
2337 printOptions(Opts, MaxArgLen);
2346 class CategorizedHelpPrinter :
public HelpPrinter {
2348 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
2356 return (*A)->getName().compare((*B)->getName());
2360 using HelpPrinter::operator=;
2363 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
2364 std::vector<OptionCategory *> SortedCategories;
2370 SortedCategories.push_back(Category);
2373 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
2375 OptionCategoryCompare);
2380 for (
size_t I = 0,
E = Opts.size();
I !=
E; ++
I) {
2383 assert(
find(SortedCategories, Cat) != SortedCategories.end() &&
2384 "Option has an unregistered category");
2385 CategorizedOptions[Cat].push_back(Opt);
2392 const auto &CategoryOptions = CategorizedOptions[Category];
2393 bool IsEmptyCategory = CategoryOptions.
empty();
2394 if (!ShowHidden && IsEmptyCategory)
2409 if (IsEmptyCategory) {
2410 outs() <<
" This option category has no options.\n";
2414 for (
const Option *Opt : CategoryOptions)
2422 class HelpPrinterWrapper {
2424 HelpPrinter &UncategorizedPrinter;
2425 CategorizedHelpPrinter &CategorizedPrinter;
2428 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
2429 CategorizedHelpPrinter &CategorizedPrinter)
2430 : UncategorizedPrinter(UncategorizedPrinter),
2431 CategorizedPrinter(CategorizedPrinter) {}
2434 void operator=(
bool Value);
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);
2497 struct CommandLineCommonOptions {
2500 HelpPrinter UncategorizedNormalPrinter{
false};
2501 HelpPrinter UncategorizedHiddenPrinter{
true};
2502 CategorizedHelpPrinter CategorizedNormalPrinter{
false};
2503 CategorizedHelpPrinter CategorizedHiddenPrinter{
true};
2506 HelpPrinterWrapper WrappedNormalPrinter{UncategorizedNormalPrinter,
2507 CategorizedNormalPrinter};
2508 HelpPrinterWrapper WrappedHiddenPrinter{UncategorizedHiddenPrinter,
2509 CategorizedHiddenPrinter};
2519 "Display list of available options (--help-list-hidden for more)"),
2528 cl::desc(
"Display list of all available options"),
2540 cl::desc(
"Display available options (--help-hidden for more)"),
2551 cl::desc(
"Display all available options"),
2560 cl::desc(
"Print non-default options after command line parsing"),
2567 "print-all-options",
2568 cl::desc(
"Print all option values after command line parsing"),
2576 std::vector<VersionPrinterTy> ExtraVersionPrinters;
2579 VersionPrinter VersionPrinterInstance;
2582 "version",
cl::desc(
"Display the version of this program"),
2608 return GeneralCategory;
2611 void VersionPrinter::operator=(
bool OptionWasSpecified) {
2612 if (!OptionWasSpecified)
2632 void HelpPrinterWrapper::operator=(
bool Value) {
2639 if (
GlobalParser->RegisteredOptionCategories.size() > 1) {
2644 CategorizedPrinter =
true;
2646 UncategorizedPrinter =
true;
2652 void CommandLineParser::printOptionValues() {
2660 size_t MaxArgLen = 0;
2661 for (
size_t i = 0,
e = Opts.size();
i !=
e; ++
i)
2662 MaxArgLen =
std::max(MaxArgLen, Opts[
i].second->getOptionWidth());
2664 for (
size_t i = 0,
e = Opts.size();
i !=
e; ++
i)
2665 Opts[
i].second->printOptionValue(MaxArgLen,
CommonOptions->PrintAllOptions);
2670 if (!
Hidden && !Categorized)
2672 else if (!
Hidden && Categorized)
2674 else if (
Hidden && !Categorized)
2709 bool Unrelated =
true;
2710 for (
auto &Cat :
I.second->Categories) {
2711 if (Cat == &Category || Cat == &
CommonOptions->GenericCategory)
2723 bool Unrelated =
true;
2724 for (
auto &Cat :
I.second->Categories) {
2740 const char *Overview) {
bool readConfigFile(StringRef CfgFileName, StringSaver &Saver, SmallVectorImpl< const char * > &Argv)
Reads command line options from the given configuration file.
void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Add an extra printer to u...
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
static bool isWindowsSpecialChar(char C)
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
This is an optimization pass for GlobalISel generic memory operations.
iterator erase(const_iterator CI)
static void tokenizeWindowsCommandLineImpl(StringRef Src, StringSaver &Saver, function_ref< void(StringRef)> AddToken, bool AlwaysCopy, function_ref< void()> MarkEOL, bool InitialCommandName)
StringMap< Option * > OptionsMap
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in it
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
SmallVector< OptionCategory *, 1 > Categories
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
static Option * getOptionPred(StringRef Name, size_t &Length, bool(*Pred)(const Option *), const StringMap< Option * > &OptionsMap)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static void sortSubCommands(const SmallPtrSetImpl< SubCommand * > &SubMap, SmallVectorImpl< std::pair< const char *, SubCommand * >> &Subs)
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
SmallVector< Option *, 4 > PositionalOpts
LocationClass< Ty > location(Ty &L)
void printOptionNoValue(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.
static constexpr size_t npos
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void PrintVersionMessage()
Utility function for printing version number.
void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
bool error(const Twine &Message, StringRef ArgName=StringRef(), raw_ostream &Errs=llvm::errs())
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
static ErrorSuccess success()
Create a success value.
static SmallString< 8 > argPrefix(StringRef ArgName, size_t Pad=DefaultPad)
void ResetCommandLineParser()
Reset the command line parser back to its initial state.
bool hasUTF16ByteOrderMark(ArrayRef< char > SrcBytes)
Returns true if a blob of text starts with a UTF-16 big or little endian byte order mark.
Triple - Helper class for working with autoconf configuration names.
virtual void printOptionInfo(size_t GlobalWidth) const =0
static bool isWindowsSpecialCharInCommandName(char C)
void setMiscFlag(enum MiscFlags M)
static void Help(ArrayRef< SubtargetSubTypeKV > CPUTable, ArrayRef< SubtargetFeatureKV > FeatTable)
Display help for feature and mcpu choices.
virtual unsigned getNumOptions() const =0
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv)
A convenience helper which concatenates the options specified by the environment variable EnvVar and ...
void unregisterSubCommand()
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::function< void(raw_ostream &)> VersionPrinterTy
void initGraphWriterOptions()
iterator find(StringRef Key)
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
static void printEnumValHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
void TokenizeWindowsCommandLineFull(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows full command line, including command name at the start.
void consumeError(Error Err)
Consume a Error without doing anything.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static size_t getOptionPrefixesSize()
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
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...
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static bool isQuote(char C)
const static size_t DefaultPad
void initSignalsOptions()
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
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...
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
static ManagedStatic< CommandLineCommonOptions > CommonOptions
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
unsigned findOption(StringRef Name)
static bool parseDouble(Option &O, StringRef Arg, double &Value)
#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that they are constant initial...
const char * getBufferEnd() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool isGrouping(const Option *O)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
size_t getBufferSize() const
(vector float) vec_cmpeq(*A, *B) C
unsigned getMiscFlags() const
void initWithColorOptions()
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
static StringRef ArgPrefix
enum FormattingFlags getFormattingFlag() const
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
virtual StringRef getOption(unsigned N) const =0
std::error_code getError() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Flag
These should be considered private to the implementation of the MCInstrDesc class.
void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a string of Windows command line arguments, which may contain quotes and escaped quotes.
void registerSubCommand()
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned getNumAdditionalVals() const
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
int getNumOccurrences() const
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub= *TopLevelSubCommand)
Mark all options not part of this category as cl::ReallyHidden.
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
static const size_t MaxOptWidth
static StringRef ArgPrefixLong
ManagedStatic< SubCommand > AllSubCommands
StringRef getDescription() const
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...
static size_t argPlusPrefixesSize(StringRef ArgName, size_t Pad=DefaultPad)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
static bool isWhitespace(char C)
static int OptNameCompare(const std::pair< const char *, Option * > *LHS, const std::pair< const char *, Option * > *RHS)
An efficient, type-erasing, non-owning reference to a callable.
void append(StringRef RHS)
Append from a StringRef.
static StringRef getValueStr(const Option &O, StringRef DefaultMsg)
StringRef getDescription() const
void printOptionDiff(const Option &O, const AnyOptionValue &V, const AnyOptionValue &Default, size_t GlobalWidth) const
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
SmallVector< Option *, 4 > SinkOpts
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
enum ValueExpected getValueExpectedFlag() const
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Allocate memory in an ever growing pool, as if by bump-pointer.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
we currently eax ecx subl eax ret We would use one fewer register if codegen d eax neg eax eax ret Note that this isn t beneficial if the load can be folded into the sub In this we want a sub
void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Override the default (LLV...
initializer< Ty > init(const Ty &Val)
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv, bool MarkEOLs, bool RelativeNames, bool ExpandBasePath, llvm::Optional< llvm::StringRef > CurrentDir, llvm::vfs::FileSystem &FS)
Expand response files on a command line recursively using the given StringSaver and tokenization stra...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
static bool RequiresValue(const Option *O)
bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
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 Optional< std::string > GetEnv(StringRef name)
static ManagedStatic< CommandLineParser > GlobalParser
void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
virtual void setDefault()=0
void setArgStr(StringRef S)
void PrintHelpMessage(bool Hidden=false, bool Categorized=false)
This function just prints the help message, exactly the same way as if the -help or -help-hidden opti...
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
void initTypeSizeOptions()
virtual StringRef getValueName() const
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
void LLVMParseCommandLineOptions(int argc, const char *const *argv, const char *Overview)
This function parses the given arguments using the LLVM command line parser.
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
StringRef - Represent a constant reference to a string, i.e.
http eax xorl edx cl sete al setne dl sall cl
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static StringRef ArgHelpPrefix
static bool hasUTF8ByteOrderMark(ArrayRef< char > S)
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
void initDebugCounterOptions()
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
void initRandomSeedOptions()
static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling ...
LLVM_NODISCARD bool empty() const
virtual StringRef getDescription(unsigned N) const =0
SmallPtrSet< SubCommand *, 1 > Subs
bool isOSWindows() const
Tests whether the OS is Windows.
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
const char * getBufferStart() const
The virtual file system interface.
static void sortOpts(StringMap< Option * > &OptMap, SmallVectorImpl< std::pair< const char *, Option * >> &Opts, bool ShowHidden)
void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
static void initCommonOptions()
std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
Lightweight error class with error context and mandatory checking.
size_t getOptionWidth(const Option &O) const
StringRef getName() const
static bool EatsUnboundedNumberOfValues(const Option *O)
void initStatisticOptions()
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
static bool isWhitespaceOrNull(char C)
void printOptionName(const Option &O, size_t GlobalWidth) const
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
StringRef str() const
Explicit conversion to StringRef.
static StringRef OptionPrefix
static bool shouldPrintOption(StringRef Name, StringRef Description, const Option &O)
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
enum NumOccurrencesFlag getNumOccurrencesFlag() const
declare void exit(i32) noreturn nounwind This compiles into
Represents either an error or a value T.
size_t size() const
size - Get the array size.
Align max(MaybeAlign Lhs, Align Rhs)
StringRef save(const char *S)
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
virtual size_t getOptionWidth(const Option &O) const
A range adaptor for a pair of iterators.
ManagedStatic< SubCommand > TopLevelSubCommand
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static StringRef EmptyOption
static bool isPrefixedOrGrouping(const Option *O)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
void addCategory(OptionCategory &C)
static llvm::Error ExpandResponseFile(StringRef FName, StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs, bool RelativeNames, bool ExpandBasePath, llvm::vfs::FileSystem &FS)
LLVM_NODISCARD unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
static void ExpandBasePaths(StringRef BasePath, StringSaver &Saver, const char *&Arg)
bool isDefaultOption() const
void removeArgument()
Unregisters this option from the CommandLine system.
OptionCategory & getGeneralCategory()
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
void printOptionInfo(const Option &O, size_t GlobalWidth) const
LLVM Value Representation.
static int SubNameCompare(const std::pair< const char *, SubCommand * > *LHS, const std::pair< const char *, SubCommand * > *RHS)
iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
StringRef getName() const
#define PRINT_OPT_DIFF(T)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
iterator insert(iterator I, T &&Elt)