27 #include "llvm/Config/config.h"
42 #define DEBUG_TYPE "commandline"
68 void GenericOptionValue::anchor() {}
71 void Option::anchor() {}
87 class CommandLineParser {
91 std::string ProgramName;
92 const char *ProgramOverview;
95 std::vector<const char *> MoreHelp;
106 CommandLineParser() : ProgramOverview(nullptr), ConsumeAfterOpt(nullptr) {}
109 const char *Overview);
111 void addLiteralOption(
Option &Opt,
const char *
Name) {
113 if (!OptionsMap.
insert(std::make_pair(Name, &Opt)).second) {
114 errs() << ProgramName <<
": CommandLine Error: Option '" << Name
115 <<
"' registered more than once!\n";
121 void addOption(
Option *O) {
122 bool HadErrors =
false;
125 if (!OptionsMap.
insert(std::make_pair(O->
ArgStr, O)).second) {
126 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr
127 <<
"' registered more than once!\n";
138 if (ConsumeAfterOpt) {
139 O->
error(
"Cannot specify more than one option with cl::ConsumeAfter!");
153 void removeOption(
Option *O) {
158 for (
auto Name : OptionNames)
162 for (
auto Opt = PositionalOpts.
begin(); Opt != PositionalOpts.
end();
165 PositionalOpts.
erase(Opt);
170 for (
auto Opt = SinkOpts.
begin(); Opt != SinkOpts.
end(); ++Opt) {
176 else if (O == ConsumeAfterOpt)
177 ConsumeAfterOpt =
nullptr;
181 return (!OptionsMap.
empty() || !PositionalOpts.
empty() ||
182 nullptr != ConsumeAfterOpt);
185 void updateArgStr(
Option *O,
const char *NewName) {
186 if (!OptionsMap.
insert(std::make_pair(NewName, O)).second) {
187 errs() << ProgramName <<
": CommandLine Error: Option '" << O->
ArgStr
188 <<
"' registered more than once!\n";
194 void printOptionValues();
197 assert(std::count_if(RegisteredOptionCategories.
begin(),
198 RegisteredOptionCategories.
end(),
200 return cat->
getName() == Category->getName();
202 "Duplicate option categories");
204 RegisteredOptionCategories.
insert(cat);
239 void OptionCategory::registerCategory() {
255 size_t EqualPos = Arg.
find(
'=');
261 return I != OptionsMap.
end() ? I->
second :
nullptr;
268 if (I == OptionsMap.
end())
271 Value = Arg.
substr(EqualPos + 1);
272 Arg = Arg.
substr(0, EqualPos);
282 std::string &NearestString) {
288 std::pair<StringRef, StringRef> SplitArg = Arg.
split(
'=');
294 unsigned BestDistance = 0;
296 ie = OptionsMap.
end();
306 for (
size_t i = 0, e = OptionNames.
size(); i != e; ++i) {
309 Flag,
true, BestDistance);
310 if (!Best || Distance < BestDistance) {
312 BestDistance = Distance;
313 if (RHS.
empty() || !PermitValue)
314 NearestString = OptionNames[i];
316 NearestString = (
Twine(OptionNames[i]) +
"=" + RHS).str();
328 bool MultiArg =
false) {
340 Val = Val.
substr(Pos + 1);
360 const char *
const *argv,
int &i) {
369 return Handler->
error(
"requires a value!");
371 assert(argv &&
"null check");
376 if (NumAdditionalVals > 0)
377 return Handler->
error(
"multi-valued option specified"
378 " with ValueDisallowed modifier!");
381 return Handler->
error(
"does not allow a value! '" +
Twine(Value) +
389 if (NumAdditionalVals == 0)
393 bool MultiArg =
false;
402 while (NumAdditionalVals > 0) {
404 return Handler->
error(
"not enough values!");
405 assert(argv &&
"null check");
436 bool (*Pred)(
const Option *),
444 while (OMI == OptionsMap.
end() && Name.
size() > 1) {
446 OMI = OptionsMap.
find(Name);
449 if (OMI != OptionsMap.
end() && Pred(OMI->
second)) {
450 Length = Name.
size();
477 Value = Arg.
substr(Length);
478 Arg = Arg.
substr(0, Length);
479 assert(OptionsMap.
count(Arg) && OptionsMap.
find(Arg)->second == PGOpt);
485 assert(
isGrouping(PGOpt) &&
"Broken getOptionPred!");
495 "Option can not be cl::Grouping AND cl::ValueRequired!");
502 }
while (PGOpt && Length != Arg.
size());
520 static bool isQuote(
char C) {
return C ==
'\"' || C ==
'\''; }
528 for (
size_t I = 0, E = Src.
size(); I != E; ++
I) {
533 if (MarkEOLs && Src[I] ==
'\n')
543 if (I + 1 < E && Src[I] ==
'\\' &&
isGNUSpecial(Src[I + 1])) {
551 char Quote = Src[I++];
552 while (I != E && Src[I] != Quote) {
554 if (Src[I] ==
'\\' && I + 1 != E &&
isGNUSpecial(Src[I + 1]))
602 size_t E = Src.
size();
603 int BackslashCount = 0;
608 }
while (I != E && Src[I] ==
'\\');
610 bool FollowedByDoubleQuote = (I != E && Src[
I] ==
'"');
611 if (FollowedByDoubleQuote) {
612 Token.
append(BackslashCount / 2,
'\\');
613 if (BackslashCount % 2 == 0)
618 Token.
append(BackslashCount,
'\\');
629 enum {
INIT, UNQUOTED, QUOTED } State =
INIT;
630 for (
size_t I = 0, E = Src.
size(); I != E; ++
I) {
636 if (MarkEOLs && Src[I] ==
'\n')
644 if (Src[I] ==
'\\') {
656 if (State == UNQUOTED) {
663 if (MarkEOLs && Src[I] ==
'\n')
671 if (Src[I] ==
'\\') {
680 if (State == QUOTED) {
685 if (Src[I] ==
'\\') {
703 return (S.
size() >= 3 && S[0] ==
'\xef' && S[1] ==
'\xbb' && S[2] ==
'\xbf');
709 bool MarkEOLs =
false) {
729 Str =
StringRef(BufRef.data() + 3, BufRef.size() - 3);
732 Tokenizer(Str, Saver, NewArgv, MarkEOLs);
742 unsigned RspFiles = 0;
743 bool AllExpanded =
true;
746 for (
unsigned I = 0; I != Argv.
size();) {
747 const char *Arg = Argv[
I];
749 if (Arg ==
nullptr) {
788 const char *Overview) {
790 assert(progName &&
"Program name not specified");
791 assert(envVar &&
"Environment variable name missing");
794 const char *envValue = getenv(envVar);
808 int newArgc =
static_cast<int>(newArgv.
size());
813 const char *Overview) {
814 GlobalParser->ParseCommandLineOptions(argc, argv, Overview);
818 const char *
const *argv,
819 const char *Overview) {
820 assert(hasOptions() &&
"No options specified!");
828 argc =
static_cast<int>(newArgv.size());
833 ProgramOverview = Overview;
834 bool ErrorParsing =
false;
837 unsigned NumPositionalRequired = 0;
840 bool HasUnlimitedPositionals =
false;
842 if (ConsumeAfterOpt) {
843 assert(PositionalOpts.
size() > 0 &&
844 "Cannot specify cl::ConsumeAfter without a positional argument!");
846 if (!PositionalOpts.
empty()) {
849 bool UnboundedFound =
false;
850 for (
size_t i = 0, e = PositionalOpts.
size(); i != e; ++i) {
851 Option *Opt = PositionalOpts[i];
853 ++NumPositionalRequired;
854 else if (ConsumeAfterOpt) {
857 if (PositionalOpts.
size() > 1)
858 ErrorParsing |= Opt->
error(
859 "error - this positional option will never be matched, "
860 "because it does not Require a value, and a "
861 "cl::ConsumeAfter option is active!");
862 }
else if (UnboundedFound && !Opt->
ArgStr[0]) {
867 ErrorParsing |= Opt->
error(
"error - option can never match, because "
868 "another positional argument will match an "
869 "unbounded number of values, and this option"
870 " does not require a value!");
871 errs() << ProgramName <<
": CommandLine Error: Option '" << Opt->
ArgStr
872 <<
"' is all messed up!\n";
877 HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
888 Option *ActivePositionalArg =
nullptr;
891 bool DashDashFound =
false;
892 for (
int i = 1; i < argc; ++i) {
893 Option *Handler =
nullptr;
894 Option *NearestHandler =
nullptr;
895 std::string NearestHandlerString;
903 if (argv[i][0] !=
'-' || argv[i][1] == 0 || DashDashFound) {
905 if (ActivePositionalArg) {
910 if (!PositionalOpts.
empty()) {
911 PositionalVals.
push_back(std::make_pair(argv[i], i));
916 if (PositionalVals.
size() >= NumPositionalRequired && ConsumeAfterOpt) {
917 for (++i; i < argc; ++i)
918 PositionalVals.
push_back(std::make_pair(argv[i], i));
925 }
else if (argv[i][0] ==
'-' && argv[i][1] ==
'-' && argv[i][2] == 0 &&
927 DashDashFound =
true;
929 }
else if (ActivePositionalArg &&
934 ArgName = argv[i] + 1;
936 while (!ArgName.
empty() && ArgName[0] ==
'-')
937 ArgName = ArgName.
substr(1);
939 Handler = LookupOption(ArgName, Value);
946 ArgName = argv[i] + 1;
948 while (!ArgName.
empty() && ArgName[0] ==
'-')
949 ArgName = ArgName.
substr(1);
951 Handler = LookupOption(ArgName, Value);
960 if (!Handler && SinkOpts.
empty())
966 if (SinkOpts.
empty()) {
967 errs() << ProgramName <<
": Unknown command line argument '" << argv[i]
968 <<
"'. Try: '" << argv[0] <<
" -help'\n";
970 if (NearestHandler) {
972 errs() << ProgramName <<
": Did you mean '-" << NearestHandlerString
981 (*I)->addOccurrence(i,
"", argv[i]);
989 ActivePositionalArg = Handler;
991 ErrorParsing |=
ProvideOption(Handler, ArgName, Value, argc, argv, i);
995 if (NumPositionalRequired > PositionalVals.
size()) {
996 errs() << ProgramName
997 <<
": Not enough positional command line arguments specified!\n"
998 <<
"Must specify at least " << NumPositionalRequired
999 <<
" positional arguments: See: " << argv[0] <<
" -help\n";
1001 ErrorParsing =
true;
1002 }
else if (!HasUnlimitedPositionals &&
1003 PositionalVals.
size() > PositionalOpts.
size()) {
1004 errs() << ProgramName <<
": Too many positional arguments specified!\n"
1005 <<
"Can specify at most " << PositionalOpts.
size()
1006 <<
" positional arguments: See: " << argv[0] <<
" -help\n";
1007 ErrorParsing =
true;
1009 }
else if (!ConsumeAfterOpt) {
1011 unsigned ValNo = 0, NumVals =
static_cast<unsigned>(PositionalVals.
size());
1012 for (
size_t i = 0, e = PositionalOpts.
size(); i != e; ++i) {
1015 PositionalVals[ValNo].second);
1017 --NumPositionalRequired;
1024 bool Done = PositionalOpts[i]->getNumOccurrencesFlag() ==
cl::Required;
1025 while (NumVals - ValNo > NumPositionalRequired && !Done) {
1026 switch (PositionalOpts[i]->getNumOccurrencesFlag()) {
1033 PositionalVals[ValNo].first,
1034 PositionalVals[ValNo].second);
1039 "positional argument processing!");
1044 assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.
size());
1046 for (
size_t j = 1, e = PositionalOpts.
size(); j != e; ++j)
1049 PositionalVals[ValNo].first,
1050 PositionalVals[ValNo].second);
1059 if (PositionalOpts.
size() == 1 && ValNo == 0 && !PositionalVals.
empty()) {
1061 PositionalVals[ValNo].first,
1062 PositionalVals[ValNo].second);
1068 for (; ValNo != PositionalVals.
size(); ++ValNo)
1071 PositionalVals[ValNo].second);
1075 for (
const auto &Opt : OptionsMap) {
1080 Opt.second->
error(
"must be specified at least once!");
1081 ErrorParsing =
true;
1093 for (
int i = 0; i < argc; ++i)
dbgs() << argv[i] <<
' ';
1110 if (!ArgName.
data())
1112 if (ArgName.
empty())
1117 errs() <<
" option: " << Message <<
"\n";
1128 if (NumOccurrences > 1)
1129 return error(
"may only occur zero or one times!", ArgName);
1132 if (NumOccurrences > 1)
1133 return error(
"must occur exactly one time!", ArgName);
1141 return handleOccurrence(pos, ArgName, Value);
1158 size_t alias::getOptionWidth()
const {
return std::strlen(
ArgStr) + 6; }
1161 size_t FirstLineIndentedBy) {
1162 std::pair<StringRef, StringRef>
Split = HelpStr.
split(
'\n');
1163 outs().
indent(Indent - FirstLineIndentedBy) <<
" - " << Split.first <<
"\n";
1164 while (!Split.second.empty()) {
1165 Split = Split.second.split(
'\n');
1166 outs().
indent(Indent) << Split.first <<
"\n";
1171 void alias::printOptionInfo(
size_t GlobalWidth)
const {
1185 size_t Len = std::strlen(O.
ArgStr);
1196 size_t GlobalWidth)
const {
1206 size_t GlobalWidth)
const {
1215 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1221 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1225 return O.
error(
"'" + Arg +
1226 "' is invalid value for boolean argument! Try 0 or 1");
1233 if (Arg ==
"" || Arg ==
"true" || Arg ==
"TRUE" || Arg ==
"True" ||
1238 if (Arg ==
"false" || Arg ==
"FALSE" || Arg ==
"False" || Arg ==
"0") {
1243 return O.
error(
"'" + Arg +
1244 "' is invalid value for boolean argument! Try 0 or 1");
1252 return O.
error(
"'" + Arg +
"' value invalid for integer argument!");
1262 return O.
error(
"'" + Arg +
"' value invalid for uint argument!");
1270 unsigned long long &Value) {
1273 return O.
error(
"'" + Arg +
"' value invalid for uint argument!");
1281 const char *ArgStart = TmpStr.
c_str();
1283 Value = strtod(ArgStart, &End);
1285 return O.
error(
"'" + Arg +
"' value invalid for floating point argument!");
1312 for (
unsigned i = 0; i != e; ++i) {
1322 size_t Size = std::strlen(O.
ArgStr) + 6;
1324 Size = std::max(Size, std::strlen(
getOption(i)) + 8);
1327 size_t BaseSize = 0;
1329 BaseSize = std::max(BaseSize, std::strlen(
getOption(i)) + 8);
1338 size_t GlobalWidth)
const {
1344 size_t NumSpaces = GlobalWidth - strlen(
getOption(i)) - 8;
1353 outs() <<
" -" << Option;
1371 for (
unsigned i = 0; i != NumOpts; ++i) {
1379 for (
unsigned j = 0; j != NumOpts; ++j) {
1388 outs() <<
"= *unknown option value*\n";
1393 #define PRINT_OPT_DIFF(T) \
1394 void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
1395 size_t GlobalWidth) const { \
1396 printOptionName(O, GlobalWidth); \
1399 raw_string_ostream SS(Str); \
1402 outs() << "= " << Str; \
1403 size_t NumSpaces = \
1404 MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
1405 outs().indent(NumSpaces) << " (default: "; \
1407 outs() << D.getValue(); \
1409 outs() << "*no default*"; \
1424 size_t GlobalWidth)
const {
1425 printOptionName(O, GlobalWidth);
1426 outs() <<
"= " << V;
1430 outs() << D.getValue();
1432 outs() <<
"*no default*";
1438 size_t GlobalWidth)
const {
1440 outs() <<
"= *cannot print option value*\n";
1448 const std::pair<const char *, Option *> *RHS) {
1449 return strcmp(LHS->first, RHS->first);
1465 if (I->
second->getOptionHiddenFlag() ==
Hidden && !ShowHidden)
1484 const bool ShowHidden;
1486 StrOptionPairVector;
1488 virtual void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen) {
1489 for (
size_t i = 0, e = Opts.size(); i != e; ++i)
1490 Opts[i].second->printOptionInfo(MaxArgLen);
1494 explicit HelpPrinter(
bool showHidden) : ShowHidden(showHidden) {}
1495 virtual ~HelpPrinter() {}
1498 void operator=(
bool Value) {
1502 StrOptionPairVector Opts;
1523 size_t MaxArgLen = 0;
1524 for (
size_t i = 0, e = Opts.size(); i != e; ++i)
1525 MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
1527 outs() <<
"OPTIONS:\n";
1528 printOptions(Opts, MaxArgLen);
1540 class CategorizedHelpPrinter :
public HelpPrinter {
1542 explicit CategorizedHelpPrinter(
bool showHidden) : HelpPrinter(showHidden) {}
1549 return strcmp((*A)->getName(), (*B)->getName());
1553 using HelpPrinter::operator=;
1556 void printOptions(StrOptionPairVector &Opts,
size_t MaxArgLen)
override {
1557 std::vector<OptionCategory *> SortedCategories;
1558 std::map<OptionCategory *, std::vector<Option *>> CategorizedOptions;
1562 for (
auto I =
GlobalParser->RegisteredOptionCategories.begin(),
1565 SortedCategories.push_back(*I);
1569 assert(SortedCategories.size() > 0 &&
"No option categories registered!");
1571 OptionCategoryCompare);
1574 for (std::vector<OptionCategory *>::const_iterator
1575 I = SortedCategories.begin(),
1576 E = SortedCategories.end();
1578 CategorizedOptions[*I] = std::vector<Option *>();
1583 for (
size_t I = 0, E = Opts.size(); I != E; ++
I) {
1585 assert(CategorizedOptions.count(Opt->
Category) > 0 &&
1586 "Option has an unregistered category");
1587 CategorizedOptions[Opt->
Category].push_back(Opt);
1591 for (std::vector<OptionCategory *>::const_iterator
1592 Category = SortedCategories.begin(),
1593 E = SortedCategories.end();
1594 Category != E; ++Category) {
1596 bool IsEmptyCategory = CategorizedOptions[*Category].size() == 0;
1597 if (!ShowHidden && IsEmptyCategory)
1602 outs() << (*Category)->getName() <<
":\n";
1605 if ((*Category)->getDescription() !=
nullptr)
1606 outs() << (*Category)->getDescription() <<
"\n\n";
1612 if (IsEmptyCategory) {
1613 outs() <<
" This option category has no options.\n";
1617 for (std::vector<Option *>::const_iterator
1618 Opt = CategorizedOptions[*Category].
begin(),
1619 E = CategorizedOptions[*Category].
end();
1621 (*Opt)->printOptionInfo(MaxArgLen);
1628 class HelpPrinterWrapper {
1630 HelpPrinter &UncategorizedPrinter;
1631 CategorizedHelpPrinter &CategorizedPrinter;
1634 explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
1635 CategorizedHelpPrinter &CategorizedPrinter)
1636 : UncategorizedPrinter(UncategorizedPrinter),
1637 CategorizedPrinter(CategorizedPrinter) {}
1640 void operator=(
bool Value);
1667 cl::desc(
"Display list of available options (-help-list-hidden for more)"),
1672 HLHOp(
"help-list-hidden",
cl::desc(
"Display list of all available options"),
1680 HOp(
"help",
cl::desc(
"Display available options (-help-hidden for more)"),
1685 HHOp(
"help-hidden",
cl::desc(
"Display all available options"),
1691 cl::desc(
"Print non-default options after command line parsing"),
1695 "print-all-options",
1699 void HelpPrinterWrapper::operator=(
bool Value) {
1706 if (
GlobalParser->RegisteredOptionCategories.size() > 1) {
1711 CategorizedPrinter =
true;
1713 UncategorizedPrinter =
true;
1719 void CommandLineParser::printOptionValues() {
1723 SmallVector<std::pair<const char *, Option *>, 128> Opts;
1727 size_t MaxArgLen = 0;
1728 for (
size_t i = 0, e = Opts.
size(); i != e; ++i)
1729 MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
1731 for (
size_t i = 0, e = Opts.
size(); i != e; ++i)
1740 class VersionPrinter {
1744 OS <<
"LLVM (http://llvm.org/):\n"
1745 <<
" " << PACKAGE_NAME <<
" version " << PACKAGE_VERSION;
1746 #ifdef LLVM_VERSION_INFO
1747 OS <<
" " << LLVM_VERSION_INFO;
1750 #ifndef __OPTIMIZE__
1751 OS <<
"DEBUG build";
1753 OS <<
"Optimized build";
1756 OS <<
" with assertions";
1759 if (CPU ==
"generic")
1762 #if (ENABLE_TIMESTAMPS == 1)
1763 <<
" Built " << __DATE__ <<
" (" << __TIME__ <<
").\n"
1766 <<
" Host CPU: " << CPU <<
'\n';
1768 void operator=(
bool OptionWasSpecified) {
1769 if (!OptionWasSpecified)
1773 (*OverrideVersionPrinter)();
1797 VersOp(
"version",
cl::desc(
"Display the version of this program"),
1810 if (!Hidden && !Categorized)
1812 else if (!Hidden && Categorized)
1814 else if (Hidden && !Categorized)
1838 if (I.second->Category != &Category &&
1845 auto CategoriesBegin = Categories.
begin();
1846 auto CategoriesEnd = Categories.
end();
1848 if (std::find(CategoriesBegin, CategoriesEnd, I.second->Category) ==
1856 const char *Overview) {
const char * getName() const
static bool ExpandResponseFile(const char *FName, StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
static cl::opt< HelpPrinterWrapper, true, parser< bool > > HHOp("help-hidden", cl::desc("Display all available options"), cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory))
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
void(* TokenizerCallback)(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs)
String tokenization function type.
Represents either an error or a value T.
static bool isQuote(char C)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
OptionCategory GeneralCategory
StringMap< Option * > & getRegisteredOptions()
Use this to get a StringMap to all registered named options (e.g.
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 void Help(ArrayRef< SubtargetFeatureKV > CPUTable, ArrayRef< SubtargetFeatureKV > FeatTable)
Display help for feature choices.
static bool isPrefixedOrGrouping(const Option *O)
static bool parseDouble(Option &O, StringRef Arg, double &Value)
void ParseEnvironmentOptions(const char *progName, const char *envvar, const char *Overview=nullptr)
ParseEnvironmentOptions - An alternative entry point to the CommandLine library, which allows you to ...
size_t size() const
size - Get the string size.
const char * getBufferStart() const
static bool isGrouping(const Option *O)
virtual const GenericOptionValue & getOptionValue(unsigned N) const =0
void PrintVersionMessage()
Utility function for printing version number.
static cl::opt< VersionPrinter, true, parser< bool > > VersOp("version", cl::desc("Display the version of this program"), cl::location(VersionPrinterInstance), cl::ValueDisallowed, cl::cat(GenericCategory))
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static void printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy)
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
#define PRINT_OPT_DIFF(T)
static cl::opt< bool > PrintOptions("print-options", cl::desc("Print non-default options after command line parsing"), cl::Hidden, cl::init(false), cl::cat(GenericCategory))
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
iterator find(StringRef Key)
unsigned findOption(const char *Name)
void printOptionName(const Option &O, size_t GlobalWidth) const
const_iterator begin(StringRef path)
Get begin iterator over path.
void SetVersionPrinter(void(*func)())
===------------------------------------------------------------------—===// SetVersionPrinter - Overr...
static HelpPrinter UncategorizedHiddenPrinter(true)
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv, bool MarkEOLs=false)
Expand response files on a command line recursively using the given StringSaver and tokenization stra...
static cl::opt< HelpPrinterWrapper, true, parser< bool > > HOp("help", cl::desc("Display available options (-help-hidden for more)"), cl::location(WrappedNormalPrinter), cl::ValueDisallowed, cl::cat(GenericCategory))
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
virtual void printOptionInfo(const Option &O, size_t GlobalWidth) const
void LLVMParseCommandLineOptions(int argc, const char *const *argv, const char *Overview)
This function parses the given arguments using the LLVM command line parser.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const size_t MaxOptWidth
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V, const OptionValue< DT > &Default, size_t GlobalWidth)
static VersionPrinter VersionPrinterInstance
static cl::OptionCategory GenericCategory("Generic Options")
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
static int OptNameCompare(const std::pair< const char *, Option * > *LHS, const std::pair< const char *, Option * > *RHS)
virtual bool compare(const GenericOptionValue &V) const =0
virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
void printOptionInfo(const Option &O, size_t GlobalWidth) const
void AddExtraVersionPrinter(void(*func)())
===------------------------------------------------------------------—===// AddExtraVersionPrinter - ...
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 HelpPrinter UncategorizedNormalPrinter(false)
static ManagedStatic< CommandLineParser > GlobalParser
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
int getNumOccurrences() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
size_t size() const
size - Get the array size.
static bool hasUTF8ByteOrderMark(ArrayRef< char > S)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
static bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i)
void append(in_iter S, in_iter E)
Append from an iterator pair.
void HideUnrelatedOptions(cl::OptionCategory &Category)
Mark all options not part of this category as cl::ReallyHidden.
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
StringRef filename(StringRef path)
Get filename.
initializer< Ty > init(const Ty &Val)
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
size_t getOptionWidth(const Option &O) const
Allocate memory in an ever growing pool, as if by bump-pointer.
bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V)
static void sortOpts(StringMap< Option * > &OptMap, SmallVectorImpl< std::pair< const char *, Option * >> &Opts, bool ShowHidden)
enum NumOccurrencesFlag getNumOccurrencesFlag() const
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...
const char * save(const char *S)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a Windows command line which may contain quotes and escaped quotes.
virtual unsigned getNumOptions() const =0
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...
OptionCategory * Category
static bool EatsUnboundedNumberOfValues(const Option *O)
static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false)
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling ...
iterator erase(iterator I)
void TokenizeGNUCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a command line that can contain escapes and quotes.
void printGenericOptionDiff(const Option &O, const GenericOptionValue &V, const GenericOptionValue &Default, size_t GlobalWidth) const
unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
void printOptionNoValue(const Option &O, size_t GlobalWidth) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
enum FormattingFlags getFormattingFlag() const
virtual const char * getOption(unsigned N) const =0
static HelpPrinterWrapper WrappedNormalPrinter(UncategorizedNormalPrinter, CategorizedNormalPrinter)
static cl::opt< HelpPrinter, true, parser< bool > > HLHOp("help-list-hidden", cl::desc("Display list of all available options"), cl::location(UncategorizedHiddenPrinter), cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory))
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static const char * getValueStr(const Option &O, const char *DefaultMsg)
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...
virtual void getExtraOptionNames(SmallVectorImpl< const char * > &)
virtual size_t getOptionWidth(const Option &O) const
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static bool isWhitespace(char C)
void ParseCommandLineOptions(int argc, const char *const *argv, const char *Overview=nullptr)
static void(* OverrideVersionPrinter)()
static bool isGNUSpecial(char C)
static bool RequiresValue(const Option *O)
static cl::opt< HelpPrinter, true, parser< bool > > HLOp("help-list", cl::desc("Display list of available options (-help-list-hidden for more)"), cl::location(UncategorizedNormalPrinter), cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory))
iterator insert(iterator I, T &&Elt)
size_t getBufferSize() const
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
unsigned getNumAdditionalVals() const
enum ValueExpected getValueExpectedFlag() const
Saves strings in the inheritor's stable storage and returns a stable raw character pointer...
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
static CategorizedHelpPrinter CategorizedNormalPrinter(false)
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
void removeArgument()
Unregisters this option from the CommandLine system.
static cl::opt< bool > PrintAllOptions("print-all-options", cl::desc("Print all option values after command line parsing"), cl::Hidden, cl::init(false), cl::cat(GenericCategory))
void setArgStr(const char *S)
virtual const char * getValueName() const
virtual const char * getDescription(unsigned N) const =0
const char * getBufferEnd() const
LLVM Value Representation.
bool hasUTF16ByteOrderMark(ArrayRef< char > S)
This class implements an extremely fast bulk output stream that can only output to a stream...
static Option * getOptionPred(StringRef Name, size_t &Length, bool(*Pred)(const Option *), const StringMap< Option * > &OptionsMap)
static CategorizedHelpPrinter CategorizedHiddenPrinter(true)
void AddLiteralOption(Option &O, const char *Name)
Adds a new option for parsing and provides the option it refers to.
static std::vector< void(*)()> * ExtraVersionPrinters
bool error(const Twine &Message, StringRef ArgName=StringRef())
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static void Split(std::vector< std::string > &V, StringRef S)
Split - Splits a string of comma separated items in to a vector of strings.
static HelpPrinterWrapper WrappedHiddenPrinter(UncategorizedHiddenPrinter, CategorizedHiddenPrinter)
LocationClass< Ty > location(Ty &L)
unsigned getMiscFlags() const
bool empty() const
empty - Check if the string is empty.