31#include "llvm/Config/config.h"
52#define DEBUG_TYPE "commandline"
73#if !(defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS) && defined(_MSC_VER))
90void GenericOptionValue::anchor() {}
91void OptionValue<boolOrDefault>::anchor() {}
92void OptionValue<std::string>::anchor() {}
93void Option::anchor() {}
128 size_t Len = ArgName.
size();
136 for (
size_t I = 0;
I < Pad; ++
I) {
165 OS <<
argPrefix(Arg.ArgName, Arg.Pad) << Arg.ArgName;
169class CommandLineParser {
173 std::string ProgramName;
177 std::vector<StringRef> MoreHelp;
192 bool LongOptionsUseDoubleDash =
false);
195 if (Opt.
Subs.empty()) {
200 for (
auto *SC : RegisteredSubCommands)
205 for (
auto *SC : Opt.
Subs) {
207 "SubCommand::getAll() should not be used with other subcommands");
216 errs() << ProgramName <<
": CommandLine Error: Option '" << Name
217 <<
"' registered more than once!\n";
224 Opt, [&](
SubCommand &SC) { addLiteralOption(Opt, &SC, Name); });
228 bool HadErrors =
false;
229 if (O->hasArgStr()) {
232 errs() << ProgramName <<
": CommandLine Error: Option '" << O->ArgStr
233 <<
"' registered more than once!\n";
243 O->error(
"Cannot specify more than one option with cl::ConsumeAfter!");
257 void addOption(
Option *O) {
258 forEachSubCommand(*O, [&](
SubCommand &SC) { addOption(O, &SC); });
263 O->getExtraOptionNames(OptionNames);
268 for (
auto Name : OptionNames) {
269 auto I =
Sub.OptionsMap.find(Name);
272 if (
I !=
Sub.OptionsMap.end() &&
I->second == O)
273 Sub.OptionsMap.erase(
I);
277 for (
auto *Opt =
Sub.PositionalOpts.begin();
278 Opt !=
Sub.PositionalOpts.end(); ++Opt) {
280 Sub.PositionalOpts.erase(Opt);
284 else if (O ==
Sub.ConsumeAfterOpt)
285 Sub.ConsumeAfterOpt =
nullptr;
288 void removeOption(
Option *O) {
289 forEachSubCommand(*O, [&](
SubCommand &SC) { removeOption(O, &SC); });
293 return (!
Sub.OptionsMap.empty() || !
Sub.PositionalOpts.empty() ||
294 nullptr !=
Sub.ConsumeAfterOpt);
297 bool hasOptions()
const {
298 for (
const auto *S : RegisteredSubCommands) {
305 bool hasNamedSubCommands()
const {
306 for (
const auto *S : RegisteredSubCommands)
307 if (!S->getName().empty())
312 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
316 if (!
Sub.OptionsMap.insert(std::make_pair(NewName, O)).second) {
317 errs() << ProgramName <<
": CommandLine Error: Option '" << O->ArgStr
318 <<
"' registered more than once!\n";
321 Sub.OptionsMap.erase(O->ArgStr);
325 forEachSubCommand(*O,
326 [&](
SubCommand &SC) { updateArgStr(O, NewName, &SC); });
329 void printOptionValues();
336 "Duplicate option categories");
344 return (!
sub->getName().empty()) &&
345 (
Sub->getName() ==
sub->getName());
347 "Duplicate subcommands");
353 "SubCommand::getAll() should not be registered");
356 if (O->isPositional() || O->isConsumeAfter() || O->hasArgStr())
359 addLiteralOption(*O,
sub,
E.first);
370 RegisteredSubCommands.
end());
374 ActiveSubCommand =
nullptr;
379 RegisteredOptionCategories.
clear();
382 RegisteredSubCommands.
clear();
394 bool LongOptionsUseDoubleDash,
bool HaveDoubleDash) {
396 if (Opt && LongOptionsUseDoubleDash && !HaveDoubleDash && !
isGrouping(Opt))
412 return *GlobalParser;
415template <
typename T, T TrueVal, T FalseVal>
419 if (!Arg.
data() || Arg ==
"true" || Arg ==
"1") {
424 if (Arg ==
"false" || Arg ==
"0") {
428 return O.error(
"'" + Arg +
429 "' is invalid value for boolean argument! Try 0 or 1");
441 : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
443 FullyInitialized(
false), Position(0) {
449 FullyInitialized =
true;
455 if (FullyInitialized)
479void OptionCategory::registerCategory() {
490 return *TopLevelSubCommand;
496 return *AllSubCommands;
514SubCommand::operator
bool()
const {
532 size_t EqualPos = Arg.
find(
'=');
537 return Sub.OptionsMap.lookup(Arg);
543 auto I =
Sub.OptionsMap.find(Arg.
substr(0, EqualPos));
544 if (
I ==
Sub.OptionsMap.end())
552 Arg = Arg.
substr(0, EqualPos);
557 std::string &NearestString) {
562 for (
auto *S : RegisteredSubCommands) {
564 "SubCommand::getAll() is not expected in RegisteredSubCommands");
565 if (S->getName().empty())
568 if (S->getName() == Name)
571 if (!NearestMatch && S->getName().edit_distance(Name) < 2)
576 NearestString = NearestMatch->
getName();
587 std::string &NearestString) {
593 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
599 unsigned BestDistance = 0;
600 for (
const auto &[
_, O] : OptionsMap) {
606 O->getExtraOptionNames(OptionNames);
612 for (
const auto &Name : OptionNames) {
614 Flag,
true, BestDistance);
615 if (!Best || Distance < BestDistance) {
617 BestDistance = Distance;
618 if (
RHS.empty() || !PermitValue)
619 NearestString = std::string(Name);
621 NearestString = (
Twine(Name) +
"=" +
RHS).str();
644 Val = Val.
substr(Pos + 1);
660 const char *
const *argv,
int &i) {
668 return Handler->
error(
"requires a value!");
670 assert(argv &&
"null check");
698 bool (*Pred)(
const Option *),
700 auto OMI = OptionsMap.
find(Name);
701 if (OMI != OptionsMap.
end() && !Pred(OMI->second))
702 OMI = OptionsMap.
end();
707 while (OMI == OptionsMap.
end() && Name.size() > 1) {
708 Name = Name.drop_back();
709 OMI = OptionsMap.
find(Name);
710 if (OMI != OptionsMap.
end() && !Pred(OMI->second))
711 OMI = OptionsMap.
end();
714 if (OMI != OptionsMap.
end() && Pred(OMI->second)) {
741 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
751 if (MaybeValue[0] ==
'=') {
761 ErrorParsing |= PGOpt->
error(
"may not occur within a group!");
790 return C ==
' ' ||
C ==
'\t' ||
C ==
'\r' ||
C ==
'\n';
797static bool isQuote(
char C) {
return C ==
'\"' ||
C ==
'\''; }
803 bool InToken =
false;
804 for (
size_t I = 0, E = Src.size();
I != E; ++
I) {
809 if (MarkEOLs && Src[
I] ==
'\n')
821 if (
I + 1 < E &&
C ==
'\\') {
830 while (
I != E && Src[
I] !=
C) {
832 if (Src[
I] ==
'\\' &&
I + 1 != E)
846 if (MarkEOLs &&
C ==
'\n')
880 size_t E = Src.size();
881 int BackslashCount = 0;
886 }
while (
I !=
E && Src[
I] ==
'\\');
888 bool FollowedByDoubleQuote = (
I !=
E && Src[
I] ==
'"');
889 if (FollowedByDoubleQuote) {
890 Token.
append(BackslashCount / 2,
'\\');
891 if (BackslashCount % 2 == 0)
896 Token.
append(BackslashCount,
'\\');
914 bool AlwaysCopy,
function_ref<
void()> MarkEOL,
bool InitialCommandName) {
923 bool CommandName = InitialCommandName;
926 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
928 for (
size_t I = 0,
E = Src.size();
I <
E; ++
I) {
931 assert(Token.
empty() &&
"token should be empty in initial state");
953 AddToken(AlwaysCopy ? Saver.
save(NormalChars) : NormalChars);
954 if (
I <
E && Src[
I] ==
'\n') {
956 CommandName = InitialCommandName;
960 }
else if (Src[
I] ==
'\"') {
961 Token += NormalChars;
963 }
else if (Src[
I] ==
'\\') {
964 assert(!CommandName &&
"or else we'd have treated it as a normal char");
965 Token += NormalChars;
979 AddToken(Saver.
save(Token.
str()));
981 if (Src[
I] ==
'\n') {
982 CommandName = InitialCommandName;
988 }
else if (Src[
I] ==
'\"') {
990 }
else if (Src[
I] ==
'\\' && !CommandName) {
998 if (Src[
I] ==
'\"') {
999 if (
I < (
E - 1) && Src[
I + 1] ==
'"') {
1008 }
else if (Src[
I] ==
'\\' && !CommandName) {
1018 AddToken(Saver.
save(Token.
str()));
1025 auto OnEOL = [&]() {
1030 true, OnEOL,
false);
1036 auto OnEOL = []() {};
1045 auto OnEOL = [&]() {
1056 for (
const char *Cur = Source.begin(); Cur != Source.end();) {
1065 while (Cur != Source.end() && *Cur !=
'\n')
1070 const char *Start = Cur;
1071 for (
const char *End = Source.end(); Cur != End; ++Cur) {
1073 if (Cur + 1 != End) {
1076 (*Cur ==
'\r' && (Cur + 1 != End) && Cur[1] ==
'\n')) {
1077 Line.append(Start, Cur - 1);
1083 }
else if (*Cur ==
'\n')
1087 Line.append(Start, Cur);
1095 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
1109 TokenPos = ArgString.
find(Token, StartPos)) {
1113 if (ResponseFile.
empty())
1117 ResponseFile.
append(BasePath);
1118 StartPos = TokenPos + Token.
size();
1121 if (!ResponseFile.
empty()) {
1124 if (!Remaining.
empty())
1131Error ExpansionContext::expandResponseFile(
1132 StringRef FName, SmallVectorImpl<const char *> &NewArgv) {
1134 llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> MemBufOrErr =
1135 FS->getBufferForFile(FName);
1139 "': " +
EC.message());
1141 MemoryBuffer &MemBuf = *MemBufOrErr.
get();
1146 std::string UTF8Buf;
1150 "Could not convert UTF16 to UTF8");
1151 Str = StringRef(UTF8Buf);
1157 Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
1160 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
1165 if (!RelativeNames && !InConfigFile)
1169 for (
const char *&Arg : NewArgv) {
1179 StringRef ArgStr(Arg);
1181 bool ConfigInclusion =
false;
1182 if (ArgStr.consume_front(
"@")) {
1186 }
else if (ArgStr.consume_front(
"--config=")) {
1188 ConfigInclusion =
true;
1194 SmallString<128> ResponseFile;
1197 SmallString<128> FilePath;
1200 std::make_error_code(std::errc::no_such_file_or_directory),
1201 "cannot not find configuration file: " + FileName);
1202 ResponseFile.
append(FilePath);
1204 ResponseFile.
append(BasePath);
1207 Arg = Saver.save(ResponseFile.
str()).
data();
1216 struct ResponseFileRecord {
1231 for (
unsigned I = 0;
I != Argv.
size();) {
1232 while (
I == FileStack.
back().End) {
1238 const char *Arg = Argv[
I];
1240 if (Arg ==
nullptr) {
1245 if (Arg[0] !=
'@') {
1250 const char *FName = Arg + 1;
1255 if (CurrentDir.empty()) {
1256 if (
auto CWD = FS->getCurrentWorkingDirectory()) {
1260 CWD.getError(),
Twine(
"cannot get absolute path for: ") + FName);
1263 CurrDir = CurrentDir;
1266 FName = CurrDir.
c_str();
1270 if (!Res || !Res->exists()) {
1271 std::error_code EC = Res.
getError();
1272 if (!InConfigFile) {
1283 "': " + EC.message());
1288 [FileStatus,
this](
const ResponseFileRecord &RFile) ->
ErrorOr<bool> {
1300 R.getError(),
Twine(
"recursive expansion of: '") +
F.File +
"'");
1303 Twine(
"cannot open file: ") +
F.File);
1310 if (
Error Err = expandResponseFile(FName, ExpandedArgv))
1313 for (ResponseFileRecord &
Record : FileStack) {
1344 Tokenize(*EnvValue, Saver, NewArgv,
false);
1347 NewArgv.
append(Argv + 1, Argv + Argc);
1368 : Saver(
A), Tokenizer(
T), FS(FS ? FS :
vfs::getRealFileSystem().
get()) {}
1374 auto Status = FS->status(Path);
1382 CfgFilePath = FileName;
1385 if (!FileExists(CfgFilePath))
1392 for (
const StringRef &Dir : SearchDirs) {
1398 if (FileExists(CfgFilePath)) {
1412 if (std::error_code EC = FS->makeAbsolute(AbsPath))
1414 EC,
Twine(
"cannot get absolute path for " + CfgFile));
1415 CfgFile = AbsPath.
str();
1417 InConfigFile =
true;
1418 RelativeNames =
true;
1419 if (
Error Err = expandResponseFile(CfgFile, Argv))
1428 bool LongOptionsUseDoubleDash) {
1437 if (std::optional<std::string> EnvValue =
1443 for (
int I = 1;
I < argc; ++
I)
1445 int NewArgc =
static_cast<int>(NewArgv.
size());
1449 NewArgc, &NewArgv[0], Overview, Errs, VFS, LongOptionsUseDoubleDash);
1453void CommandLineParser::ResetAllOptionOccurrences() {
1457 for (
auto *SC : RegisteredSubCommands) {
1461 Opts.
reserve(SC->OptionsMap.size());
1462 for (
auto &O : SC->OptionsMap)
1466 for (
Option *O : SC->PositionalOpts)
1468 if (SC->ConsumeAfterOpt)
1469 SC->ConsumeAfterOpt->reset();
1473bool CommandLineParser::ParseCommandLineOptions(
1476 assert(hasOptions() &&
"No options specified!");
1478 ProgramOverview = Overview;
1479 bool IgnoreErrors = Errs;
1484 bool ErrorParsing =
false;
1495 if (
Error Err = ECtx.expandResponseFiles(newArgv)) {
1496 *Errs <<
toString(std::move(Err)) <<
'\n';
1500 argc =
static_cast<int>(newArgv.size());
1506 unsigned NumPositionalRequired = 0;
1509 bool HasUnlimitedPositionals =
false;
1513 std::string NearestSubCommandString;
1514 bool MaybeNamedSubCommand =
1515 argc >= 2 && argv[FirstArg][0] !=
'-' && hasNamedSubCommands();
1516 if (MaybeNamedSubCommand) {
1520 LookupSubCommand(
StringRef(argv[FirstArg]), NearestSubCommandString);
1526 assert(ChosenSubCommand);
1529 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1531 if (ConsumeAfterOpt) {
1532 assert(PositionalOpts.size() > 0 &&
1533 "Cannot specify cl::ConsumeAfter without a positional argument!");
1535 if (!PositionalOpts.empty()) {
1538 bool UnboundedFound =
false;
1539 for (
size_t i = 0, e = PositionalOpts.size(); i != e; ++i) {
1540 Option *Opt = PositionalOpts[i];
1542 ++NumPositionalRequired;
1543 else if (ConsumeAfterOpt) {
1546 if (PositionalOpts.size() > 1) {
1548 Opt->
error(
"error - this positional option will never be matched, "
1549 "because it does not Require a value, and a "
1550 "cl::ConsumeAfter option is active!");
1551 ErrorParsing =
true;
1553 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1559 Opt->
error(
"error - option can never match, because "
1560 "another positional argument will match an "
1561 "unbounded number of values, and this option"
1562 " does not require a value!");
1563 *Errs << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr
1564 <<
"' is all messed up!\n";
1565 *Errs << PositionalOpts.size();
1566 ErrorParsing =
true;
1570 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1581 Option *ActivePositionalArg =
nullptr;
1584 bool DashDashFound =
false;
1585 for (
int i = FirstArg; i < argc; ++i) {
1586 Option *Handler =
nullptr;
1587 std::string NearestHandlerString;
1589 StringRef ArgName =
"";
1590 bool HaveDoubleDash =
false;
1596 if (argv[i][0] !=
'-' || argv[i][1] == 0 || DashDashFound) {
1598 if (ActivePositionalArg) {
1603 if (!PositionalOpts.empty()) {
1604 PositionalVals.
push_back(std::make_pair(StringRef(argv[i]), i));
1609 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
1610 for (++i; i < argc; ++i)
1611 PositionalVals.
push_back(std::make_pair(StringRef(argv[i]), i));
1618 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
1620 DashDashFound =
true;
1622 }
else if (ActivePositionalArg &&
1627 ArgName = StringRef(argv[i] + 1);
1630 HaveDoubleDash =
true;
1632 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1633 LongOptionsUseDoubleDash, HaveDoubleDash);
1639 ArgName = StringRef(argv[i] + 1);
1642 HaveDoubleDash =
true;
1644 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1645 LongOptionsUseDoubleDash, HaveDoubleDash);
1652 LongOptionsUseDoubleDash, HaveDoubleDash);
1655 if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
1666 auto ReportUnknownArgument = [&](
bool IsArg,
1667 StringRef NearestArgumentName) {
1668 *Errs << ProgramName <<
": Unknown "
1669 << (IsArg ?
"command line argument" :
"subcommand") <<
" '"
1670 << argv[i] <<
"'. Try: '" << argv[0] <<
" --help'\n";
1672 if (NearestArgumentName.empty())
1675 *Errs << ProgramName <<
": Did you mean '";
1677 *Errs << PrintArg(NearestArgumentName, 0);
1679 *Errs << NearestArgumentName;
1683 if (i > 1 || !MaybeNamedSubCommand)
1684 ReportUnknownArgument(
true, NearestHandlerString);
1686 ReportUnknownArgument(
false, NearestSubCommandString);
1688 ErrorParsing =
true;
1696 Handler->
error(
"This argument does not take a value.\n"
1697 "\tInstead, it consumes any positional arguments until "
1698 "the next recognized option.", *Errs);
1699 ErrorParsing =
true;
1701 ActivePositionalArg = Handler;
1708 if (NumPositionalRequired > PositionalVals.
size()) {
1709 *Errs << ProgramName
1710 <<
": Not enough positional command line arguments specified!\n"
1711 <<
"Must specify at least " << NumPositionalRequired
1712 <<
" positional argument" << (NumPositionalRequired > 1 ?
"s" :
"")
1713 <<
": See: " << argv[0] <<
" --help\n";
1715 ErrorParsing =
true;
1716 }
else if (!HasUnlimitedPositionals &&
1717 PositionalVals.
size() > PositionalOpts.size()) {
1718 *Errs << ProgramName <<
": Too many positional arguments specified!\n"
1719 <<
"Can specify at most " << PositionalOpts.size()
1720 <<
" positional arguments: See: " << argv[0] <<
" --help\n";
1721 ErrorParsing =
true;
1723 }
else if (!ConsumeAfterOpt) {
1725 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1726 for (
Option *Opt : PositionalOpts) {
1729 PositionalVals[ValNo].second);
1731 --NumPositionalRequired;
1739 while (NumVals - ValNo > NumPositionalRequired && !
Done) {
1747 PositionalVals[ValNo].second);
1752 "positional argument processing!");
1757 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1759 for (
Option *Opt : PositionalOpts)
1762 Opt, PositionalVals[ValNo].first, PositionalVals[ValNo].second);
1771 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1773 PositionalVals[ValNo].first,
1774 PositionalVals[ValNo].second);
1780 for (; ValNo != PositionalVals.
size(); ++ValNo)
1783 PositionalVals[ValNo].second);
1787 for (
const auto &Opt : OptionsMap) {
1792 Opt.second->
error(
"must be specified at least once!");
1793 ErrorParsing =
true;
1805 for (
int i = 0; i < argc; ++i)
dbgs() << argv[i] <<
' ';
1826 if (!ArgName.
data())
1828 if (ArgName.
empty())
1831 Errs <<
globalParser().ProgramName <<
": for the " << PrintArg(ArgName, 0);
1833 Errs <<
" option: " << Message <<
"\n";
1839 return handleOccurrence(pos, ArgName, Value);
1846 if (O.ValueStr.empty())
1861 size_t FirstLineIndentedBy) {
1862 assert(Indent >= FirstLineIndentedBy);
1863 std::pair<StringRef, StringRef> Split =
HelpStr.split(
'\n');
1866 while (!Split.second.empty()) {
1867 Split = Split.second.split(
'\n');
1868 outs().
indent(Indent) << Split.first <<
"\n";
1873 size_t FirstLineIndentedBy) {
1875 assert(BaseIndent >= FirstLineIndentedBy);
1876 std::pair<StringRef, StringRef> Split =
HelpStr.split(
'\n');
1877 outs().
indent(BaseIndent - FirstLineIndentedBy)
1879 while (!Split.second.empty()) {
1880 Split = Split.second.split(
'\n');
1881 outs().
indent(BaseIndent + ValHelpPrefix.
size()) << Split.first <<
"\n";
1886void alias::printOptionInfo(
size_t GlobalWidth)
const {
1902 if (!ValName.empty()) {
1903 size_t FormattingLen = 3;
1916 size_t GlobalWidth)
const {
1917 outs() << PrintArg(O.ArgStr);
1920 if (!ValName.empty()) {
1926 outs() << (O.ArgStr.size() == 1 ?
" <" :
"=<") <<
getValueStr(O, ValName)
1935 size_t GlobalWidth)
const {
1936 outs() << PrintArg(O.ArgStr);
1937 outs().
indent(GlobalWidth - O.ArgStr.size());
1957template <
typename FixedOrScalableQuantityT>
1960 FixedOrScalableQuantityT &
Value) {
1961 using ScalarTy =
typename FixedOrScalableQuantityT::ScalarTy;
1967 Value = FixedOrScalableQuantityT::getFixed(MinValue);
1973 return O.error(
"'" + Arg +
"' value invalid for " + ValueKind +
1976 Remainder = Remainder.
ltrim();
1978 return O.error(
"'" + Arg +
"' value invalid for " + ValueKind +
1981 Remainder = Remainder.
ltrim();
1983 return O.error(
"'" + Arg +
"' value invalid for " + ValueKind +
1986 Value = FixedOrScalableQuantityT::getScalable(MinValue);
1995 return O.error(
"'" + Arg +
"' value invalid for integer argument!");
2004 return O.error(
"'" + Arg +
"' value invalid for long argument!");
2013 return O.error(
"'" + Arg +
"' value invalid for llong argument!");
2023 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
2030 unsigned long &
Value) {
2033 return O.error(
"'" + Arg +
"' value invalid for ulong argument!");
2041 unsigned long long &
Value) {
2044 return O.error(
"'" + Arg +
"' value invalid for ullong argument!");
2051 ElementCount &
Value) {
2060 return O.error(
"'" + Arg +
"' value invalid for floating point argument!");
2086 for (
unsigned i = 0; i != e; ++i) {
2102 return O.getValueExpectedFlag() !=
ValueOptional || !Name.empty() ||
2103 !Description.
empty();
2108 if (O.hasArgStr()) {
2120 size_t BaseSize = 0;
2131 size_t GlobalWidth)
const {
2132 if (O.hasArgStr()) {
2138 outs() << PrintArg(O.ArgStr);
2157 if (OptionName.
empty()) {
2162 if (!Description.
empty())
2168 if (!O.HelpStr.empty())
2169 outs() <<
" " << O.HelpStr <<
'\n';
2186 outs() <<
" " << PrintArg(O.ArgStr);
2187 outs().
indent(GlobalWidth - O.ArgStr.size());
2190 for (
unsigned i = 0; i != NumOpts; ++i) {
2198 for (
unsigned j = 0; j != NumOpts; ++j) {
2207 outs() <<
"= *unknown option value*\n";
2215 return OS << static_cast<int>(V);
2220#define PRINT_OPT_DIFF(T) \
2221 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
2222 size_t GlobalWidth) const { \
2223 printOptionName(O, GlobalWidth); \
2226 raw_string_ostream SS(Str); \
2229 outs() << "= " << Str; \
2230 size_t NumSpaces = \
2231 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
2232 outs().indent(NumSpaces) << " (default: "; \
2234 outs() << D.getValue(); \
2236 outs() << "*no default*"; \
2255 size_t GlobalWidth)
const {
2256 printOptionName(O, GlobalWidth);
2257 outs() <<
"= " << V;
2261 outs() <<
D.getValue();
2263 outs() <<
"*no default*";
2268 const Option &O, std::optional<StringRef> V,
2269 const OptionValue<std::optional<std::string>> &
D,
2270 size_t GlobalWidth)
const {
2271 printOptionName(O, GlobalWidth);
2272 outs() <<
"= " <<
V;
2273 size_t VSize =
V.has_value() ?
V.value().size() : 0;
2276 if (
D.hasValue() &&
D.getValue().has_value())
2277 outs() <<
D.getValue();
2279 outs() <<
"*no value*";
2285 size_t GlobalWidth)
const {
2287 outs() <<
"= *cannot print option value*\n";
2295 const std::pair<const char *, Option *> *
RHS) {
2296 return strcmp(
LHS->first,
RHS->first);
2300 const std::pair<const char *, SubCommand *> *
RHS) {
2301 return strcmp(
LHS->first,
RHS->first);
2310 for (
auto I = OptMap.
begin(),
E = OptMap.
end();
I !=
E; ++
I) {
2316 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
2320 if (!OptionSet.
insert(
I->second).second)
2324 std::pair<const char *, Option *>(
I->first.data(),
I->second));
2334 for (
auto *S : SubMap) {
2335 if (S->getName().empty())
2337 Subs.push_back(std::make_pair(S->getName().data(), S));
2346 const bool ShowHidden;
2347 using StrOptionPairVector =
2349 using StrSubCommandPairVector =
2352 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
2353 for (
const auto &Opt : Opts)
2357 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
2358 for (
const auto &S : Subs) {
2359 outs() <<
" " << S.first;
2360 if (!S.second->getDescription().empty()) {
2362 outs() <<
" - " << S.second->getDescription();
2369 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
2370 virtual ~HelpPrinter() =
default;
2373 void operator=(
bool Value) {
2384 auto &OptionsMap =
Sub->OptionsMap;
2385 auto &PositionalOpts =
Sub->PositionalOpts;
2386 auto &ConsumeAfterOpt =
Sub->ConsumeAfterOpt;
2388 StrOptionPairVector Opts;
2389 sortOpts(OptionsMap, Opts, ShowHidden);
2391 StrSubCommandPairVector Subs;
2400 outs() <<
" [subcommand]";
2401 outs() <<
" [options]";
2403 if (!
Sub->getDescription().empty()) {
2404 outs() <<
"SUBCOMMAND '" <<
Sub->getName()
2405 <<
"': " <<
Sub->getDescription() <<
"\n\n";
2411 for (
auto *Opt : PositionalOpts) {
2418 if (ConsumeAfterOpt)
2419 outs() <<
" " << ConsumeAfterOpt->HelpStr;
2423 size_t MaxSubLen = 0;
2424 for (
const auto &
Sub : Subs)
2425 MaxSubLen = std::max(MaxSubLen, strlen(
Sub.first));
2428 outs() <<
"SUBCOMMANDS:\n\n";
2429 printSubCommands(Subs, MaxSubLen);
2432 <<
" <subcommand> --help\" to get more help on a specific "
2439 size_t MaxArgLen = 0;
2440 for (
const auto &Opt : Opts)
2443 outs() <<
"OPTIONS:\n";
2444 printOptions(Opts, MaxArgLen);
2453class CategorizedHelpPrinter :
public HelpPrinter {
2455 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
2461 static int OptionCategoryCompare(OptionCategory *
const *
A,
2462 OptionCategory *
const *
B) {
2463 return (*A)->getName().compare((*B)->getName());
2467 using HelpPrinter::operator=;
2470 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
2471 std::vector<OptionCategory *> SortedCategories;
2472 DenseMap<OptionCategory *, std::vector<Option *>> CategorizedOptions;
2480 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
2482 OptionCategoryCompare);
2487 for (
const auto &
I : Opts) {
2488 Option *Opt =
I.second;
2489 for (OptionCategory *Cat : Opt->
Categories) {
2491 "Option has an unregistered category");
2492 CategorizedOptions[Cat].push_back(Opt);
2497 for (OptionCategory *Category : SortedCategories) {
2499 const auto &CategoryOptions = CategorizedOptions[Category];
2500 if (CategoryOptions.empty())
2505 outs() << Category->getName() <<
":\n";
2508 if (!Category->getDescription().empty())
2509 outs() << Category->getDescription() <<
"\n\n";
2514 for (
const Option *Opt : CategoryOptions)
2522class HelpPrinterWrapper {
2524 HelpPrinter &UncategorizedPrinter;
2525 CategorizedHelpPrinter &CategorizedPrinter;
2528 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
2529 CategorizedHelpPrinter &CategorizedPrinter)
2530 : UncategorizedPrinter(UncategorizedPrinter),
2531 CategorizedPrinter(CategorizedPrinter) {}
2534 void operator=(
bool Value);
2539#if defined(__GNUC__)
2542# if defined(__OPTIMIZE__)
2543# define LLVM_IS_DEBUG_BUILD 0
2545# define LLVM_IS_DEBUG_BUILD 1
2547#elif defined(_MSC_VER)
2552# define LLVM_IS_DEBUG_BUILD 1
2554# define LLVM_IS_DEBUG_BUILD 0
2558# define LLVM_IS_DEBUG_BUILD 0
2562class VersionPrinter {
2564 void print(
const std::vector<VersionPrinterTy> &ExtraPrinters) {
2566#ifdef PACKAGE_VENDOR
2567 OS << PACKAGE_VENDOR <<
" ";
2569 OS <<
"LLVM (http://llvm.org/):\n ";
2571 OS << PACKAGE_NAME <<
" version " << PACKAGE_VERSION <<
"\n ";
2572#if LLVM_IS_DEBUG_BUILD
2573 OS <<
"DEBUG build";
2575 OS <<
"Optimized build";
2578 OS <<
" with assertions";
2584 if (!ExtraPrinters.empty()) {
2585 for (
const auto &
I : ExtraPrinters)
2589 void operator=(
bool OptionWasSpecified);
2592struct CommandLineCommonOptions {
2595 HelpPrinter UncategorizedNormalPrinter{
false};
2596 HelpPrinter UncategorizedHiddenPrinter{
true};
2597 CategorizedHelpPrinter CategorizedNormalPrinter{
false};
2598 CategorizedHelpPrinter CategorizedHiddenPrinter{
true};
2601 HelpPrinterWrapper WrappedNormalPrinter{UncategorizedNormalPrinter,
2602 CategorizedNormalPrinter};
2603 HelpPrinterWrapper WrappedHiddenPrinter{UncategorizedHiddenPrinter,
2604 CategorizedHiddenPrinter};
2614 "Display list of available options (--help-list-hidden for more)"),
2623 cl::desc(
"Display list of all available options"),
2635 cl::desc(
"Display available options (--help-hidden for more)"),
2645 cl::desc(
"Display all available options"),
2654 cl::desc(
"Print non-default options after command line parsing"),
2661 "print-all-options",
2662 cl::desc(
"Print all option values after command line parsing"),
2670 std::vector<VersionPrinterTy> ExtraVersionPrinters;
2673 VersionPrinter VersionPrinterInstance;
2676 "version",
cl::desc(
"Display the version of this program"),
2701 return GeneralCategory;
2704void VersionPrinter::operator=(
bool OptionWasSpecified) {
2705 if (!OptionWasSpecified)
2717void HelpPrinterWrapper::operator=(
bool Value) {
2724 if (
globalParser().RegisteredOptionCategories.size() > 1) {
2729 CategorizedPrinter =
true;
2731 UncategorizedPrinter =
true;
2738void CommandLineParser::printOptionValues() {
2743 sortOpts(ActiveSubCommand->OptionsMap, Opts,
true);
2746 size_t MaxArgLen = 0;
2747 for (
const auto &Opt : Opts)
2750 for (
const auto &Opt : Opts)
2756 if (!
Hidden && !Categorized)
2758 else if (!
Hidden && Categorized)
2760 else if (
Hidden && !Categorized)
2772#if LLVM_IS_DEBUG_BUILD
2778#ifdef EXPENSIVE_CHECKS
2779 "+expensive-checks",
2781#if __has_feature(address_sanitizer)
2784#if __has_feature(dataflow_sanitizer)
2787#if __has_feature(hwaddress_sanitizer)
2790#if __has_feature(memory_sanitizer)
2793#if __has_feature(thread_sanitizer)
2796#if __has_feature(undefined_behavior_sanitizer)
2799#ifdef LLVM_INTEGRATED_CRT_ALLOC
2800 "+alloc:" LLVM_INTEGRATED_CRT_ALLOC,
2808#if LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG
2809 OS <<
"Build config: ";
2833 return Sub.OptionsMap;
2843 for (
auto &
I :
Sub.OptionsMap) {
2844 bool Unrelated =
true;
2845 for (
auto &Cat :
I.second->Categories) {
2846 if (Cat == &Category || Cat == &
CommonOptions->GenericCategory)
2857 for (
auto &
I :
Sub.OptionsMap) {
2858 bool Unrelated =
true;
2859 for (
auto &Cat :
I.second->Categories) {
2875 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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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 bool parseDouble(Option &O, StringRef Arg, double &Value)
static CommandLineParser & globalParser()
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 void ExpandBasePaths(StringRef BasePath, StringSaver &Saver, const char *&Arg)
static Option * getOptionPred(StringRef Name, size_t &Length, bool(*Pred)(const Option *), const OptionsMapTy &OptionsMap)
static SmallString< 8 > argPrefix(StringRef ArgName, size_t Pad=DefaultPad)
static StringRef ArgHelpPrefix
void opt_unsigned_anchor()
static bool isWindowsSpecialCharInCommandName(char C)
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 Option * HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value, bool &ErrorParsing, const OptionsMapTy &OptionsMap)
HandlePrefixedOrGroupedOption - The specified argument string (which started with at least one '-') d...
static void initCommonOptions()
static void sortOpts(OptionsMapTy &OptMap, SmallVectorImpl< std::pair< const char *, Option * > > &Opts, bool ShowHidden)
DenseMap< StringRef, Option * > OptionsMapTy
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 bool parseFixedOrScalableQuantity(Option &O, StringRef Arg, StringRef ValueKind, FixedOrScalableQuantityT &Value)
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 bool EatsUnboundedNumberOfValues(const Option *O)
static int OptNameCompare(const std::pair< const char *, Option * > *LHS, const std::pair< const char *, Option * > *RHS)
static Option * LookupNearestOption(StringRef Arg, const OptionsMapTy &OptionsMap, std::string &NearestString)
LookupNearestOption - Lookup the closest match to the option specified by the specified option on the...
static StringRef ArgPrefix
static bool isWindowsSpecialChar(char C)
static bool isGrouping(const Option *O)
static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos, StringRef ArgName, StringRef Value)
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling ...
#define LLVM_EXPORT_TEMPLATE
static void Help(StringTable 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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
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...
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...
bool erase(PtrType Ptr)
Remove pointer from the set.
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)
void reserve(size_type N)
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...
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.
static constexpr size_t npos
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
Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_ABI unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
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 ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T, vfs::FileSystem *FS=nullptr)
LLVM_ABI bool findConfigFile(StringRef FileName, SmallVectorImpl< char > &FilePath)
Looks for the specified configuration file.
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 getName() const
SmallPtrSet< SubCommand *, 1 > Subs
int getNumOccurrences() const
enum ValueExpected getValueExpectedFlag() const
void addCategory(OptionCategory &C)
void setMiscFlag(enum MiscFlags M)
enum FormattingFlags getFormattingFlag() const
virtual void printOptionInfo(size_t GlobalWidth) const =0
enum NumOccurrencesFlag getNumOccurrencesFlag() const
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value)
SmallVector< OptionCategory *, 1 > Categories
bool error(const Twine &Message, StringRef ArgName=StringRef(), raw_ostream &Errs=llvm::errs())
void setArgStr(StringRef S)
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)
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
Option(enum NumOccurrencesFlag OccurrencesFlag, enum OptionHidden Hidden)
StringRef getName() const
SubCommand(StringRef Name, StringRef Description="")
static LLVM_ABI SubCommand & getTopLevel()
LLVM_ABI void unregisterSubCommand()
static LLVM_ABI SubCommand & getAll()
DenseMap< StringRef, Option * > OptionsMap
LLVM_ABI void registerSubCommand()
SmallVector< Option *, 4 > PositionalOpts
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 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)
The virtual file system interface.
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.
constexpr size_t NameSize
This namespace contains all of the command line option processing machinery.
LLVM_ABI iterator_range< SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
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 DenseMap< StringRef, Option * > & getRegisteredOptions(SubCommand &Sub=SubCommand::getTopLevel())
Use this to get a map of all registered named options (e.g.
LLVM_ABI 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 ...
LLVM_ABI void ResetCommandLineParser()
Reset the command line parser back to its initial state.
LLVM_ABI void PrintOptionValues()
LLVM_ABI void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
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.
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
LLVM_ABI bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
static raw_ostream & operator<<(raw_ostream &OS, boolOrDefault V)
initializer< Ty > init(const Ty &Val)
std::function< void(raw_ostream &)> VersionPrinterTy
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 bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, vfs::FileSystem *VFS=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
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.
LLVM_ABI IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
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()
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
bool to_float(const Twine &T, float &Num)
@ 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 initStatisticOptions()
LLVM_ABI raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
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)
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
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.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
@ Default
The result value is uniform if and only if all operands are uniform.