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() {}
89void OptionValue<boolOrDefault>::anchor() {}
90void OptionValue<std::string>::anchor() {}
91void Option::anchor() {}
124 size_t Len = ArgName.
size();
132 for (
size_t I = 0;
I < Pad; ++
I) {
155 PrintArg(StringRef ArgName,
size_t Pad =
DefaultPad) : ArgName(ArgName), Pad(Pad) {}
156 friend raw_ostream &
operator<<(raw_ostream &OS,
const PrintArg &);
159raw_ostream &
operator<<(raw_ostream &OS,
const PrintArg& Arg) {
160 OS <<
argPrefix(Arg.ArgName, Arg.Pad) << Arg.ArgName;
164class CommandLineParser {
168 std::string ProgramName;
169 StringRef ProgramOverview;
172 std::vector<StringRef> MoreHelp;
180 SmallPtrSet<OptionCategory *, 16> RegisteredOptionCategories;
183 SmallPtrSet<SubCommand *, 4> RegisteredSubCommands;
190 StringRef Overview, raw_ostream *Errs =
nullptr,
191 vfs::FileSystem *VFS =
nullptr,
192 bool LongOptionsUseDoubleDash =
false);
194 void forEachSubCommand(
Option &Opt, function_ref<
void(
SubCommand &)> Action) {
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");
215 if (!SC->
OptionsMap.insert(std::make_pair(Name, &Opt)).second) {
216 errs() << ProgramName <<
": CommandLine Error: Option '" <<
Name
217 <<
"' registered more than once!\n";
222 void addLiteralOption(
Option &Opt, StringRef Name) {
224 Opt, [&](
SubCommand &SC) { addLiteralOption(Opt, &SC, Name); });
228 bool HadErrors =
false;
229 if (
O->hasArgStr()) {
231 if (
O->isDefaultOption() && SC->
OptionsMap.contains(
O->ArgStr))
235 if (!SC->
OptionsMap.insert(std::make_pair(
O->ArgStr, O)).second) {
236 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
237 <<
"' registered more than once!\n";
249 O->error(
"Cannot specify more than one option with cl::ConsumeAfter!");
263 void addOption(
Option *O,
bool ProcessDefaultOption =
false) {
264 if (!ProcessDefaultOption &&
O->isDefaultOption()) {
268 forEachSubCommand(*O, [&](
SubCommand &SC) { addOption(O, &SC); });
272 SmallVector<StringRef, 16> OptionNames;
273 O->getExtraOptionNames(OptionNames);
279 for (
auto Name : OptionNames) {
280 auto I =
Sub.OptionsMap.find(Name);
281 if (
I != End &&
I->getValue() == O)
282 Sub.OptionsMap.erase(
I);
286 for (
auto *Opt =
Sub.PositionalOpts.begin();
287 Opt !=
Sub.PositionalOpts.end(); ++Opt) {
289 Sub.PositionalOpts.erase(Opt);
294 for (
auto *Opt =
Sub.SinkOpts.begin(); Opt !=
Sub.SinkOpts.end(); ++Opt) {
296 Sub.SinkOpts.erase(Opt);
300 else if (O ==
Sub.ConsumeAfterOpt)
301 Sub.ConsumeAfterOpt =
nullptr;
304 void removeOption(
Option *O) {
305 forEachSubCommand(*O, [&](
SubCommand &SC) { removeOption(O, &SC); });
309 return (!
Sub.OptionsMap.empty() || !
Sub.PositionalOpts.empty() ||
310 nullptr !=
Sub.ConsumeAfterOpt);
313 bool hasOptions()
const {
314 for (
const auto *S : RegisteredSubCommands) {
321 bool hasNamedSubCommands()
const {
322 for (
const auto *S : RegisteredSubCommands)
323 if (!S->getName().empty())
328 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
332 if (!
Sub.OptionsMap.insert(std::make_pair(NewName, O)).second) {
333 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
334 <<
"' registered more than once!\n";
340 void updateArgStr(
Option *O, StringRef NewName) {
341 forEachSubCommand(*O,
342 [&](
SubCommand &SC) { updateArgStr(O, NewName, &SC); });
345 void printOptionValues();
352 "Duplicate option categories");
360 return (!
sub->getName().empty()) &&
361 (
Sub->getName() ==
sub->getName());
363 "Duplicate subcommands");
364 RegisteredSubCommands.insert(
sub);
369 "SubCommand::getAll() should not be registered");
372 if ((
O->isPositional() ||
O->isSink() ||
O->isConsumeAfter()) ||
376 addLiteralOption(*O,
sub,
E.first());
381 RegisteredSubCommands.erase(
sub);
384 iterator_range<typename SmallPtrSet<SubCommand *, 4>::iterator>
386 return make_range(RegisteredSubCommands.begin(),
387 RegisteredSubCommands.end());
391 ActiveSubCommand =
nullptr;
393 ProgramOverview = StringRef();
396 RegisteredOptionCategories.
clear();
399 RegisteredSubCommands.clear();
405 DefaultOptions.
clear();
413 bool LongOptionsUseDoubleDash,
bool HaveDoubleDash) {
415 if (Opt && LongOptionsUseDoubleDash && !HaveDoubleDash && !
isGrouping(Opt))
419 SubCommand *LookupSubCommand(StringRef Name, std::string &NearestString);
426template <
typename T, T TrueVal, T FalseVal>
428 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
434 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
438 return O.error(
"'" + Arg +
439 "' is invalid value for boolean argument! Try 0 or 1");
452 FullyInitialized =
true;
458 if (FullyInitialized)
484void OptionCategory::registerCategory() {
518SubCommand::operator
bool()
const {
536 size_t EqualPos = Arg.
find(
'=');
541 return Sub.OptionsMap.lookup(Arg);
547 auto I =
Sub.OptionsMap.find(Arg.
substr(0, EqualPos));
548 if (
I ==
Sub.OptionsMap.end())
556 Arg = Arg.
substr(0, EqualPos);
561 std::string &NearestString) {
566 for (
auto *S : RegisteredSubCommands) {
568 "SubCommand::getAll() is not expected in RegisteredSubCommands");
569 if (S->getName().empty())
572 if (S->getName() == Name)
575 if (!NearestMatch && S->getName().edit_distance(Name) < 2)
580 NearestString = NearestMatch->
getName();
591 std::string &NearestString) {
597 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
603 unsigned BestDistance = 0;
605 ie = OptionsMap.
end();
613 O->getExtraOptionNames(OptionNames);
619 for (
const auto &Name : OptionNames) {
621 Flag,
true, BestDistance);
622 if (!Best || Distance < BestDistance) {
624 BestDistance = Distance;
625 if (
RHS.empty() || !PermitValue)
626 NearestString = std::string(Name);
628 NearestString = (
Twine(Name) +
"=" +
RHS).str();
640 bool MultiArg =
false) {
652 Val = Val.
substr(Pos + 1);
668 const char *
const *argv,
int &i) {
679 return Handler->
error(
"requires a value!");
681 assert(argv &&
"null check");
686 if (NumAdditionalVals > 0)
687 return Handler->
error(
"multi-valued option specified"
688 " with ValueDisallowed modifier!");
699 if (NumAdditionalVals == 0)
703 bool MultiArg =
false;
712 while (NumAdditionalVals > 0) {
714 return Handler->
error(
"not enough values!");
715 assert(argv &&
"null check");
738 bool (*Pred)(
const Option *),
741 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
742 OMI = OptionsMap.
end();
747 while (OMI == OptionsMap.
end() && Name.size() > 1) {
748 Name = Name.drop_back();
749 OMI = OptionsMap.
find(Name);
750 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
751 OMI = OptionsMap.
end();
754 if (OMI != OptionsMap.
end() && Pred(OMI->second)) {
782 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
792 if (MaybeValue[0] ==
'=') {
802 ErrorParsing |= PGOpt->
error(
"may not occur within a group!");
831 return C ==
' ' ||
C ==
'\t' ||
C ==
'\r' ||
C ==
'\n';
838static bool isQuote(
char C) {
return C ==
'\"' ||
C ==
'\''; }
844 for (
size_t I = 0, E = Src.size();
I != E; ++
I) {
849 if (MarkEOLs && Src[
I] ==
'\n')
860 if (
I + 1 < E &&
C ==
'\\') {
869 while (
I != E && Src[
I] !=
C) {
871 if (Src[
I] ==
'\\' &&
I + 1 != E)
886 if (MarkEOLs &&
C ==
'\n')
919 size_t E = Src.size();
920 int BackslashCount = 0;
925 }
while (
I !=
E && Src[
I] ==
'\\');
927 bool FollowedByDoubleQuote = (
I !=
E && Src[
I] ==
'"');
928 if (FollowedByDoubleQuote) {
929 Token.
append(BackslashCount / 2,
'\\');
930 if (BackslashCount % 2 == 0)
935 Token.
append(BackslashCount,
'\\');
953 bool AlwaysCopy,
function_ref<
void()> MarkEOL,
bool InitialCommandName) {
962 bool CommandName = InitialCommandName;
965 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
967 for (
size_t I = 0,
E = Src.size();
I <
E; ++
I) {
970 assert(Token.
empty() &&
"token should be empty in initial state");
992 AddToken(AlwaysCopy ? Saver.
save(NormalChars) : NormalChars);
993 if (
I <
E && Src[
I] ==
'\n') {
995 CommandName = InitialCommandName;
999 }
else if (Src[
I] ==
'\"') {
1000 Token += NormalChars;
1002 }
else if (Src[
I] ==
'\\') {
1003 assert(!CommandName &&
"or else we'd have treated it as a normal char");
1004 Token += NormalChars;
1018 AddToken(Saver.
save(Token.
str()));
1020 if (Src[
I] ==
'\n') {
1021 CommandName = InitialCommandName;
1024 CommandName =
false;
1027 }
else if (Src[
I] ==
'\"') {
1029 }
else if (Src[
I] ==
'\\' && !CommandName) {
1037 if (Src[
I] ==
'\"') {
1038 if (
I < (
E - 1) && Src[
I + 1] ==
'"') {
1047 }
else if (Src[
I] ==
'\\' && !CommandName) {
1057 AddToken(Saver.
save(Token.
str()));
1064 auto OnEOL = [&]() {
1069 true, OnEOL,
false);
1075 auto OnEOL = []() {};
1084 auto OnEOL = [&]() {
1095 for (
const char *Cur = Source.begin(); Cur != Source.end();) {
1104 while (Cur != Source.end() && *Cur !=
'\n')
1109 const char *Start = Cur;
1110 for (
const char *End = Source.end(); Cur != End; ++Cur) {
1112 if (Cur + 1 != End) {
1115 (*Cur ==
'\r' && (Cur + 1 != End) && Cur[1] ==
'\n')) {
1116 Line.append(Start, Cur - 1);
1122 }
else if (*Cur ==
'\n')
1126 Line.append(Start, Cur);
1134 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
1148 TokenPos = ArgString.
find(Token, StartPos)) {
1152 if (ResponseFile.
empty())
1156 ResponseFile.
append(BasePath);
1157 StartPos = TokenPos + Token.
size();
1160 if (!ResponseFile.
empty()) {
1163 if (!Remaining.
empty())
1170Error ExpansionContext::expandResponseFile(
1171 StringRef FName, SmallVectorImpl<const char *> &NewArgv) {
1173 llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> MemBufOrErr =
1174 FS->getBufferForFile(FName);
1178 "': " +
EC.message());
1180 MemoryBuffer &MemBuf = *MemBufOrErr.
get();
1185 std::string UTF8Buf;
1189 "Could not convert UTF16 to UTF8");
1190 Str = StringRef(UTF8Buf);
1196 Str = StringRef(BufRef.data() + 3, BufRef.size() - 3);
1199 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
1204 if (!RelativeNames && !InConfigFile)
1208 for (
const char *&Arg : NewArgv) {
1218 StringRef ArgStr(Arg);
1220 bool ConfigInclusion =
false;
1221 if (ArgStr.consume_front(
"@")) {
1225 }
else if (ArgStr.consume_front(
"--config=")) {
1227 ConfigInclusion =
true;
1233 SmallString<128> ResponseFile;
1236 SmallString<128> FilePath;
1239 std::make_error_code(std::errc::no_such_file_or_directory),
1240 "cannot not find configuration file: " + FileName);
1241 ResponseFile.
append(FilePath);
1243 ResponseFile.
append(BasePath);
1246 Arg = Saver.save(ResponseFile.
str()).
data();
1255 struct ResponseFileRecord {
1270 for (
unsigned I = 0;
I != Argv.
size();) {
1271 while (
I == FileStack.
back().End) {
1277 const char *Arg = Argv[
I];
1279 if (Arg ==
nullptr) {
1284 if (Arg[0] !=
'@') {
1289 const char *FName = Arg + 1;
1294 if (CurrentDir.empty()) {
1295 if (
auto CWD = FS->getCurrentWorkingDirectory()) {
1299 CWD.getError(),
Twine(
"cannot get absolute path for: ") + FName);
1302 CurrDir = CurrentDir;
1305 FName = CurrDir.
c_str();
1309 if (!Res || !Res->exists()) {
1310 std::error_code EC = Res.
getError();
1311 if (!InConfigFile) {
1322 "': " + EC.message());
1327 [FileStatus,
this](
const ResponseFileRecord &RFile) ->
ErrorOr<bool> {
1339 R.getError(),
Twine(
"recursive expansion of: '") +
F.File +
"'");
1342 Twine(
"cannot open file: ") +
F.File);
1349 if (
Error Err = expandResponseFile(FName, ExpandedArgv))
1352 for (ResponseFileRecord &
Record : FileStack) {
1383 Tokenize(*EnvValue, Saver, NewArgv,
false);
1386 NewArgv.
append(Argv + 1, Argv + Argc);
1407 : Saver(
A), Tokenizer(
T), FS(FS ? FS :
vfs::getRealFileSystem().
get()) {}
1413 auto Status = FS->status(Path);
1421 CfgFilePath = FileName;
1424 if (!FileExists(CfgFilePath))
1431 for (
const StringRef &Dir : SearchDirs) {
1437 if (FileExists(CfgFilePath)) {
1451 if (std::error_code EC = FS->makeAbsolute(AbsPath))
1453 EC,
Twine(
"cannot get absolute path for " + CfgFile));
1454 CfgFile = AbsPath.
str();
1456 InConfigFile =
true;
1457 RelativeNames =
true;
1458 if (
Error Err = expandResponseFile(CfgFile, Argv))
1467 bool LongOptionsUseDoubleDash) {
1476 if (std::optional<std::string> EnvValue =
1482 for (
int I = 1;
I < argc; ++
I)
1484 int NewArgc =
static_cast<int>(NewArgv.
size());
1488 NewArgc, &NewArgv[0], Overview, Errs, VFS, LongOptionsUseDoubleDash);
1492void CommandLineParser::ResetAllOptionOccurrences() {
1496 for (
auto *SC : RegisteredSubCommands) {
1508bool CommandLineParser::ParseCommandLineOptions(
1511 assert(hasOptions() &&
"No options specified!");
1513 ProgramOverview = Overview;
1514 bool IgnoreErrors = Errs;
1519 bool ErrorParsing =
false;
1530 if (
Error Err = ECtx.expandResponseFiles(newArgv)) {
1531 *Errs <<
toString(std::move(Err)) <<
'\n';
1535 argc =
static_cast<int>(newArgv.size());
1541 unsigned NumPositionalRequired = 0;
1544 bool HasUnlimitedPositionals =
false;
1548 std::string NearestSubCommandString;
1549 bool MaybeNamedSubCommand =
1550 argc >= 2 && argv[FirstArg][0] !=
'-' && hasNamedSubCommands();
1551 if (MaybeNamedSubCommand) {
1555 LookupSubCommand(
StringRef(argv[FirstArg]), NearestSubCommandString);
1561 assert(ChosenSubCommand);
1564 auto &SinkOpts = ChosenSubCommand->
SinkOpts;
1565 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1567 for (
auto *O: DefaultOptions) {
1571 if (ConsumeAfterOpt) {
1572 assert(PositionalOpts.size() > 0 &&
1573 "Cannot specify cl::ConsumeAfter without a positional argument!");
1575 if (!PositionalOpts.empty()) {
1578 bool UnboundedFound =
false;
1579 for (
size_t i = 0, e = PositionalOpts.size(); i != e; ++i) {
1580 Option *Opt = PositionalOpts[i];
1582 ++NumPositionalRequired;
1583 else if (ConsumeAfterOpt) {
1586 if (PositionalOpts.size() > 1) {
1588 Opt->
error(
"error - this positional option will never be matched, "
1589 "because it does not Require a value, and a "
1590 "cl::ConsumeAfter option is active!");
1591 ErrorParsing =
true;
1593 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1599 Opt->
error(
"error - option can never match, because "
1600 "another positional argument will match an "
1601 "unbounded number of values, and this option"
1602 " does not require a value!");
1603 *Errs << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr
1604 <<
"' is all messed up!\n";
1605 *Errs << PositionalOpts.size();
1606 ErrorParsing =
true;
1610 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1621 Option *ActivePositionalArg =
nullptr;
1624 bool DashDashFound =
false;
1625 for (
int i = FirstArg; i < argc; ++i) {
1626 Option *Handler =
nullptr;
1627 std::string NearestHandlerString;
1629 StringRef ArgName =
"";
1630 bool HaveDoubleDash =
false;
1636 if (argv[i][0] !=
'-' || argv[i][1] == 0 || DashDashFound) {
1638 if (ActivePositionalArg) {
1643 if (!PositionalOpts.empty()) {
1644 PositionalVals.
push_back(std::make_pair(StringRef(argv[i]), i));
1649 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
1650 for (++i; i < argc; ++i)
1651 PositionalVals.
push_back(std::make_pair(StringRef(argv[i]), i));
1658 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
1660 DashDashFound =
true;
1662 }
else if (ActivePositionalArg &&
1667 ArgName = StringRef(argv[i] + 1);
1670 HaveDoubleDash =
true;
1672 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1673 LongOptionsUseDoubleDash, HaveDoubleDash);
1679 ArgName = StringRef(argv[i] + 1);
1682 HaveDoubleDash =
true;
1684 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1685 LongOptionsUseDoubleDash, HaveDoubleDash);
1692 LongOptionsUseDoubleDash, HaveDoubleDash);
1695 if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
1701 if (!Handler && SinkOpts.empty())
1706 if (!SinkOpts.empty()) {
1707 for (
Option *SinkOpt : SinkOpts)
1708 SinkOpt->addOccurrence(i,
"", StringRef(argv[i]));
1712 auto ReportUnknownArgument = [&](
bool IsArg,
1713 StringRef NearestArgumentName) {
1714 *Errs << ProgramName <<
": Unknown "
1715 << (IsArg ?
"command line argument" :
"subcommand") <<
" '"
1716 << argv[i] <<
"'. Try: '" << argv[0] <<
" --help'\n";
1718 if (NearestArgumentName.empty())
1721 *Errs << ProgramName <<
": Did you mean '";
1723 *Errs << PrintArg(NearestArgumentName, 0);
1725 *Errs << NearestArgumentName;
1729 if (i > 1 || !MaybeNamedSubCommand)
1730 ReportUnknownArgument(
true, NearestHandlerString);
1732 ReportUnknownArgument(
false, NearestSubCommandString);
1734 ErrorParsing =
true;
1742 Handler->
error(
"This argument does not take a value.\n"
1743 "\tInstead, it consumes any positional arguments until "
1744 "the next recognized option.", *Errs);
1745 ErrorParsing =
true;
1747 ActivePositionalArg = Handler;
1754 if (NumPositionalRequired > PositionalVals.
size()) {
1755 *Errs << ProgramName
1756 <<
": Not enough positional command line arguments specified!\n"
1757 <<
"Must specify at least " << NumPositionalRequired
1758 <<
" positional argument" << (NumPositionalRequired > 1 ?
"s" :
"")
1759 <<
": See: " << argv[0] <<
" --help\n";
1761 ErrorParsing =
true;
1762 }
else if (!HasUnlimitedPositionals &&
1763 PositionalVals.
size() > PositionalOpts.size()) {
1764 *Errs << ProgramName <<
": Too many positional arguments specified!\n"
1765 <<
"Can specify at most " << PositionalOpts.size()
1766 <<
" positional arguments: See: " << argv[0] <<
" --help\n";
1767 ErrorParsing =
true;
1769 }
else if (!ConsumeAfterOpt) {
1771 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1772 for (
Option *Opt : PositionalOpts) {
1775 PositionalVals[ValNo].second);
1777 --NumPositionalRequired;
1785 while (NumVals - ValNo > NumPositionalRequired && !
Done) {
1793 PositionalVals[ValNo].second);
1798 "positional argument processing!");
1803 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1805 for (
Option *Opt : PositionalOpts)
1808 Opt, PositionalVals[ValNo].first, PositionalVals[ValNo].second);
1817 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1819 PositionalVals[ValNo].first,
1820 PositionalVals[ValNo].second);
1826 for (; ValNo != PositionalVals.
size(); ++ValNo)
1829 PositionalVals[ValNo].second);
1833 for (
const auto &Opt : OptionsMap) {
1838 Opt.second->
error(
"must be specified at least once!");
1839 ErrorParsing =
true;
1851 for (
int i = 0; i < argc; ++i)
dbgs() << argv[i] <<
' ';
1872 if (!ArgName.
data())
1874 if (ArgName.
empty())
1877 Errs <<
GlobalParser->ProgramName <<
": for the " << PrintArg(ArgName, 0);
1879 Errs <<
" option: " << Message <<
"\n";
1888 return handleOccurrence(pos, ArgName, Value);
1895 if (O.ValueStr.empty())
1910 size_t FirstLineIndentedBy) {
1911 assert(Indent >= FirstLineIndentedBy);
1912 std::pair<StringRef, StringRef> Split =
HelpStr.split(
'\n');
1915 while (!Split.second.empty()) {
1916 Split = Split.second.split(
'\n');
1917 outs().
indent(Indent) << Split.first <<
"\n";
1922 size_t FirstLineIndentedBy) {
1924 assert(BaseIndent >= FirstLineIndentedBy);
1925 std::pair<StringRef, StringRef> Split =
HelpStr.split(
'\n');
1926 outs().
indent(BaseIndent - FirstLineIndentedBy)
1928 while (!Split.second.empty()) {
1929 Split = Split.second.split(
'\n');
1930 outs().
indent(BaseIndent + ValHelpPrefix.
size()) << Split.first <<
"\n";
1935void alias::printOptionInfo(
size_t GlobalWidth)
const {
1951 if (!ValName.empty()) {
1952 size_t FormattingLen = 3;
1965 size_t GlobalWidth)
const {
1966 outs() << PrintArg(O.ArgStr);
1969 if (!ValName.empty()) {
1975 outs() << (O.ArgStr.size() == 1 ?
" <" :
"=<") <<
getValueStr(O, ValName)
1984 size_t GlobalWidth)
const {
1985 outs() << PrintArg(O.ArgStr);
1986 outs().
indent(GlobalWidth - O.ArgStr.size());
2008 return O.error(
"'" + Arg +
"' value invalid for integer argument!");
2017 return O.error(
"'" + Arg +
"' value invalid for long argument!");
2026 return O.error(
"'" + Arg +
"' value invalid for llong argument!");
2036 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
2043 unsigned long &
Value) {
2046 return O.error(
"'" + Arg +
"' value invalid for ulong argument!");
2054 unsigned long long &
Value) {
2057 return O.error(
"'" + Arg +
"' value invalid for ullong argument!");
2066 return O.error(
"'" + Arg +
"' value invalid for floating point argument!");
2092 for (
unsigned i = 0; i != e; ++i) {
2108 return O.getValueExpectedFlag() !=
ValueOptional || !Name.empty() ||
2109 !Description.
empty();
2114 if (O.hasArgStr()) {
2126 size_t BaseSize = 0;
2137 size_t GlobalWidth)
const {
2138 if (O.hasArgStr()) {
2144 outs() << PrintArg(O.ArgStr);
2163 if (OptionName.
empty()) {
2168 if (!Description.
empty())
2174 if (!O.HelpStr.empty())
2175 outs() <<
" " << O.HelpStr <<
'\n';
2192 outs() <<
" " << PrintArg(O.ArgStr);
2193 outs().
indent(GlobalWidth - O.ArgStr.size());
2196 for (
unsigned i = 0; i != NumOpts; ++i) {
2204 for (
unsigned j = 0; j != NumOpts; ++j) {
2213 outs() <<
"= *unknown option value*\n";
2218#define PRINT_OPT_DIFF(T) \
2219 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
2220 size_t GlobalWidth) const { \
2221 printOptionName(O, GlobalWidth); \
2224 raw_string_ostream SS(Str); \
2227 outs() << "= " << Str; \
2228 size_t NumSpaces = \
2229 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
2230 outs().indent(NumSpaces) << " (default: "; \
2232 outs() << D.getValue(); \
2234 outs() << "*no default*"; \
2252 size_t GlobalWidth)
const {
2253 printOptionName(O, GlobalWidth);
2254 outs() <<
"= " << V;
2258 outs() <<
D.getValue();
2260 outs() <<
"*no default*";
2266 size_t GlobalWidth)
const {
2268 outs() <<
"= *cannot print option value*\n";
2276 const std::pair<const char *, Option *> *
RHS) {
2277 return strcmp(
LHS->first,
RHS->first);
2281 const std::pair<const char *, SubCommand *> *
RHS) {
2282 return strcmp(
LHS->first,
RHS->first);
2298 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
2302 if (!OptionSet.
insert(
I->second).second)
2306 std::pair<const char *, Option *>(
I->getKey().data(),
I->second));
2316 for (
auto *S : SubMap) {
2317 if (S->getName().empty())
2319 Subs.push_back(std::make_pair(S->getName().data(), S));
2328 const bool ShowHidden;
2330 StrOptionPairVector;
2332 StrSubCommandPairVector;
2334 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
2335 for (
const auto &Opt : Opts)
2339 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
2340 for (
const auto &S : Subs) {
2341 outs() <<
" " << S.first;
2342 if (!S.second->getDescription().empty()) {
2344 outs() <<
" - " << S.second->getDescription();
2351 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
2352 virtual ~HelpPrinter() =
default;
2355 void operator=(
bool Value) {
2366 auto &OptionsMap =
Sub->OptionsMap;
2367 auto &PositionalOpts =
Sub->PositionalOpts;
2368 auto &ConsumeAfterOpt =
Sub->ConsumeAfterOpt;
2370 StrOptionPairVector Opts;
2371 sortOpts(OptionsMap, Opts, ShowHidden);
2373 StrSubCommandPairVector Subs;
2382 outs() <<
" [subcommand]";
2383 outs() <<
" [options]";
2385 if (!
Sub->getDescription().empty()) {
2386 outs() <<
"SUBCOMMAND '" <<
Sub->getName()
2387 <<
"': " <<
Sub->getDescription() <<
"\n\n";
2393 for (
auto *Opt : PositionalOpts) {
2400 if (ConsumeAfterOpt)
2401 outs() <<
" " << ConsumeAfterOpt->HelpStr;
2405 size_t MaxSubLen = 0;
2406 for (
const auto &
Sub : Subs)
2407 MaxSubLen = std::max(MaxSubLen, strlen(
Sub.first));
2410 outs() <<
"SUBCOMMANDS:\n\n";
2411 printSubCommands(Subs, MaxSubLen);
2414 <<
" <subcommand> --help\" to get more help on a specific "
2421 size_t MaxArgLen = 0;
2422 for (
const auto &Opt : Opts)
2425 outs() <<
"OPTIONS:\n";
2426 printOptions(Opts, MaxArgLen);
2435class CategorizedHelpPrinter :
public HelpPrinter {
2437 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
2443 static int OptionCategoryCompare(OptionCategory *
const *
A,
2444 OptionCategory *
const *
B) {
2445 return (*A)->getName().compare((*B)->getName());
2449 using HelpPrinter::operator=;
2452 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
2453 std::vector<OptionCategory *> SortedCategories;
2454 DenseMap<OptionCategory *, std::vector<Option *>> CategorizedOptions;
2462 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
2464 OptionCategoryCompare);
2469 for (
const auto &
I : Opts) {
2471 for (OptionCategory *Cat : Opt->
Categories) {
2473 "Option has an unregistered category");
2474 CategorizedOptions[Cat].push_back(Opt);
2479 for (OptionCategory *Category : SortedCategories) {
2481 const auto &CategoryOptions = CategorizedOptions[Category];
2482 if (CategoryOptions.empty())
2496 for (
const Option *Opt : CategoryOptions)
2504class HelpPrinterWrapper {
2506 HelpPrinter &UncategorizedPrinter;
2507 CategorizedHelpPrinter &CategorizedPrinter;
2510 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
2511 CategorizedHelpPrinter &CategorizedPrinter)
2512 : UncategorizedPrinter(UncategorizedPrinter),
2513 CategorizedPrinter(CategorizedPrinter) {}
2516 void operator=(
bool Value);
2521#if defined(__GNUC__)
2524# if defined(__OPTIMIZE__)
2525# define LLVM_IS_DEBUG_BUILD 0
2527# define LLVM_IS_DEBUG_BUILD 1
2529#elif defined(_MSC_VER)
2534# define LLVM_IS_DEBUG_BUILD 1
2536# define LLVM_IS_DEBUG_BUILD 0
2540# define LLVM_IS_DEBUG_BUILD 0
2544class VersionPrinter {
2546 void print(std::vector<VersionPrinterTy> ExtraPrinters = {}) {
2548#ifdef PACKAGE_VENDOR
2549 OS << PACKAGE_VENDOR <<
" ";
2551 OS <<
"LLVM (http://llvm.org/):\n ";
2553 OS << PACKAGE_NAME <<
" version " << PACKAGE_VERSION <<
"\n ";
2554#if LLVM_IS_DEBUG_BUILD
2555 OS <<
"DEBUG build";
2557 OS <<
"Optimized build";
2560 OS <<
" with assertions";
2566 if (!ExtraPrinters.empty()) {
2567 for (
const auto &
I : ExtraPrinters)
2571 void operator=(
bool OptionWasSpecified);
2574struct CommandLineCommonOptions {
2577 HelpPrinter UncategorizedNormalPrinter{
false};
2578 HelpPrinter UncategorizedHiddenPrinter{
true};
2579 CategorizedHelpPrinter CategorizedNormalPrinter{
false};
2580 CategorizedHelpPrinter CategorizedHiddenPrinter{
true};
2583 HelpPrinterWrapper WrappedNormalPrinter{UncategorizedNormalPrinter,
2584 CategorizedNormalPrinter};
2585 HelpPrinterWrapper WrappedHiddenPrinter{UncategorizedHiddenPrinter,
2586 CategorizedHiddenPrinter};
2596 "Display list of available options (--help-list-hidden for more)"),
2605 cl::desc(
"Display list of all available options"),
2617 cl::desc(
"Display available options (--help-hidden for more)"),
2628 cl::desc(
"Display all available options"),
2637 cl::desc(
"Print non-default options after command line parsing"),
2644 "print-all-options",
2645 cl::desc(
"Print all option values after command line parsing"),
2653 std::vector<VersionPrinterTy> ExtraVersionPrinters;
2656 VersionPrinter VersionPrinterInstance;
2659 "version",
cl::desc(
"Display the version of this program"),
2684 return GeneralCategory;
2687void VersionPrinter::operator=(
bool OptionWasSpecified) {
2688 if (!OptionWasSpecified)
2700void HelpPrinterWrapper::operator=(
bool Value) {
2707 if (
GlobalParser->RegisteredOptionCategories.size() > 1) {
2712 CategorizedPrinter =
true;
2714 UncategorizedPrinter =
true;
2721void CommandLineParser::printOptionValues() {
2729 size_t MaxArgLen = 0;
2730 for (
const auto &Opt : Opts)
2733 for (
const auto &Opt : Opts)
2739 if (!
Hidden && !Categorized)
2741 else if (!
Hidden && Categorized)
2743 else if (
Hidden && !Categorized)
2755#if LLVM_IS_DEBUG_BUILD
2761#ifdef EXPENSIVE_CHECKS
2762 "+expensive-checks",
2764#if __has_feature(address_sanitizer)
2767#if __has_feature(dataflow_sanitizer)
2770#if __has_feature(hwaddress_sanitizer)
2773#if __has_feature(memory_sanitizer)
2776#if __has_feature(thread_sanitizer)
2779#if __has_feature(undefined_behavior_sanitizer)
2788#if LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG
2789 OS <<
"Build config: ";
2813 return Sub.OptionsMap;
2823 for (
auto &
I :
Sub.OptionsMap) {
2824 bool Unrelated =
true;
2825 for (
auto &Cat :
I.second->Categories) {
2826 if (Cat == &Category || Cat == &
CommonOptions->GenericCategory)
2837 for (
auto &
I :
Sub.OptionsMap) {
2838 bool Unrelated =
true;
2839 for (
auto &Cat :
I.second->Categories) {
2855 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< 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 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),...
size_t size() const
size - Get the array size.
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...
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)
StringMapIterBase< ValueTy, false > iterator
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
StringMapIterBase< ValueTy, true > const_iterator
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.
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
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 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 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
SubCommand(StringRef Name, StringRef Description="")
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)
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.
@ C
The default llvm calling convention, compatible with C.
constexpr size_t NameSize
This namespace contains all of the command line option processing machinery.
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 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.
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.
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)
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.
FunctionAddr VTableAddr Value
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.
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.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
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.
@ Default
The result values are uniform if and only if all operands are uniform.