31#include "llvm/Config/config.h"
50#define DEBUG_TYPE "commandline"
79void GenericOptionValue::anchor() {}
82void Option::anchor() {}
106 size_t Len = ArgName.
size();
114 for (
size_t I = 0;
I < Pad; ++
I) {
142 OS <<
argPrefix(Arg.ArgName, Arg.Pad) << Arg.ArgName;
146class CommandLineParser {
150 std::string ProgramName;
154 std::vector<StringRef> MoreHelp;
173 bool LongOptionsUseDoubleDash =
false);
176 if (Opt.
Subs.empty()) {
181 for (
auto *SC : RegisteredSubCommands)
186 for (
auto *SC : Opt.
Subs) {
188 "SubCommand::getAll() should not be used with other subcommands");
196 if (!
SC->OptionsMap.insert(std::make_pair(
Name, &Opt)).second) {
197 errs() << ProgramName <<
": CommandLine Error: Option '" <<
Name
198 <<
"' registered more than once!\n";
209 bool HadErrors =
false;
210 if (
O->hasArgStr()) {
212 if (
O->isDefaultOption() &&
SC->OptionsMap.contains(
O->ArgStr))
216 if (!
SC->OptionsMap.insert(std::make_pair(
O->ArgStr, O)).second) {
217 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
218 <<
"' registered more than once!\n";
225 SC->PositionalOpts.push_back(O);
227 SC->SinkOpts.push_back(O);
229 if (
SC->ConsumeAfterOpt) {
230 O->error(
"Cannot specify more than one option with cl::ConsumeAfter!");
233 SC->ConsumeAfterOpt =
O;
244 void addOption(
Option *O,
bool ProcessDefaultOption =
false) {
245 if (!ProcessDefaultOption &&
O->isDefaultOption()) {
249 forEachSubCommand(*O, [&](
SubCommand &SC) { addOption(O, &SC); });
254 O->getExtraOptionNames(OptionNames);
260 for (
auto Name : OptionNames) {
262 if (
I !=
End &&
I->getValue() == O)
285 void removeOption(
Option *O) {
286 forEachSubCommand(*O, [&](
SubCommand &SC) { removeOption(O, &SC); });
289 bool hasOptions(
const SubCommand &Sub)
const {
294 bool hasOptions()
const {
295 for (
const auto *S : RegisteredSubCommands) {
302 bool hasNamedSubCommands()
const {
303 for (
const auto *S : RegisteredSubCommands)
304 if (!S->getName().empty())
309 SubCommand *getActiveSubCommand() {
return ActiveSubCommand; }
313 if (!Sub.
OptionsMap.insert(std::make_pair(NewName, O)).second) {
314 errs() << ProgramName <<
": CommandLine Error: Option '" <<
O->ArgStr
315 <<
"' registered more than once!\n";
322 forEachSubCommand(*O,
323 [&](
SubCommand &SC) { updateArgStr(O, NewName, &SC); });
326 void printOptionValues();
333 "Duplicate option categories");
341 return (!
sub->getName().empty()) &&
344 "Duplicate subcommands");
345 RegisteredSubCommands.insert(
sub);
350 "SubCommand::getAll() should not be registered");
353 if ((
O->isPositional() ||
O->isSink() ||
O->isConsumeAfter()) ||
357 addLiteralOption(*O,
sub, E.first());
362 RegisteredSubCommands.erase(
sub);
367 return make_range(RegisteredSubCommands.begin(),
368 RegisteredSubCommands.end());
372 ActiveSubCommand =
nullptr;
377 RegisteredOptionCategories.
clear();
380 RegisteredSubCommands.clear();
386 DefaultOptions.
clear();
394 bool LongOptionsUseDoubleDash,
bool HaveDoubleDash) {
396 if (Opt && LongOptionsUseDoubleDash && !HaveDoubleDash && !
isGrouping(Opt))
417 FullyInitialized =
true;
423 if (FullyInitialized)
449void OptionCategory::registerCategory() {
483SubCommand::operator
bool()
const {
501 size_t EqualPos = Arg.
find(
'=');
521 Arg = Arg.
substr(0, EqualPos);
526 std::string &NearestString) {
531 for (
auto *S : RegisteredSubCommands) {
533 "SubCommand::getAll() is not expected in RegisteredSubCommands");
534 if (S->getName().empty())
537 if (S->getName() ==
Name)
540 if (!NearestMatch && S->getName().edit_distance(
Name) < 2)
545 NearestString = NearestMatch->
getName();
556 std::string &NearestString) {
562 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
568 unsigned BestDistance = 0;
570 ie = OptionsMap.
end();
578 O->getExtraOptionNames(OptionNames);
584 for (
const auto &
Name : OptionNames) {
586 Flag,
true, BestDistance);
587 if (!Best || Distance < BestDistance) {
589 BestDistance = Distance;
590 if (
RHS.empty() || !PermitValue)
591 NearestString = std::string(
Name);
605 bool MultiArg =
false) {
617 Val = Val.
substr(Pos + 1);
633 const char *
const *argv,
int &i) {
644 return Handler->
error(
"requires a value!");
646 assert(argv &&
"null check");
651 if (NumAdditionalVals > 0)
652 return Handler->
error(
"multi-valued option specified"
653 " with ValueDisallowed modifier!");
664 if (NumAdditionalVals == 0)
668 bool MultiArg =
false;
677 while (NumAdditionalVals > 0) {
679 return Handler->
error(
"not enough values!");
680 assert(argv &&
"null check");
703 bool (*Pred)(
const Option *),
706 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
707 OMI = OptionsMap.
end();
712 while (OMI == OptionsMap.
end() &&
Name.size() > 1) {
715 if (OMI != OptionsMap.
end() && !Pred(OMI->getValue()))
716 OMI = OptionsMap.
end();
719 if (OMI != OptionsMap.
end() && Pred(OMI->second)) {
747 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
757 if (MaybeValue[0] ==
'=') {
767 ErrorParsing |= PGOpt->
error(
"may not occur within a group!");
796 return C ==
' ' ||
C ==
'\t' ||
C ==
'\r' ||
C ==
'\n';
803static bool isQuote(
char C) {
return C ==
'\"' ||
C ==
'\''; }
809 for (
size_t I = 0, E = Src.size();
I != E; ++
I) {
814 if (MarkEOLs && Src[
I] ==
'\n')
825 if (
I + 1 < E &&
C ==
'\\') {
834 while (
I != E && Src[
I] !=
C) {
836 if (Src[
I] ==
'\\' &&
I + 1 != E)
851 if (MarkEOLs &&
C ==
'\n')
884 size_t E = Src.size();
885 int BackslashCount = 0;
890 }
while (
I != E && Src[
I] ==
'\\');
892 bool FollowedByDoubleQuote = (
I != E && Src[
I] ==
'"');
893 if (FollowedByDoubleQuote) {
894 Token.
append(BackslashCount / 2,
'\\');
895 if (BackslashCount % 2 == 0)
900 Token.
append(BackslashCount,
'\\');
918 bool AlwaysCopy,
function_ref<
void()> MarkEOL,
bool InitialCommandName) {
927 bool CommandName = InitialCommandName;
930 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
932 for (
size_t I = 0, E = Src.size();
I < E; ++
I) {
935 assert(Token.
empty() &&
"token should be empty in initial state");
957 AddToken(AlwaysCopy ? Saver.
save(NormalChars) : NormalChars);
958 if (
I < E && Src[
I] ==
'\n') {
960 CommandName = InitialCommandName;
964 }
else if (Src[
I] ==
'\"') {
965 Token += NormalChars;
967 }
else if (Src[
I] ==
'\\') {
968 assert(!CommandName &&
"or else we'd have treated it as a normal char");
969 Token += NormalChars;
983 AddToken(Saver.
save(Token.
str()));
985 if (Src[
I] ==
'\n') {
986 CommandName = InitialCommandName;
992 }
else if (Src[
I] ==
'\"') {
994 }
else if (Src[
I] ==
'\\' && !CommandName) {
1002 if (Src[
I] ==
'\"') {
1003 if (
I < (E - 1) && Src[
I + 1] ==
'"') {
1012 }
else if (Src[
I] ==
'\\' && !CommandName) {
1022 AddToken(Saver.
save(Token.
str()));
1029 auto OnEOL = [&]() {
1034 true, OnEOL,
false);
1040 auto OnEOL = []() {};
1049 auto OnEOL = [&]() {
1060 for (
const char *Cur = Source.begin(); Cur != Source.end();) {
1069 while (Cur != Source.end() && *Cur !=
'\n')
1074 const char *Start = Cur;
1075 for (
const char *
End = Source.end(); Cur !=
End; ++Cur) {
1077 if (Cur + 1 !=
End) {
1080 (*Cur ==
'\r' && (Cur + 1 !=
End) && Cur[1] ==
'\n')) {
1081 Line.append(Start, Cur - 1);
1087 }
else if (*Cur ==
'\n')
1091 Line.append(Start, Cur);
1099 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
1113 TokenPos = ArgString.
find(Token, StartPos)) {
1117 if (ResponseFile.
empty())
1121 ResponseFile.
append(BasePath);
1122 StartPos = TokenPos + Token.
size();
1125 if (!ResponseFile.
empty()) {
1128 if (!Remaining.
empty())
1135Error ExpansionContext::expandResponseFile(
1143 "': " +
EC.message());
1150 std::string UTF8Buf;
1154 "Could not convert UTF16 to UTF8");
1161 Str =
StringRef(BufRef.data() + 3, BufRef.size() - 3);
1164 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
1169 if (!RelativeNames && !InConfigFile)
1173 for (
const char *&Arg : NewArgv) {
1185 bool ConfigInclusion =
false;
1186 if (ArgStr.consume_front(
"@")) {
1190 }
else if (ArgStr.consume_front(
"--config=")) {
1192 ConfigInclusion =
true;
1204 std::make_error_code(std::errc::no_such_file_or_directory),
1205 "cannot not find configuration file: " + FileName);
1206 ResponseFile.
append(FilePath);
1208 ResponseFile.
append(BasePath);
1220 struct ResponseFileRecord {
1235 for (
unsigned I = 0;
I != Argv.
size();) {
1236 while (
I == FileStack.
back().End) {
1242 const char *Arg = Argv[
I];
1244 if (Arg ==
nullptr) {
1249 if (Arg[0] !=
'@') {
1254 const char *FName = Arg + 1;
1259 if (CurrentDir.
empty()) {
1264 CWD.getError(),
Twine(
"cannot get absolute path for: ") + FName);
1267 CurrDir = CurrentDir;
1270 FName = CurrDir.
c_str();
1274 if (!Res || !Res->exists()) {
1275 std::error_code EC = Res.
getError();
1276 if (!InConfigFile) {
1287 "': " + EC.message());
1292 [FileStatus,
this](
const ResponseFileRecord &RFile) ->
ErrorOr<bool> {
1295 return RHS.getError();
1304 R.getError(),
Twine(
"recursive expansion of: '") +
F.File +
"'");
1307 Twine(
"cannot open file: ") +
F.File);
1314 if (
Error Err = expandResponseFile(FName, ExpandedArgv))
1317 for (ResponseFileRecord &
Record : FileStack) {
1323 FileStack.push_back({FName,
I + ExpandedArgv.
size()});
1348 Tokenize(*EnvValue, Saver, NewArgv,
false);
1351 NewArgv.
append(Argv + 1, Argv + Argc);
1371 : Saver(
A), Tokenizer(
T), FS(vfs::getRealFileSystem().
get()) {}
1385 CfgFilePath = FileName;
1388 if (!FileExists(CfgFilePath))
1395 for (
const StringRef &Dir : SearchDirs) {
1401 if (FileExists(CfgFilePath)) {
1416 return make_error<StringError>(
1417 EC,
Twine(
"cannot get absolute path for " + CfgFile));
1418 CfgFile = AbsPath.
str();
1420 InConfigFile =
true;
1421 RelativeNames =
true;
1422 if (
Error Err = expandResponseFile(CfgFile, Argv))
1431 bool LongOptionsUseDoubleDash) {
1440 if (std::optional<std::string> EnvValue =
1446 for (
int I = 1;
I < argc; ++
I)
1448 int NewArgc =
static_cast<int>(NewArgv.
size());
1451 return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
1452 Errs, LongOptionsUseDoubleDash);
1456void CommandLineParser::ResetAllOptionOccurrences() {
1460 for (
auto *SC : RegisteredSubCommands) {
1461 for (
auto &O : SC->OptionsMap)
1463 for (
Option *O : SC->PositionalOpts)
1465 for (
Option *O : SC->SinkOpts)
1467 if (SC->ConsumeAfterOpt)
1468 SC->ConsumeAfterOpt->reset();
1472bool CommandLineParser::ParseCommandLineOptions(
int argc,
1473 const char *
const *argv,
1476 bool LongOptionsUseDoubleDash) {
1477 assert(hasOptions() &&
"No options specified!");
1479 ProgramOverview = Overview;
1480 bool IgnoreErrors = Errs;
1483 bool ErrorParsing =
false;
1494 if (
Error Err = ECtx.expandResponseFiles(newArgv)) {
1495 *Errs <<
toString(std::move(Err)) <<
'\n';
1499 argc =
static_cast<int>(newArgv.size());
1505 unsigned NumPositionalRequired = 0;
1508 bool HasUnlimitedPositionals =
false;
1512 std::string NearestSubCommandString;
1513 bool MaybeNamedSubCommand =
1514 argc >= 2 && argv[FirstArg][0] !=
'-' && hasNamedSubCommands();
1515 if (MaybeNamedSubCommand) {
1519 LookupSubCommand(
StringRef(argv[FirstArg]), NearestSubCommandString);
1525 assert(ChosenSubCommand);
1528 auto &SinkOpts = ChosenSubCommand->
SinkOpts;
1529 auto &OptionsMap = ChosenSubCommand->
OptionsMap;
1531 for (
auto *O: DefaultOptions) {
1535 if (ConsumeAfterOpt) {
1536 assert(PositionalOpts.size() > 0 &&
1537 "Cannot specify cl::ConsumeAfter without a positional argument!");
1539 if (!PositionalOpts.empty()) {
1542 bool UnboundedFound =
false;
1543 for (
size_t i = 0, e = PositionalOpts.size(); i != e; ++i) {
1544 Option *Opt = PositionalOpts[i];
1546 ++NumPositionalRequired;
1547 else if (ConsumeAfterOpt) {
1550 if (PositionalOpts.size() > 1) {
1552 Opt->
error(
"error - this positional option will never be matched, "
1553 "because it does not Require a value, and a "
1554 "cl::ConsumeAfter option is active!");
1555 ErrorParsing =
true;
1557 }
else if (UnboundedFound && !Opt->
hasArgStr()) {
1563 Opt->
error(
"error - option can never match, because "
1564 "another positional argument will match an "
1565 "unbounded number of values, and this option"
1566 " does not require a value!");
1567 *Errs << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr
1568 <<
"' is all messed up!\n";
1569 *Errs << PositionalOpts.size();
1570 ErrorParsing =
true;
1574 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
1585 Option *ActivePositionalArg =
nullptr;
1588 bool DashDashFound =
false;
1589 for (
int i = FirstArg; i < argc; ++i) {
1590 Option *Handler =
nullptr;
1591 std::string NearestHandlerString;
1594 bool HaveDoubleDash =
false;
1600 if (argv[i][0] !=
'-' || argv[i][1] == 0 || DashDashFound) {
1602 if (ActivePositionalArg) {
1607 if (!PositionalOpts.empty()) {
1613 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
1614 for (++i; i < argc; ++i)
1622 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
1624 DashDashFound =
true;
1626 }
else if (ActivePositionalArg &&
1634 HaveDoubleDash =
true;
1636 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1637 LongOptionsUseDoubleDash, HaveDoubleDash);
1646 HaveDoubleDash =
true;
1648 Handler = LookupLongOption(*ChosenSubCommand, ArgName,
Value,
1649 LongOptionsUseDoubleDash, HaveDoubleDash);
1656 LongOptionsUseDoubleDash, HaveDoubleDash);
1659 if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
1665 if (!Handler && SinkOpts.empty())
1670 if (!SinkOpts.empty()) {
1671 for (
Option *SinkOpt : SinkOpts)
1672 SinkOpt->addOccurrence(i,
"",
StringRef(argv[i]));
1676 auto ReportUnknownArgument = [&](
bool IsArg,
1678 *Errs << ProgramName <<
": Unknown "
1679 << (IsArg ?
"command line argument" :
"subcommand") <<
" '"
1680 << argv[i] <<
"'. Try: '" << argv[0] <<
" --help'\n";
1682 if (NearestArgumentName.empty())
1685 *Errs << ProgramName <<
": Did you mean '";
1687 *Errs << PrintArg(NearestArgumentName, 0);
1689 *Errs << NearestArgumentName;
1693 if (i > 1 || !MaybeNamedSubCommand)
1694 ReportUnknownArgument(
true, NearestHandlerString);
1696 ReportUnknownArgument(
false, NearestSubCommandString);
1698 ErrorParsing =
true;
1706 Handler->
error(
"This argument does not take a value.\n"
1707 "\tInstead, it consumes any positional arguments until "
1708 "the next recognized option.", *Errs);
1709 ErrorParsing =
true;
1711 ActivePositionalArg = Handler;
1718 if (NumPositionalRequired > PositionalVals.
size()) {
1719 *Errs << ProgramName
1720 <<
": Not enough positional command line arguments specified!\n"
1721 <<
"Must specify at least " << NumPositionalRequired
1722 <<
" positional argument" << (NumPositionalRequired > 1 ?
"s" :
"")
1723 <<
": See: " << argv[0] <<
" --help\n";
1725 ErrorParsing =
true;
1726 }
else if (!HasUnlimitedPositionals &&
1727 PositionalVals.
size() > PositionalOpts.size()) {
1728 *Errs << ProgramName <<
": Too many positional arguments specified!\n"
1729 <<
"Can specify at most " << PositionalOpts.size()
1730 <<
" positional arguments: See: " << argv[0] <<
" --help\n";
1731 ErrorParsing =
true;
1733 }
else if (!ConsumeAfterOpt) {
1735 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1736 for (
Option *Opt : PositionalOpts) {
1739 PositionalVals[ValNo].second);
1741 --NumPositionalRequired;
1749 while (NumVals - ValNo > NumPositionalRequired && !
Done) {
1757 PositionalVals[ValNo].second);
1762 "positional argument processing!");
1767 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1769 for (
Option *Opt : PositionalOpts)
1772 Opt, PositionalVals[ValNo].first, PositionalVals[ValNo].second);
1781 if (PositionalOpts.size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1783 PositionalVals[ValNo].first,
1784 PositionalVals[ValNo].second);
1790 for (; ValNo != PositionalVals.
size(); ++ValNo)
1793 PositionalVals[ValNo].second);
1797 for (
const auto &Opt : OptionsMap) {
1802 Opt.second->
error(
"must be specified at least once!");
1803 ErrorParsing =
true;
1815 for (
int i = 0; i < argc; ++i)
dbgs() << argv[i] <<
' ';
1836 if (!ArgName.
data())
1838 if (ArgName.
empty())
1841 Errs <<
GlobalParser->ProgramName <<
": for the " << PrintArg(ArgName, 0);
1843 Errs <<
" option: " << Message <<
"\n";
1852 return handleOccurrence(pos, ArgName,
Value);
1859 if (O.ValueStr.empty())
1869size_t alias::getOptionWidth()
const {
1874 size_t FirstLineIndentedBy) {
1875 assert(Indent >= FirstLineIndentedBy);
1876 std::pair<StringRef, StringRef> Split =
HelpStr.
split(
'\n');
1879 while (!Split.second.empty()) {
1880 Split = Split.second.split(
'\n');
1881 outs().
indent(Indent) << Split.first <<
"\n";
1886 size_t FirstLineIndentedBy) {
1888 assert(BaseIndent >= FirstLineIndentedBy);
1889 std::pair<StringRef, StringRef> Split =
HelpStr.
split(
'\n');
1890 outs().
indent(BaseIndent - FirstLineIndentedBy)
1892 while (!Split.second.empty()) {
1893 Split = Split.second.split(
'\n');
1894 outs().
indent(BaseIndent + ValHelpPrefix.
size()) << Split.first <<
"\n";
1899void alias::printOptionInfo(
size_t GlobalWidth)
const {
1915 if (!ValName.empty()) {
1916 size_t FormattingLen = 3;
1929 size_t GlobalWidth)
const {
1930 outs() << PrintArg(O.ArgStr);
1933 if (!ValName.empty()) {
1939 outs() << (O.ArgStr.size() == 1 ?
" <" :
"=<") <<
getValueStr(O, ValName)
1948 size_t GlobalWidth)
const {
1949 outs() << PrintArg(O.ArgStr);
1950 outs().
indent(GlobalWidth - O.ArgStr.size());
1957 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1963 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1967 return O.error(
"'" + Arg +
1968 "' is invalid value for boolean argument! Try 0 or 1");
1975 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1980 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1985 return O.error(
"'" + Arg +
1986 "' is invalid value for boolean argument! Try 0 or 1");
1994 return O.error(
"'" + Arg +
"' value invalid for integer argument!");
2003 return O.error(
"'" + Arg +
"' value invalid for long argument!");
2012 return O.error(
"'" + Arg +
"' value invalid for llong argument!");
2022 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
2029 unsigned long &
Value) {
2032 return O.error(
"'" + Arg +
"' value invalid for ulong argument!");
2040 unsigned long long &
Value) {
2043 return O.error(
"'" + Arg +
"' value invalid for ullong argument!");
2050 if (to_float(Arg,
Value))
2052 return O.error(
"'" + Arg +
"' value invalid for floating point argument!");
2078 for (
unsigned i = 0; i != e; ++i) {
2095 !Description.
empty();
2100 if (O.hasArgStr()) {
2112 size_t BaseSize = 0;
2123 size_t GlobalWidth)
const {
2124 if (O.hasArgStr()) {
2130 outs() << PrintArg(O.ArgStr);
2149 if (OptionName.
empty()) {
2154 if (!Description.
empty())
2160 if (!O.HelpStr.empty())
2161 outs() <<
" " << O.HelpStr <<
'\n';
2178 outs() <<
" " << PrintArg(O.ArgStr);
2179 outs().
indent(GlobalWidth - O.ArgStr.size());
2182 for (
unsigned i = 0; i != NumOpts; ++i) {
2190 for (
unsigned j = 0; j != NumOpts; ++j) {
2199 outs() <<
"= *unknown option value*\n";
2204#define PRINT_OPT_DIFF(T) \
2205 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
2206 size_t GlobalWidth) const { \
2207 printOptionName(O, GlobalWidth); \
2210 raw_string_ostream SS(Str); \
2213 outs() << "= " << Str; \
2214 size_t NumSpaces = \
2215 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
2216 outs().indent(NumSpaces) << " (default: "; \
2218 outs() << D.getValue(); \
2220 outs() << "*no default*"; \
2238 size_t GlobalWidth)
const {
2239 printOptionName(O, GlobalWidth);
2240 outs() <<
"= " << V;
2244 outs() <<
D.getValue();
2246 outs() <<
"*no default*";
2252 size_t GlobalWidth)
const {
2254 outs() <<
"= *cannot print option value*\n";
2262 const std::pair<const char *, Option *> *RHS) {
2263 return strcmp(
LHS->first,
RHS->first);
2267 const std::pair<const char *, SubCommand *> *RHS) {
2268 return strcmp(
LHS->first,
RHS->first);
2284 if (
I->second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
2288 if (!OptionSet.
insert(
I->second).second)
2292 std::pair<const char *, Option *>(
I->getKey().data(),
I->second));
2302 for (
auto *S : SubMap) {
2303 if (S->getName().empty())
2305 Subs.push_back(std::make_pair(S->getName().data(), S));
2314 const bool ShowHidden;
2316 StrOptionPairVector;
2318 StrSubCommandPairVector;
2320 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
2321 for (
size_t i = 0, e = Opts.size(); i != e; ++i)
2322 Opts[i].second->printOptionInfo(MaxArgLen);
2325 void printSubCommands(StrSubCommandPairVector &Subs,
size_t MaxSubLen) {
2326 for (
const auto &S : Subs) {
2327 outs() <<
" " << S.first;
2328 if (!S.second->getDescription().empty()) {
2330 outs() <<
" - " << S.second->getDescription();
2337 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
2338 virtual ~HelpPrinter() =
default;
2341 void operator=(
bool Value) {
2356 StrOptionPairVector Opts;
2357 sortOpts(OptionsMap, Opts, ShowHidden);
2359 StrSubCommandPairVector Subs;
2368 outs() <<
" [subcommand]";
2369 outs() <<
" [options]";
2379 for (
auto *Opt : PositionalOpts) {
2386 if (ConsumeAfterOpt)
2387 outs() <<
" " << ConsumeAfterOpt->HelpStr;
2391 size_t MaxSubLen = 0;
2392 for (
size_t i = 0, e = Subs.size(); i != e; ++i)
2393 MaxSubLen = std::max(MaxSubLen, strlen(Subs[i].first));
2396 outs() <<
"SUBCOMMANDS:\n\n";
2397 printSubCommands(Subs, MaxSubLen);
2400 <<
" <subcommand> --help\" to get more help on a specific "
2407 size_t MaxArgLen = 0;
2408 for (
size_t i = 0, e = Opts.size(); i != e; ++i)
2409 MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
2411 outs() <<
"OPTIONS:\n";
2412 printOptions(Opts, MaxArgLen);
2421class CategorizedHelpPrinter :
public HelpPrinter {
2423 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
2431 return (*A)->getName().compare((*B)->getName());
2435 using HelpPrinter::operator=;
2438 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
2439 std::vector<OptionCategory *> SortedCategories;
2445 SortedCategories.push_back(Category);
2448 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
2450 OptionCategoryCompare);
2455 for (
size_t I = 0, E = Opts.size();
I != E; ++
I) {
2459 "Option has an unregistered category");
2460 CategorizedOptions[Cat].push_back(Opt);
2467 const auto &CategoryOptions = CategorizedOptions[Category];
2468 if (CategoryOptions.empty())
2482 for (
const Option *Opt : CategoryOptions)
2490class HelpPrinterWrapper {
2492 HelpPrinter &UncategorizedPrinter;
2493 CategorizedHelpPrinter &CategorizedPrinter;
2496 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
2497 CategorizedHelpPrinter &CategorizedPrinter)
2498 : UncategorizedPrinter(UncategorizedPrinter),
2499 CategorizedPrinter(CategorizedPrinter) {}
2502 void operator=(
bool Value);
2507#if defined(__GNUC__)
2510# if defined(__OPTIMIZE__)
2511# define LLVM_IS_DEBUG_BUILD 0
2513# define LLVM_IS_DEBUG_BUILD 1
2515#elif defined(_MSC_VER)
2520# define LLVM_IS_DEBUG_BUILD 1
2522# define LLVM_IS_DEBUG_BUILD 0
2526# define LLVM_IS_DEBUG_BUILD 0
2530class VersionPrinter {
2532 void print(std::vector<VersionPrinterTy> ExtraPrinters = {}) {
2534#ifdef PACKAGE_VENDOR
2535 OS << PACKAGE_VENDOR <<
" ";
2537 OS <<
"LLVM (http://llvm.org/):\n ";
2539 OS << PACKAGE_NAME <<
" version " << PACKAGE_VERSION <<
"\n ";
2540#if LLVM_IS_DEBUG_BUILD
2541 OS <<
"DEBUG build";
2543 OS <<
"Optimized build";
2546 OS <<
" with assertions";
2552 if (!ExtraPrinters.empty()) {
2553 for (
const auto &
I : ExtraPrinters)
2557 void operator=(
bool OptionWasSpecified);
2560struct CommandLineCommonOptions {
2563 HelpPrinter UncategorizedNormalPrinter{
false};
2564 HelpPrinter UncategorizedHiddenPrinter{
true};
2565 CategorizedHelpPrinter CategorizedNormalPrinter{
false};
2566 CategorizedHelpPrinter CategorizedHiddenPrinter{
true};
2569 HelpPrinterWrapper WrappedNormalPrinter{UncategorizedNormalPrinter,
2570 CategorizedNormalPrinter};
2571 HelpPrinterWrapper WrappedHiddenPrinter{UncategorizedHiddenPrinter,
2572 CategorizedHiddenPrinter};
2582 "Display list of available options (--help-list-hidden for more)"),
2591 cl::desc(
"Display list of all available options"),
2603 cl::desc(
"Display available options (--help-hidden for more)"),
2614 cl::desc(
"Display all available options"),
2623 cl::desc(
"Print non-default options after command line parsing"),
2630 "print-all-options",
2631 cl::desc(
"Print all option values after command line parsing"),
2639 std::vector<VersionPrinterTy> ExtraVersionPrinters;
2642 VersionPrinter VersionPrinterInstance;
2645 "version",
cl::desc(
"Display the version of this program"),
2671 return GeneralCategory;
2674void VersionPrinter::operator=(
bool OptionWasSpecified) {
2675 if (!OptionWasSpecified)
2687void HelpPrinterWrapper::operator=(
bool Value) {
2694 if (
GlobalParser->RegisteredOptionCategories.size() > 1) {
2699 CategorizedPrinter =
true;
2701 UncategorizedPrinter =
true;
2707void CommandLineParser::printOptionValues() {
2715 size_t MaxArgLen = 0;
2716 for (
size_t i = 0, e = Opts.
size(); i != e; ++i)
2717 MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
2719 for (
size_t i = 0, e = Opts.
size(); i != e; ++i)
2720 Opts[i].second->printOptionValue(MaxArgLen,
CommonOptions->PrintAllOptions);
2725 if (!
Hidden && !Categorized)
2727 else if (!
Hidden && Categorized)
2729 else if (
Hidden && !Categorized)
2741#if LLVM_IS_DEBUG_BUILD
2747#ifdef EXPENSIVE_CHECKS
2748 "+expensive-checks",
2750#if __has_feature(address_sanitizer)
2753#if __has_feature(dataflow_sanitizer)
2756#if __has_feature(hwaddress_sanitizer)
2759#if __has_feature(memory_sanitizer)
2762#if __has_feature(thread_sanitizer)
2765#if __has_feature(undefined_behavior_sanitizer)
2774#if LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG
2775 OS <<
"Build config: ";
2798 assert(Subs.contains(&Sub));
2810 bool Unrelated =
true;
2811 for (
auto &Cat :
I.second->Categories) {
2812 if (Cat == &Category || Cat == &
CommonOptions->GenericCategory)
2824 bool Unrelated =
true;
2825 for (
auto &Cat :
I.second->Categories) {
2841 const char *Overview) {
This file defines the StringMap class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling ...
static StringRef OptionPrefix
static bool RequiresValue(const Option *O)
static int SubNameCompare(const std::pair< const char *, SubCommand * > *LHS, const std::pair< const char *, SubCommand * > *RHS)
static size_t argPlusPrefixesSize(StringRef ArgName, size_t Pad=DefaultPad)
static bool isPrefixedOrGrouping(const Option *O)
static bool shouldPrintOption(StringRef Name, StringRef Description, const Option &O)
static ManagedStatic< SubCommand > AllSubCommands
static Option * HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value, bool &ErrorParsing, const StringMap< Option * > &OptionsMap)
HandlePrefixedOrGroupedOption - The specified argument string (which started with at least one '-') d...
static bool parseDouble(Option &O, StringRef Arg, double &Value)
static 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
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...
static void Help(ArrayRef< SubtargetSubTypeKV > CPUTable, 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 ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallString class.
Defines the virtual file system interface vfs::FileSystem.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
size_t size() const
size - Get the array size.
Allocate memory in an ever growing pool, as if by bump-pointer.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
This interface provides simple read-only access to a block of memory, and provides simple methods for...
size_t getBufferSize() const
const char * getBufferEnd() const
const char * getBufferStart() const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void assign(StringRef RHS)
Assign from a StringRef.
void append(StringRef RHS)
Append from a StringRef.
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static constexpr size_t npos
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
BumpPtrAllocator & getAllocator() const
StringRef save(const char *S)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
Contains options that control response file expansion.
bool findConfigFile(StringRef FileName, SmallVectorImpl< char > &FilePath)
Looks for the specified configuration file.
ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T)
Error expandResponseFiles(SmallVectorImpl< const char * > &Argv)
Expands constructs "@file" in the provided array of arguments recursively.
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
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)
StringRef getName() const
SmallVector< Option *, 4 > SinkOpts
static SubCommand & getTopLevel()
void unregisterSubCommand()
static SubCommand & getAll()
void registerSubCommand()
SmallVector< Option *, 4 > PositionalOpts
StringMap< Option * > OptionsMap
StringRef getDescription() const
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 std::optional< std::string > GetEnv(StringRef name)
virtual llvm::ErrorOr< std::string > getCurrentWorkingDirectory() const =0
Get the working directory of this file system.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
This is a convenience method that opens a file, gets its content and then closes the file.
virtual std::error_code makeAbsolute(SmallVectorImpl< char > &Path) const
Make Path an absolute path.
virtual llvm::ErrorOr< Status > status(const Twine &Path)=0
Get the status of the entry at Path, if one exists.
The result of a status operation.
bool equivalent(const Status &Other) const
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.
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
ManagedStatic< cl::opt< FnT >, OptCreatorT > Action
constexpr size_t NameSize
std::function< void(raw_ostream &)> VersionPrinterTy
void(*)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs) TokenizerCallback
String tokenization function type.
void PrintVersionMessage()
Utility function for printing version number.
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv)
A convenience helper which supports the typical use case of expansion function call.
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 ...
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.
OptionCategory & getGeneralCategory()
void ResetAllOptionOccurrences()
Reset all command line options to a state that looks as if they have never appeared on the command li...
void SetVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Override the default (LLV...
void tokenizeConfigFile(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes content of configuration file.
StringMap< Option * > & getRegisteredOptions(SubCommand &Sub=SubCommand::getTopLevel())
Use this to get a StringMap to all registered named options (e.g.
void ResetCommandLineParser()
Reset the command line parser back to its initial state.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
iterator_range< typename SmallPtrSet< SubCommand *, 4 >::iterator > getRegisteredSubcommands()
Use this to get all registered SubCommands from the provided parser.
void AddLiteralOption(Option &O, StringRef Name)
Adds a new option for parsing and provides the option it refers to.
void TokenizeWindowsCommandLineNoCopy(StringRef Source, StringSaver &Saver, SmallVectorImpl< StringRef > &NewArgv)
Tokenizes a Windows command line while attempting to avoid copies.
void printBuildConfig(raw_ostream &OS)
Prints the compiler build configuration.
bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
Parses Arg into the option handler Handler.
initializer< Ty > init(const Ty &Val)
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)
void HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub=SubCommand::getTopLevel())
Mark all options not part of this category as cl::ReallyHidden.
void AddExtraVersionPrinter(VersionPrinterTy func)
===------------------------------------------------------------------—===// Add an extra printer to u...
void PrintHelpMessage(bool Hidden=false, bool Categorized=false)
This function just prints the help message, exactly the same way as if the -help or -help-hidden opti...
void TokenizeWindowsCommandLineFull(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows full command line, including command name at the start.
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
bool has_parent_path(const Twine &path, Style style=Style::native)
Has parent path?
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
void initWithColorOptions()
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.
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 interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
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.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
@ no_such_file_or_directory
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
void initSignalsOptions()
void initTypeSizeOptions()
void initStatisticOptions()
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void initRandomSeedOptions()
void initGraphWriterOptions()
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
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.