31#include "llvm/Config/config.h"
51#define DEBUG_TYPE "commandline"
71#if !(defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) && defined(_MSC_VER))
88void GenericOptionValue::anchor() {}
91void Option::anchor() {}
124 size_t Len = ArgName.
size();
132 for (
size_t I = 0;
I < Pad; ++
I) {
160 OS <<
argPrefix(Arg.ArgName, Arg.Pad) << Arg.ArgName;
164class CommandLineParser {
168 std::string ProgramName;
172 std::vector<StringRef> MoreHelp;
191 bool LongOptionsUseDoubleDash =
false);
194 if (Opt.
Subs.empty()) {
199 for (
auto *SC : RegisteredSubCommands)
204 for (
auto *SC : Opt.
Subs) {
206 "SubCommand::getAll() should not be used with other subcommands");
215 errs() << ProgramName <<
": CommandLine Error: Option '" <<
Name
216 <<
"' registered more than once!\n";
227 bool HadErrors =
false;
228 if (
O->hasArgStr()) {
230 if (
O->isDefaultOption() && SC->
OptionsMap.contains(
O->ArgStr))
234 if (!SC->
OptionsMap.insert(std::make_pair(
O->ArgStr, O)).second) {
235 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
236 <<
"' registered more than once!\n";
248 O->error(
"Cannot specify more than one option with cl::ConsumeAfter!");
262 void addOption(
Option *O,
bool ProcessDefaultOption =
false) {
263 if (!ProcessDefaultOption &&
O->isDefaultOption()) {
267 forEachSubCommand(*O, [&](
SubCommand &SC) { addOption(O, &SC); });
272 O->getExtraOptionNames(OptionNames);
277 auto End =
Sub.OptionsMap.end();
278 for (
auto Name : OptionNames) {
280 if (
I !=
End &&
I->getValue() == O)
281 Sub.OptionsMap.erase(
I);
285 for (
auto *Opt =
Sub.PositionalOpts.begin();
286 Opt !=
Sub.PositionalOpts.end(); ++Opt) {
288 Sub.PositionalOpts.erase(Opt);
293 for (
auto *Opt =
Sub.SinkOpts.begin(); Opt !=
Sub.SinkOpts.end(); ++Opt) {
295 Sub.SinkOpts.erase(Opt);
299 else if (O ==
Sub.ConsumeAfterOpt)
300 Sub.ConsumeAfterOpt =
nullptr;
303 void removeOption(
Option *O) {
304 forEachSubCommand(*O, [&](
SubCommand &SC) { removeOption(O, &SC); });
308 return (!
Sub.OptionsMap.empty() || !
Sub.PositionalOpts.empty() ||
309 nullptr !=
Sub.ConsumeAfterOpt);
312 bool hasOptions()
const {
313 for (
const auto *S : RegisteredSubCommands) {
320 bool hasNamedSubCommands()
const {
321 for (
const auto *S : RegisteredSubCommands)
322 if (!S->getName().empty())
327 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
331 if (!
Sub.OptionsMap.insert(std::make_pair(NewName, O)).second) {
332 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
333 <<
"' registered more than once!\n";
336 Sub.OptionsMap.erase(
O->ArgStr);
340 forEachSubCommand(*O,
341 [&](
SubCommand &SC) { updateArgStr(O, NewName, &SC); });
344 void printOptionValues();
351 "Duplicate option categories");
359 return (!
sub->getName().empty()) &&
360 (
Sub->getName() ==
sub->getName());
362 "Duplicate subcommands");
363 RegisteredSubCommands.insert(
sub);
368 "SubCommand::getAll() should not be registered");
371 if ((
O->isPositional() ||
O->isSink() ||
O->isConsumeAfter()) ||
375 addLiteralOption(*O,
sub, E.first());
380 RegisteredSubCommands.erase(
sub);
385 return make_range(RegisteredSubCommands.begin(),
386 RegisteredSubCommands.end());
390 ActiveSubCommand =
nullptr;
395 RegisteredOptionCategories.
clear();
398 RegisteredSubCommands.clear();
404 DefaultOptions.
clear();
412 bool LongOptionsUseDoubleDash,
bool HaveDoubleDash) {
414 if (Opt && LongOptionsUseDoubleDash && !HaveDoubleDash && !
isGrouping(Opt))
425template <
typename T, T TrueVal, T FalseVal>
427 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
433 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
437 return O.error(
"'" + Arg +
438 "' is invalid value for boolean argument! Try 0 or 1");
451 FullyInitialized =
true;
457 if (FullyInitialized)
483void OptionCategory::registerCategory() {
517SubCommand::operator
bool()
const {
535 size_t EqualPos = Arg.
find(
'=');
540 return Sub.OptionsMap.lookup(Arg);
546 auto I =
Sub.OptionsMap.find(Arg.
substr(0, EqualPos));
547 if (
I ==
Sub.OptionsMap.end())
555 Arg = Arg.
substr(0, EqualPos);
560 std::string &NearestString) {
565 for (
auto *S : RegisteredSubCommands) {
567 "SubCommand::getAll() is not expected in RegisteredSubCommands");
568 if (S->getName().empty())
571 if (S->getName() ==
Name)
574 if (!NearestMatch && S->getName().edit_distance(
Name) < 2)
579 NearestString = NearestMatch->
getName();
590 std::string &NearestString) {
596 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
602 unsigned BestDistance = 0;
604 ie = OptionsMap.
end();
612 O->getExtraOptionNames(OptionNames);
618 for (
const auto &
Name : OptionNames) {
620 Flag,
true, BestDistance);
621 if (!Best || Distance < BestDistance) {
623 BestDistance = Distance;
624 if (
RHS.empty() || !PermitValue)
625 NearestString = std::string(
Name);
639 bool MultiArg =
false) {
651 Val = Val.
substr(Pos + 1);
667 const char *
const *argv,
int &i) {
678 return Handler->
error(
"requires a value!");
680 assert(argv &&
"null check");
685 if (NumAdditionalVals > 0)
686 return Handler->
error(
"multi-valued option specified"
687 " with ValueDisallowed modifier!");
698 if (NumAdditionalVals == 0)
702 bool MultiArg =
false;
711 while (NumAdditionalVals > 0) {
713 return Handler->
error(
"not enough values!");
714 assert(argv &&
"null check");
737 bool (*Pred)(
const Option *),
740 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
741 OMI = OptionsMap.
end();
746 while (OMI == OptionsMap.
end() &&
Name.size() > 1) {
749 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
750 OMI = OptionsMap.
end();
753 if (OMI != OptionsMap.
end() && Pred(OMI->second)) {
781 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
791 if (MaybeValue[0] ==
'=') {
801 ErrorParsing |= PGOpt->
error(
"may not occur within a group!");
830 return C ==
' ' ||
C ==
'\t' ||
C ==
'\r' ||
C ==
'\n';
837static bool isQuote(
char C) {
return C ==
'\"' ||
C ==
'\''; }
843 for (
size_t I = 0, E = Src.size();
I != E; ++
I) {
848 if (MarkEOLs && Src[
I] ==
'\n')
859 if (
I + 1 < E &&
C ==
'\\') {
868 while (
I != E && Src[
I] !=
C) {
870 if (Src[
I] ==
'\\' &&
I + 1 != E)
885 if (MarkEOLs &&
C ==
'\n')
918 size_t E = Src.size();
919 int BackslashCount = 0;
924 }
while (
I != E && Src[
I] ==
'\\');
926 bool FollowedByDoubleQuote = (
I != E && Src[
I] ==
'"');
927 if (FollowedByDoubleQuote) {
928 Token.
append(BackslashCount / 2,
'\\');
929 if (BackslashCount % 2 == 0)
934 Token.
append(BackslashCount,
'\\');
952 bool AlwaysCopy,
function_ref<
void()> MarkEOL,
bool InitialCommandName) {
961 bool CommandName = InitialCommandName;
964 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
966 for (
size_t I = 0, E = Src.size();
I < E; ++
I) {
969 assert(Token.
empty() &&
"token should be empty in initial state");
991 AddToken(AlwaysCopy ? Saver.
save(NormalChars) : NormalChars);
992 if (
I < E && Src[
I] ==
'\n') {
994 CommandName = InitialCommandName;
998 }
else if (Src[
I] ==
'\"') {
999 Token += NormalChars;
1001 }
else if (Src[
I] ==
'\\') {
1002 assert(!CommandName &&
"or else we'd have treated it as a normal char");
1003 Token += NormalChars;
1017 AddToken(Saver.
save(Token.
str()));
1019 if (Src[
I] ==
'\n') {
1020 CommandName = InitialCommandName;
1023 CommandName =
false;
1026 }
else if (Src[
I] ==
'\"') {
1028 }
else if (Src[
I] ==
'\\' && !CommandName) {
1036 if (Src[
I] ==
'\"') {
1037 if (
I < (E - 1) && Src[
I + 1] ==
'"') {
1046 }
else if (Src[
I] ==
'\\' && !CommandName) {
1056 AddToken(Saver.
save(Token.
str()));
1063 auto OnEOL = [&]() {
1068 true, OnEOL,
false);
1074 auto OnEOL = []() {};
1083 auto OnEOL = [&]() {
1094 for (
const char *Cur = Source.begin(); Cur != Source.end();) {
1103 while (Cur != Source.end() && *Cur !=
'\n')
1108 const char *Start = Cur;
1109 for (
const char *
End = Source.end(); Cur !=
End; ++Cur) {
1111 if (Cur + 1 !=
End) {
1114 (*Cur ==
'\r' && (Cur + 1 !=
End) && Cur[1] ==
'\n')) {
1115 Line.append(Start, Cur - 1);
1121 }
else if (*Cur ==
'\n')
1125 Line.append(Start, Cur);
1133 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
1147 TokenPos = ArgString.
find(Token, StartPos)) {
1151 if (ResponseFile.
empty())
1155 ResponseFile.
append(BasePath);
1156 StartPos = TokenPos + Token.
size();
1159 if (!ResponseFile.
empty()) {
1162 if (!Remaining.
empty())
1169Error ExpansionContext::expandResponseFile(
1177 "': " +
EC.message());
1184 std::string UTF8Buf;
1188 "Could not convert UTF16 to UTF8");
1195 Str =
StringRef(BufRef.data() + 3, BufRef.size() - 3);
1198 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
1203 if (!RelativeNames && !InConfigFile)
1207 for (
const char *&Arg : NewArgv) {
1219 bool ConfigInclusion =
false;
1220 if (ArgStr.consume_front(
"@")) {
1224 }
else if (ArgStr.consume_front(
"--config=")) {
1226 ConfigInclusion =
true;
1238 std::make_error_code(std::errc::no_such_file_or_directory),
1239 "cannot not find configuration file: " + FileName);
1240 ResponseFile.
append(FilePath);
1242 ResponseFile.
append(BasePath);
1254 struct ResponseFileRecord {
1269 for (
unsigned I = 0;
I != Argv.
size();) {
1270 while (
I == FileStack.
back().End) {
1276 const char *Arg = Argv[
I];
1278 if (Arg ==
nullptr) {
1283 if (Arg[0] !=
'@') {
1288 const char *FName = Arg + 1;
1293 if (CurrentDir.
empty()) {
1298 CWD.getError(),
Twine(
"cannot get absolute path for: ") + FName);
1301 CurrDir = CurrentDir;
1304 FName = CurrDir.
c_str();
1308 if (!Res || !Res->exists()) {
1309 std::error_code EC = Res.
getError();
1310 if (!InConfigFile) {
1321 "': " + EC.message());
1326 [FileStatus,
this](
const ResponseFileRecord &RFile) ->
ErrorOr<bool> {
1329 return RHS.getError();
1338 R.getError(),
Twine(
"recursive expansion of: '") +
F.File +
"'");
1341 Twine(
"cannot open file: ") +
F.File);
1348 if (
Error Err = expandResponseFile(FName, ExpandedArgv))
1351 for (ResponseFileRecord &
Record : FileStack) {
1357 FileStack.push_back({FName,
I + ExpandedArgv.
size()});
1382 Tokenize(*EnvValue, Saver, NewArgv,
false);
1385 NewArgv.
append(Argv + 1, Argv + Argc);
1405 : Saver(
A), Tokenizer(
T), FS(vfs::getRealFileSystem().
get()) {}
1419 CfgFilePath = FileName;
1422 if (!FileExists(CfgFilePath))
1429 for (
const StringRef &Dir : SearchDirs) {
1435 if (FileExists(CfgFilePath)) {
1450 return make_error<StringError>(
1451 EC,
Twine(
"cannot get absolute path for " + CfgFile));
1452 CfgFile = AbsPath.
str();
1454 InConfigFile =
true;
1455 RelativeNames =
true;
1456 if (
Error Err = expandResponseFile(CfgFile, Argv))
1465 bool LongOptionsUseDoubleDash) {
1474 if (std::optional<std::string> EnvValue =
1480 for (
int I = 1;
I < argc; ++
I)
1482 int NewArgc =
static_cast<int>(NewArgv.
size());
1485 return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
1486 Errs, LongOptionsUseDoubleDash);
1490void CommandLineParser::ResetAllOptionOccurrences() {
1494 for (
auto *SC : RegisteredSubCommands) {
1506bool CommandLineParser::ParseCommandLineOptions(
int argc,
1507 const char *
const *argv,
1510 bool LongOptionsUseDoubleDash) {
1511 assert(hasOptions() &&
"No options specified!");
1513 ProgramOverview = Overview;
1514 bool IgnoreErrors = Errs;
1517 bool ErrorParsing =
false;
1528 if (
Error Err = ECtx.expandResponseFiles(newArgv)) {
1529 *Errs <<
toString(std::move(Err)) <<
'\n';
1533 argc =
static_cast<int>(newArgv.size());
1539 unsigned NumPositionalRequired = 0;
1542 bool HasUnlimitedPositionals =
false;
1546 std::string NearestSubCommandString;
1547 bool MaybeNamedSubCommand =
1548 argc >= 2 && argv[FirstArg][0] !=
'-' && hasNamedSubCommands();
1549 if (MaybeNamedSubCommand) {
1553 LookupSubCommand(
StringRef(argv[FirstArg]), NearestSubCommandString);
1559 assert(ChosenSubCommand);
1562 auto &SinkOpts = ChosenSubCommand->
SinkOpts;
1563 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1565 for (
auto *O: DefaultOptions) {
1569 if (ConsumeAfterOpt) {
1570 assert(PositionalOpts.size() > 0 &&
1571 "Cannot specify cl::ConsumeAfter without a positional argument!");
1573 if (!PositionalOpts.empty()) {
1576 bool UnboundedFound =
false;
1577 for (
size_t i = 0, e = PositionalOpts.size(); i != e; ++i) {
1578 Option *Opt = PositionalOpts[i];
1580 ++NumPositionalRequired;
1581 else if (ConsumeAfterOpt) {
1584 if (PositionalOpts.size() > 1) {
1586 Opt->
error(
"error - this positional option will never be matched, "
1587 "because it does not Require a value, and a "
1588 "cl::ConsumeAfter option is active!");
1589 ErrorParsing =
true;
1591 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1597 Opt->
error(
"error - option can never match, because "
1598 "another positional argument will match an "
1599 "unbounded number of values, and this option"
1600 " does not require a value!");
1601 *Errs << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr
1602 <<
"' is all messed up!\n";
1603 *Errs << PositionalOpts.size();
1604 ErrorParsing =
true;
1608 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1619 Option *ActivePositionalArg =
nullptr;
1622 bool DashDashFound =
false;
1623 for (
int i = FirstArg; i < argc; ++i) {
1624 Option *Handler =
nullptr;
1625 std::string NearestHandlerString;
1628 bool HaveDoubleDash =
false;
1634 if (argv[i][0] !=
'-' || argv[i][1] == 0 || DashDashFound) {
1636 if (ActivePositionalArg) {
1641 if (!PositionalOpts.empty()) {
1647 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
1648 for (++i; i < argc; ++i)
1656 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
1658 DashDashFound =
true;
1660 }
else if (ActivePositionalArg &&
1668 HaveDoubleDash =
true;
1670 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1671 LongOptionsUseDoubleDash, HaveDoubleDash);
1680 HaveDoubleDash =
true;
1682 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1683 LongOptionsUseDoubleDash, HaveDoubleDash);
1690 LongOptionsUseDoubleDash, HaveDoubleDash);
1693 if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
1699 if (!Handler && SinkOpts.empty())
1704 if (!SinkOpts.empty()) {
1705 for (
Option *SinkOpt : SinkOpts)
1706 SinkOpt->addOccurrence(i,
"",
StringRef(argv[i]));
1710 auto ReportUnknownArgument = [&](
bool IsArg,
1712 *Errs << ProgramName <<
": Unknown "
1713 << (IsArg ?
"command line argument" :
"subcommand") <<
" '"
1714 << argv[i] <<
"'. Try: '" << argv[0] <<
" --help'\n";
1716 if (NearestArgumentName.empty())
1719 *Errs << ProgramName <<
": Did you mean '";
1721 *Errs << PrintArg(NearestArgumentName, 0);
1723 *Errs << NearestArgumentName;
1727 if (i > 1 || !MaybeNamedSubCommand)
1728 ReportUnknownArgument(
true, NearestHandlerString);
1730 ReportUnknownArgument(
false, NearestSubCommandString);
1732 ErrorParsing =
true;
1740 Handler->
error(
"This argument does not take a value.\n"
1741 "\tInstead, it consumes any positional arguments until "
1742 "the next recognized option.", *Errs);
1743 ErrorParsing =
true;
1745 ActivePositionalArg = Handler;
1752 if (NumPositionalRequired > PositionalVals.
size()) {
1753 *Errs << ProgramName
1754 <<
": Not enough positional command line arguments specified!\n"
1755 <<
"Must specify at least " << NumPositionalRequired
1756 <<
" positional argument" << (NumPositionalRequired > 1 ?
"s" :
"")
1757 <<
": See: " << argv[0] <<
" --help\n";
1759 ErrorParsing =
true;
1760 }
else if (!HasUnlimitedPositionals &&
1761 PositionalVals.
size() > PositionalOpts.size()) {
1762 *Errs << ProgramName <<
": Too many positional arguments specified!\n"
1763 <<
"Can specify at most " << PositionalOpts.size()
1764 <<
" positional arguments: See: " << argv[0] <<
" --help\n";
1765 ErrorParsing =
true;
1767 }
else if (!ConsumeAfterOpt) {
1769 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1770 for (
Option *Opt : PositionalOpts) {
1773 PositionalVals[ValNo].second);
1775 --NumPositionalRequired;
1783 while (NumVals - ValNo > NumPositionalRequired && !
Done) {
1791 PositionalVals[ValNo].second);
1796 "positional argument processing!");
1801 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1803 for (
Option *Opt : PositionalOpts)
1806 Opt, PositionalVals[ValNo].first, PositionalVals[ValNo].second);
1815 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1817 PositionalVals[ValNo].first,
1818 PositionalVals[ValNo].second);
1824 for (; ValNo != PositionalVals.
size(); ++ValNo)
1827 PositionalVals[ValNo].second);
1831 for (
const auto &Opt : OptionsMap) {
1836 Opt.second->
error(
"must be specified at least once!");
1837 ErrorParsing =
true;
1849 for (
int i = 0; i < argc; ++i)
dbgs() << argv[i] <<
' ';
1870 if (!ArgName.
data())
1872 if (ArgName.
empty())
1875 Errs <<
GlobalParser->ProgramName <<
": for the " << PrintArg(ArgName, 0);
1877 Errs <<
" option: " << Message <<
"\n";
1886 return handleOccurrence(pos, ArgName,
Value);
1893 if (O.ValueStr.empty())
1903size_t alias::getOptionWidth()
const {
1908 size_t FirstLineIndentedBy) {
1909 assert(Indent >= FirstLineIndentedBy);
1910 std::pair<StringRef, StringRef> Split =
HelpStr.
split(
'\n');
1913 while (!Split.second.empty()) {
1914 Split = Split.second.split(
'\n');
1915 outs().
indent(Indent) << Split.first <<
"\n";
1920 size_t FirstLineIndentedBy) {
1922 assert(BaseIndent >= FirstLineIndentedBy);
1923 std::pair<StringRef, StringRef> Split =
HelpStr.
split(
'\n');
1924 outs().
indent(BaseIndent - FirstLineIndentedBy)
1926 while (!Split.second.empty()) {
1927 Split = Split.second.split(
'\n');
1928 outs().
indent(BaseIndent + ValHelpPrefix.
size()) << Split.first <<
"\n";
1933void alias::printOptionInfo(
size_t GlobalWidth)
const {
1949 if (!ValName.empty()) {
1950 size_t FormattingLen = 3;
1963 size_t GlobalWidth)
const {
1964 outs() << PrintArg(O.ArgStr);
1967 if (!ValName.empty()) {
1973 outs() << (O.ArgStr.size() == 1 ?
" <" :
"=<") <<
getValueStr(O, ValName)
1982 size_t GlobalWidth)
const {
1983 outs() << PrintArg(O.ArgStr);
1984 outs().
indent(GlobalWidth - O.ArgStr.size());
1991 return parseBool<bool, true, false>(O, ArgName, Arg,
Value);
1998 return parseBool<boolOrDefault, BOU_TRUE, BOU_FALSE>(O, ArgName, Arg,
Value);
2006 return O.error(
"'" + Arg +
"' value invalid for integer argument!");
2015 return O.error(
"'" + Arg +
"' value invalid for long argument!");
2024 return O.error(
"'" + Arg +
"' value invalid for llong argument!");
2034 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
2041 unsigned long &
Value) {
2044 return O.error(
"'" + Arg +
"' value invalid for ulong argument!");
2052 unsigned long long &
Value) {
2055 return O.error(
"'" + Arg +
"' value invalid for ullong argument!");
2062 if (to_float(Arg,
Value))
2064 return O.error(
"'" + Arg +
"' value invalid for floating point argument!");
2090 for (
unsigned i = 0; i != e; ++i) {
2107 !Description.
empty();
2112 if (O.hasArgStr()) {
2124 size_t BaseSize = 0;
2135 size_t GlobalWidth)
const {
2136 if (O.hasArgStr()) {
2142 outs() << PrintArg(O.ArgStr);
2161 if (OptionName.
empty()) {
2166 if (!Description.
empty())
2172 if (!O.HelpStr.empty())
2173 outs() <<
" " << O.HelpStr <<
'\n';
2190 outs() <<
" " << PrintArg(O.ArgStr);
2191 outs().
indent(GlobalWidth - O.ArgStr.size());
2194 for (
unsigned i = 0; i != NumOpts; ++i) {
2202 for (
unsigned j = 0; j != NumOpts; ++j) {
2211 outs() <<
"= *unknown option value*\n";
2216#define PRINT_OPT_DIFF(T) \
2217 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
2218 size_t GlobalWidth) const { \
2219 printOptionName(O, GlobalWidth); \
2222 raw_string_ostream SS(Str); \
2225 outs() << "= " << Str; \
2226 size_t NumSpaces = \
2227 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
2228 outs().indent(NumSpaces) << " (default: "; \
2230 outs() << D.getValue(); \
2232 outs() << "*no default*"; \
2250 size_t GlobalWidth)
const {
2251 printOptionName(O, GlobalWidth);
2252 outs() <<
"= " << V;
2256 outs() <<
D.getValue();
2258 outs() <<
"*no default*";
2264 size_t GlobalWidth)
const {
2266 outs() <<
"= *cannot print option value*\n";
2274 const std::pair<const char *, Option *> *RHS) {
2275 return strcmp(
LHS->first,
RHS->first);
2279 const std::pair<const char *, SubCommand *> *RHS) {
2280 return strcmp(
LHS->first,
RHS->first);
2296 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
2300 if (!OptionSet.
insert(
I->second).second)
2304 std::pair<const char *, Option *>(
I->getKey().data(),
I->second));
2314 for (
auto *S : SubMap) {
2315 if (S->getName().empty())
2317 Subs.push_back(std::make_pair(S->getName().data(), S));
2326 const bool ShowHidden;
2328 StrOptionPairVector;
2330 StrSubCommandPairVector;
2332 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
2333 for (
const auto &Opt : Opts)
2337 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
2338 for (
const auto &S : Subs) {
2339 outs() <<
" " << S.first;
2340 if (!S.second->getDescription().empty()) {
2342 outs() <<
" - " << S.second->getDescription();
2349 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
2350 virtual ~HelpPrinter() =
default;
2353 void operator=(
bool Value) {
2364 auto &OptionsMap =
Sub->OptionsMap;
2365 auto &PositionalOpts =
Sub->PositionalOpts;
2366 auto &ConsumeAfterOpt =
Sub->ConsumeAfterOpt;
2368 StrOptionPairVector Opts;
2369 sortOpts(OptionsMap, Opts, ShowHidden);
2371 StrSubCommandPairVector Subs;
2380 outs() <<
" [subcommand]";
2381 outs() <<
" [options]";
2383 if (!
Sub->getDescription().empty()) {
2384 outs() <<
"SUBCOMMAND '" <<
Sub->getName()
2385 <<
"': " <<
Sub->getDescription() <<
"\n\n";
2391 for (
auto *Opt : PositionalOpts) {
2398 if (ConsumeAfterOpt)
2399 outs() <<
" " << ConsumeAfterOpt->HelpStr;
2403 size_t MaxSubLen = 0;
2404 for (
const auto &
Sub : Subs)
2405 MaxSubLen = std::max(MaxSubLen, strlen(
Sub.first));
2408 outs() <<
"SUBCOMMANDS:\n\n";
2409 printSubCommands(Subs, MaxSubLen);
2412 <<
" <subcommand> --help\" to get more help on a specific "
2419 size_t MaxArgLen = 0;
2420 for (
const auto &Opt : Opts)
2423 outs() <<
"OPTIONS:\n";
2424 printOptions(Opts, MaxArgLen);
2433class CategorizedHelpPrinter :
public HelpPrinter {
2435 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
2443 return (*A)->getName().compare((*B)->getName());
2447 using HelpPrinter::operator=;
2450 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
2451 std::vector<OptionCategory *> SortedCategories;
2460 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
2462 OptionCategoryCompare);
2467 for (
const auto &
I : Opts) {
2471 "Option has an unregistered category");
2472 CategorizedOptions[Cat].push_back(Opt);
2479 const auto &CategoryOptions = CategorizedOptions[Category];
2480 if (CategoryOptions.empty())
2494 for (
const Option *Opt : CategoryOptions)
2502class HelpPrinterWrapper {
2504 HelpPrinter &UncategorizedPrinter;
2505 CategorizedHelpPrinter &CategorizedPrinter;
2508 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
2509 CategorizedHelpPrinter &CategorizedPrinter)
2510 : UncategorizedPrinter(UncategorizedPrinter),
2511 CategorizedPrinter(CategorizedPrinter) {}
2514 void operator=(
bool Value);
2519#if defined(__GNUC__)
2522# if defined(__OPTIMIZE__)
2523# define LLVM_IS_DEBUG_BUILD 0
2525# define LLVM_IS_DEBUG_BUILD 1
2527#elif defined(_MSC_VER)
2532# define LLVM_IS_DEBUG_BUILD 1
2534# define LLVM_IS_DEBUG_BUILD 0
2538# define LLVM_IS_DEBUG_BUILD 0
2542class VersionPrinter {
2544 void print(std::vector<VersionPrinterTy> ExtraPrinters = {}) {
2546#ifdef PACKAGE_VENDOR
2547 OS << PACKAGE_VENDOR <<
" ";
2549 OS <<
"LLVM (http://llvm.org/):\n ";
2551 OS << PACKAGE_NAME <<
" version " << PACKAGE_VERSION <<
"\n ";
2552#if LLVM_IS_DEBUG_BUILD
2553 OS <<
"DEBUG build";
2555 OS <<
"Optimized build";
2558 OS <<
" with assertions";
2564 if (!ExtraPrinters.empty()) {
2565 for (
const auto &
I : ExtraPrinters)
2569 void operator=(
bool OptionWasSpecified);
2572struct CommandLineCommonOptions {
2575 HelpPrinter UncategorizedNormalPrinter{
false};
2576 HelpPrinter UncategorizedHiddenPrinter{
true};
2577 CategorizedHelpPrinter CategorizedNormalPrinter{
false};
2578 CategorizedHelpPrinter CategorizedHiddenPrinter{
true};
2581 HelpPrinterWrapper WrappedNormalPrinter{UncategorizedNormalPrinter,
2582 CategorizedNormalPrinter};
2583 HelpPrinterWrapper WrappedHiddenPrinter{UncategorizedHiddenPrinter,
2584 CategorizedHiddenPrinter};
2594 "Display list of available options (--help-list-hidden for more)"),
2603 cl::desc(
"Display list of all available options"),
2615 cl::desc(
"Display available options (--help-hidden for more)"),
2626 cl::desc(
"Display all available options"),
2635 cl::desc(
"Print non-default options after command line parsing"),
2642 "print-all-options",
2643 cl::desc(
"Print all option values after command line parsing"),
2651 std::vector<VersionPrinterTy> ExtraVersionPrinters;
2654 VersionPrinter VersionPrinterInstance;
2657 "version",
cl::desc(
"Display the version of this program"),
2683 return GeneralCategory;
2686void VersionPrinter::operator=(
bool OptionWasSpecified) {
2687 if (!OptionWasSpecified)
2699void HelpPrinterWrapper::operator=(
bool Value) {
2706 if (
GlobalParser->RegisteredOptionCategories.size() > 1) {
2711 CategorizedPrinter =
true;
2713 UncategorizedPrinter =
true;
2720void CommandLineParser::printOptionValues() {
2728 size_t MaxArgLen = 0;
2729 for (
const auto &Opt : Opts)
2732 for (
const auto &Opt : Opts)
2738 if (!
Hidden && !Categorized)
2740 else if (!
Hidden && Categorized)
2742 else if (
Hidden && !Categorized)
2754#if LLVM_IS_DEBUG_BUILD
2760#ifdef EXPENSIVE_CHECKS
2761 "+expensive-checks",
2763#if __has_feature(address_sanitizer)
2766#if __has_feature(dataflow_sanitizer)
2769#if __has_feature(hwaddress_sanitizer)
2772#if __has_feature(memory_sanitizer)
2775#if __has_feature(thread_sanitizer)
2778#if __has_feature(undefined_behavior_sanitizer)
2787#if LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG
2788 OS <<
"Build config: ";
2812 return Sub.OptionsMap;
2822 for (
auto &
I :
Sub.OptionsMap) {
2823 bool Unrelated =
true;
2824 for (
auto &Cat :
I.second->Categories) {
2825 if (Cat == &Category || Cat == &
CommonOptions->GenericCategory)
2836 for (
auto &
I :
Sub.OptionsMap) {
2837 bool Unrelated =
true;
2838 for (
auto &Cat :
I.second->Categories) {
2854 const char *Overview) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling ...
static StringRef OptionPrefix
static bool RequiresValue(const Option *O)
static int SubNameCompare(const std::pair< const char *, SubCommand * > *LHS, const std::pair< const char *, SubCommand * > *RHS)
static size_t argPlusPrefixesSize(StringRef ArgName, size_t Pad=DefaultPad)
static bool isPrefixedOrGrouping(const Option *O)
static bool shouldPrintOption(StringRef Name, StringRef Description, const Option &O)
static ManagedStatic< SubCommand > AllSubCommands
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 bool parseDouble(Option &O, StringRef Arg, double &Value)
static bool parseBool(Option &O, StringRef ArgName, StringRef Arg, T &Value)
static const size_t DefaultPad
static StringRef EmptyOption
static bool hasUTF8ByteOrderMark(ArrayRef< char > S)
static ManagedStatic< CommandLineParser > GlobalParser
static void ExpandBasePaths(StringRef BasePath, StringSaver &Saver, const char *&Arg)
static SmallString< 8 > argPrefix(StringRef ArgName, size_t Pad=DefaultPad)
static StringRef ArgHelpPrefix
void opt_unsigned_anchor()
static bool isWindowsSpecialCharInCommandName(char C)
static Option * getOptionPred(StringRef Name, size_t &Length, bool(*Pred)(const Option *), const StringMap< Option * > &OptionsMap)
static StringRef getValueStr(const Option &O, StringRef DefaultMsg)
static size_t getOptionPrefixesSize()
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 bool isQuote(char C)
static ManagedStatic< CommandLineCommonOptions > CommonOptions
static void initCommonOptions()
static void tokenizeWindowsCommandLineImpl(StringRef Src, StringSaver &Saver, function_ref< void(StringRef)> AddToken, bool AlwaysCopy, function_ref< void()> MarkEOL, bool InitialCommandName)
static bool isWhitespace(char C)
static LLVM_REQUIRE_CONSTANT_INITIALIZATION ManagedStatic< SubCommand > TopLevelSubCommand
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 StringRef ArgPrefixLong
static void sortSubCommands(const SmallPtrSetImpl< SubCommand * > &SubMap, SmallVectorImpl< std::pair< const char *, SubCommand * > > &Subs)
#define PRINT_OPT_DIFF(T)
static bool isWhitespaceOrNull(char C)
static const size_t MaxOptWidth
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...
static bool EatsUnboundedNumberOfValues(const Option *O)
static int OptNameCompare(const std::pair< const char *, Option * > *LHS, const std::pair< const char *, Option * > *RHS)
static void sortOpts(StringMap< Option * > &OptMap, SmallVectorImpl< std::pair< const char *, Option * > > &Opts, bool ShowHidden)
static StringRef ArgPrefix
static bool isWindowsSpecialChar(char C)
static bool isGrouping(const Option *O)
#define LLVM_REQUIRE_CONSTANT_INITIALIZATION
LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that they are constant initial...
#define LLVM_EXPORT_TEMPLATE
static void Help(ArrayRef< StringRef > CPUNames, ArrayRef< SubtargetFeatureKV > FeatTable)
Display help for feature and mcpu choices.
Provides a library for accessing information about this process and other processes on the operating ...
This file defines the SmallPtrSet class.
This file defines the SmallString class.
Defines the virtual file system interface vfs::FileSystem.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
size_t size() const
size - Get the array size.
Allocate memory in an ever growing pool, as if by bump-pointer.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
This interface provides simple read-only access to a block of memory, and provides simple methods for...
size_t getBufferSize() const
const char * getBufferEnd() const
const char * getBufferStart() const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void assign(StringRef RHS)
Assign from a StringRef.
void append(StringRef RHS)
Append from a StringRef.
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
LLVM_ABI unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static constexpr size_t npos
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
BumpPtrAllocator & getAllocator() const
StringRef save(const char *S)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
Contains options that control response file expansion.
LLVM_ABI bool findConfigFile(StringRef FileName, SmallVectorImpl< char > &FilePath)
Looks for the specified configuration file.
LLVM_ABI ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T)
LLVM_ABI Error expandResponseFiles(SmallVectorImpl< const char * > &Argv)
Expands constructs "@file" in the provided array of arguments recursively.
LLVM_ABI Error readConfigFile(StringRef CfgFile, SmallVectorImpl< const char * > &Argv)
Reads command line options from the given configuration file.
StringRef getDescription() const
StringRef getName() const
SmallPtrSet< SubCommand *, 1 > Subs
int getNumOccurrences() const
enum ValueExpected getValueExpectedFlag() const
void addCategory(OptionCategory &C)
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
void setMiscFlag(enum MiscFlags M)
enum FormattingFlags getFormattingFlag() const
virtual void printOptionInfo(size_t GlobalWidth) const =0
enum NumOccurrencesFlag getNumOccurrencesFlag() const
SmallVector< OptionCategory *, 1 > Categories
bool error(const Twine &Message, StringRef ArgName=StringRef(), raw_ostream &Errs=llvm::errs())
void setArgStr(StringRef S)
bool isDefaultOption() const
unsigned getMiscFlags() const
virtual void setDefault()=0
virtual void printOptionValue(size_t GlobalWidth, bool Force) const =0
static void printEnumValHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
unsigned getNumAdditionalVals() const
void removeArgument()
Unregisters this option from the CommandLine system.
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
virtual size_t getOptionWidth() const =0
StringRef getName() const
SmallVector< Option *, 4 > SinkOpts
static LLVM_ABI SubCommand & getTopLevel()
LLVM_ABI void unregisterSubCommand()
static LLVM_ABI SubCommand & getAll()
LLVM_ABI void registerSubCommand()
SmallVector< Option *, 4 > PositionalOpts
StringMap< Option * > OptionsMap
void printOptionInfo(const Option &O, size_t GlobalWidth) const
virtual StringRef getValueName() const
void printOptionNoValue(const Option &O, size_t GlobalWidth) const
size_t getOptionWidth(const Option &O) const
void printOptionName(const Option &O, size_t GlobalWidth) const
virtual size_t getOptionWidth(const Option &O) const
virtual StringRef getDescription(unsigned N) const =0
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
virtual unsigned getNumOptions() const =0
virtual StringRef getOption(unsigned N) const =0
void printOptionDiff(const Option &O, const AnyOptionValue &V, const AnyOptionValue &Default, size_t GlobalWidth) const
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
unsigned findOption(StringRef Name)
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
static LLVM_ABI std::optional< std::string > GetEnv(StringRef name)
virtual llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const =0
Get the working directory of this file system.
virtual std::error_code makeAbsolute(SmallVectorImpl< char > &Path) const
Make Path an absolute path.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false, bool IsText=true)
This is a convenience method that opens a file, gets its content and then closes the file.
virtual llvm::ErrorOr< Status > status(const Twine &Path)=0
Get the status of the entry at Path, if one exists.
The result of a status operation.
LLVM_ABI bool equivalent(const Status &Other) const
LLVM_C_ABI void LLVMParseCommandLineOptions(int argc, const char *const *argv, const char *Overview)
This function parses the given arguments using the LLVM command line parser.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
constexpr size_t NameSize
std::function< void(raw_ostream &)> VersionPrinterTy
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
LLVM_ABI void PrintVersionMessage()
Utility function for printing version number.
LLVM_ABI bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv)
A convenience helper which supports the typical use case of expansion function call.
LLVM_ABI 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.
LLVM_ABI OptionCategory & getGeneralCategory()
LLVM_ABI void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
LLVM_ABI void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Override the default (LLV...
LLVM_ABI void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
LLVM_ABI StringMap< Option * > & getRegisteredOptions(SubCommand &Sub=SubCommand::getTopLevel())
Use this to get a StringMap to all registered named options (e.g.
LLVM_ABI void ResetCommandLineParser()
Reset the command line parser back to its initial state.
LLVM_ABI bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
LLVM_ABI void PrintOptionValues()
LLVM_ABI iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
LLVM_ABI void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
LLVM_ABI void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
LLVM_ABI void printBuildConfig(raw_ostream &OS)
Prints the compiler build configuration.
LLVM_ABI bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
LLVM_ABI bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, SmallVectorImpl< const char * > &NewArgv)
A convenience helper which concatenates the options specified by the environment variable EnvVar and ...
initializer< Ty > init(const Ty &Val)
LLVM_ABI ArrayRef< StringRef > getCompilerBuildConfig()
An array of optional enabled settings in the LLVM build configuration, which may be of interest to co...
LocationClass< Ty > location(Ty &L)
LLVM_ABI void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=SubCommand::getTopLevel())
Mark all options not part of this category as cl::ReallyHidden.
LLVM_ABI void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Add an extra printer to u...
LLVM_ABI 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...
LLVM_ABI 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.
LLVM_ABI void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI bool has_parent_path(const Twine &path, Style style=Style::native)
Has parent path?
LLVM_ABI bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
void initWithColorOptions()
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
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.
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
LLVM_ABI 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 initDebugCounterOptions()
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
@ no_such_file_or_directory
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
void initSignalsOptions()
void initTypeSizeOptions()
void initStatisticOptions()
LLVM_ABI raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void initRandomSeedOptions()
@ Sub
Subtraction of integers.
void initGraphWriterOptions()
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
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...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
const char * toString(DWARFSectionKind Kind)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
@ Default
The result values are uniform if and only if all operands are uniform.