LLVM API Documentation
#include "llvm/Support/CommandLine.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/config.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <cerrno>
#include <cstdlib>
#include <map>
#include <system_error>
Go to the source code of this file.
Namespaces | |
namespace | llvm |
List of target independent CodeGen pass IDs. | |
namespace | llvm::cl |
Defines | |
#define | DEBUG_TYPE "commandline" |
#define | PRINT_OPT_DIFF(T) |
Typedefs | |
typedef SmallPtrSet < OptionCategory *, 16 > | OptionCatSet |
Functions | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< bool >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< boolOrDefault >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< int >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< unsigned >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< unsigned long long >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< double >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< float >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< std::string >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class basic_parser< char >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class opt< unsigned >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class opt< int >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class opt< std::string >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class opt< char >) | |
llvm::cl::TEMPLATE_INSTANTIATION (class opt< bool >) | |
static void | GetOptionInfo (SmallVectorImpl< Option * > &PositionalOpts, SmallVectorImpl< Option * > &SinkOpts, StringMap< Option * > &OptionsMap) |
static Option * | LookupOption (StringRef &Arg, StringRef &Value, const StringMap< Option * > &OptionsMap) |
static Option * | LookupNearestOption (StringRef Arg, const StringMap< Option * > &OptionsMap, std::string &NearestString) |
static bool | CommaSeparateAndAddOccurrence (Option *Handler, unsigned pos, StringRef ArgName, StringRef Value, bool MultiArg=false) |
static bool | ProvideOption (Option *Handler, StringRef ArgName, StringRef Value, int argc, const char *const *argv, int &i) |
static bool | ProvidePositionalOption (Option *Handler, StringRef Arg, int i) |
static bool | isGrouping (const Option *O) |
static bool | isPrefixedOrGrouping (const Option *O) |
static Option * | getOptionPred (StringRef Name, size_t &Length, bool(*Pred)(const Option *), const StringMap< Option * > &OptionsMap) |
static Option * | HandlePrefixedOrGroupedOption (StringRef &Arg, StringRef &Value, bool &ErrorParsing, const StringMap< Option * > &OptionsMap) |
static bool | RequiresValue (const Option *O) |
static bool | EatsUnboundedNumberOfValues (const Option *O) |
static bool | isWhitespace (char C) |
static bool | isQuote (char C) |
static bool | isGNUSpecial (char C) |
static size_t | parseBackslash (StringRef Src, size_t I, SmallString< 128 > &Token) |
static bool | ExpandResponseFile (const char *FName, StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false) |
static const char * | getValueStr (const Option &O, const char *DefaultMsg) |
static void | printHelpStr (StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy) |
static bool | parseDouble (Option &O, StringRef Arg, double &Value) |
static int | OptNameCompare (const void *LHS, const void *RHS) |
static void | sortOpts (StringMap< Option * > &OptMap, SmallVectorImpl< std::pair< const char *, Option * > > &Opts, bool ShowHidden) |
static HelpPrinter | UncategorizedNormalPrinter (false) |
static HelpPrinter | UncategorizedHiddenPrinter (true) |
static CategorizedHelpPrinter | CategorizedNormalPrinter (false) |
static CategorizedHelpPrinter | CategorizedHiddenPrinter (true) |
static HelpPrinterWrapper | WrappedNormalPrinter (UncategorizedNormalPrinter, CategorizedNormalPrinter) |
static HelpPrinterWrapper | WrappedHiddenPrinter (UncategorizedHiddenPrinter, CategorizedHiddenPrinter) |
Variables | |
static char | ProgramName [80] = "<premain>" |
static const char * | ProgramOverview = nullptr |
static ManagedStatic < std::vector< const char * > > | MoreHelp |
static bool | OptionListChanged = false |
static Option * | RegisteredOptionList = nullptr |
static ManagedStatic < OptionCatSet > | RegisteredOptionCategories |
static const size_t | MaxOptWidth = 8 |
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) |
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) |
static cl::opt < HelpPrinterWrapper, true, parser< bool > > | HOp ("help", cl::desc("Display available options (-help-hidden for more)"), cl::location(WrappedNormalPrinter), cl::ValueDisallowed) |
static cl::opt < HelpPrinterWrapper, true, parser< bool > > | HHOp ("help-hidden", cl::desc("Display all available options"), cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed) |
static cl::opt< bool > | PrintOptions ("print-options", cl::desc("Print non-default options after command line parsing"), cl::Hidden, cl::init(false)) |
static cl::opt< bool > | PrintAllOptions ("print-all-options", cl::desc("Print all option values after command line parsing"), cl::Hidden, cl::init(false)) |
static void(* | OverrideVersionPrinter )() = nullptr |
static std::vector< void(*)()> * | ExtraVersionPrinters = nullptr |
static VersionPrinter | VersionPrinterInstance |
static cl::opt< VersionPrinter, true, parser< bool > > | VersOp ("version", cl::desc("Display the version of this program"), cl::location(VersionPrinterInstance), cl::ValueDisallowed) |
#define DEBUG_TYPE "commandline" |
Definition at line 41 of file CommandLine.cpp.
#define PRINT_OPT_DIFF | ( | T | ) |
void parser<T>:: \ printOptionDiff(const Option &O, T V, OptionValue<T> D, \ size_t GlobalWidth) const { \ printOptionName(O, GlobalWidth); \ std::string Str; \ { \ raw_string_ostream SS(Str); \ SS << V; \ } \ outs() << "= " << Str; \ size_t NumSpaces = MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0;\ outs().indent(NumSpaces) << " (default: "; \ if (D.hasValue()) \ outs() << D.getValue(); \ else \ outs() << "*no default*"; \ outs() << ")\n"; \ } \
Definition at line 1373 of file CommandLine.cpp.
typedef SmallPtrSet<OptionCategory*,16> OptionCatSet |
Definition at line 123 of file CommandLine.cpp.
static CategorizedHelpPrinter CategorizedHiddenPrinter | ( | true | ) | [static] |
Referenced by llvm::cl::PrintHelpMessage().
static CategorizedHelpPrinter CategorizedNormalPrinter | ( | false | ) | [static] |
Referenced by llvm::cl::PrintHelpMessage().
static bool CommaSeparateAndAddOccurrence | ( | Option * | Handler, |
unsigned | pos, | ||
StringRef | ArgName, | ||
StringRef | Value, | ||
bool | MultiArg = false |
||
) | [static] |
CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence() that does special handling of cl::CommaSeparated options.
Definition at line 274 of file CommandLine.cpp.
References llvm::cl::Option::addOccurrence(), llvm::cl::CommaSeparated, llvm::StringRef::find(), llvm::cl::Option::getMiscFlags(), llvm::StringRef::npos, and llvm::StringRef::substr().
Referenced by ProvideOption().
static bool EatsUnboundedNumberOfValues | ( | const Option * | O | ) | [static] |
Definition at line 459 of file CommandLine.cpp.
References llvm::cl::Option::getNumOccurrencesFlag(), llvm::cl::OneOrMore, and llvm::cl::ZeroOrMore.
Referenced by llvm::cl::ParseCommandLineOptions().
static bool ExpandResponseFile | ( | const char * | FName, |
StringSaver & | Saver, | ||
TokenizerCallback | Tokenizer, | ||
SmallVectorImpl< const char * > & | NewArgv, | ||
bool | MarkEOLs = false |
||
) | [static] |
Definition at line 650 of file CommandLine.cpp.
References llvm::convertUTF16ToUTF8String(), llvm::ErrorOr< T >::get(), llvm::MemoryBuffer::getBufferEnd(), llvm::MemoryBuffer::getBufferSize(), llvm::MemoryBuffer::getBufferStart(), llvm::MemoryBuffer::getFile(), and llvm::hasUTF16ByteOrderMark().
Referenced by llvm::cl::ExpandResponseFiles().
static void GetOptionInfo | ( | SmallVectorImpl< Option * > & | PositionalOpts, |
SmallVectorImpl< Option * > & | SinkOpts, | ||
StringMap< Option * > & | OptionsMap | ||
) | [static] |
GetOptionInfo - Scan the list of registered options, turning them into data structures that are easier to handle.
Definition at line 145 of file CommandLine.cpp.
References llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorImpl< T >::clear(), llvm::cl::ConsumeAfter, llvm::SmallVectorTemplateCommon< T >::end(), llvm::errs(), llvm::cl::Option::getExtraOptionNames(), llvm::cl::Option::getNextRegisteredOption(), llvm::StringMap< ValueTy, AllocatorTy >::GetOrCreateValue(), llvm::cl::Positional, ProgramName, llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), RegisteredOptionList, llvm::report_fatal_error(), llvm::StringMapEntry< ValueTy >::second, llvm::cl::Sink, and llvm::SmallVectorTemplateCommon< T, typename >::size().
Referenced by llvm::cl::getRegisteredOptions(), llvm::cl::ParseCommandLineOptions(), and llvm::cl::PrintOptionValues().
static Option* getOptionPred | ( | StringRef | Name, |
size_t & | Length, | ||
bool(*)(const Option *) | Pred, | ||
const StringMap< Option * > & | OptionsMap | ||
) | [static] |
Definition at line 382 of file CommandLine.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringMap< ValueTy, AllocatorTy >::find(), llvm::StringMapEntry< ValueTy >::second, llvm::StringRef::size(), and llvm::StringRef::substr().
Referenced by HandlePrefixedOrGroupedOption().
static const char* getValueStr | ( | const Option & | O, |
const char * | DefaultMsg | ||
) | [static] |
Definition at line 1122 of file CommandLine.cpp.
References llvm::cl::Option::ValueStr.
Referenced by llvm::cl::basic_parser_impl::getOptionWidth(), and llvm::cl::basic_parser_impl::printOptionInfo().
static Option* HandlePrefixedOrGroupedOption | ( | StringRef & | Arg, |
StringRef & | Value, | ||
bool & | ErrorParsing, | ||
const StringMap< Option * > & | OptionsMap | ||
) | [static] |
HandlePrefixedOrGroupedOption - The specified argument string (which started with at least one '-') does not fully match an available option. Check to see if this is a prefix or grouped option. If so, split arg into output an Arg/Value pair and return the Option to parse it with.
Definition at line 407 of file CommandLine.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::count(), llvm::NVPTXISD::Dummy, llvm::StringMap< ValueTy, AllocatorTy >::find(), llvm::cl::Option::getFormattingFlag(), getOptionPred(), llvm::cl::Option::getValueExpectedFlag(), isGrouping(), isPrefixedOrGrouping(), llvm::cl::Prefix, ProvideOption(), llvm::StringRef::size(), llvm::StringRef::substr(), and llvm::cl::ValueRequired.
Referenced by llvm::cl::ParseCommandLineOptions().
static bool isGNUSpecial | ( | char | C | ) | [static] |
Definition at line 472 of file CommandLine.cpp.
References llvm::LibFunc::strchr.
Referenced by llvm::cl::TokenizeGNUCommandLine().
static bool isGrouping | ( | const Option * | O | ) | [inline, static] |
Definition at line 369 of file CommandLine.cpp.
References llvm::cl::Option::getFormattingFlag(), and llvm::cl::Grouping.
Referenced by HandlePrefixedOrGroupedOption(), and isPrefixedOrGrouping().
static bool isPrefixedOrGrouping | ( | const Option * | O | ) | [inline, static] |
Definition at line 372 of file CommandLine.cpp.
References llvm::cl::Option::getFormattingFlag(), isGrouping(), and llvm::cl::Prefix.
Referenced by HandlePrefixedOrGroupedOption().
Definition at line 468 of file CommandLine.cpp.
Referenced by llvm::cl::TokenizeGNUCommandLine().
static bool isWhitespace | ( | char | C | ) | [static] |
Definition at line 464 of file CommandLine.cpp.
References llvm::LibFunc::strchr.
Referenced by llvm::cl::TokenizeGNUCommandLine(), and llvm::cl::TokenizeWindowsCommandLine().
static Option* LookupNearestOption | ( | StringRef | Arg, |
const StringMap< Option * > & | OptionsMap, | ||
std::string & | NearestString | ||
) | [static] |
LookupNearestOption - Lookup the closest match to the option specified by the specified option on the command line. If there is a value specified (after an equal sign) return that as well. This assumes that leading dashes have already been stripped.
Definition at line 230 of file CommandLine.cpp.
References llvm::cl::Option::ArgStr, llvm::StringMap< ValueTy, AllocatorTy >::begin(), llvm::StringRef::edit_distance(), llvm::StringRef::empty(), llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::cl::Option::getExtraOptionNames(), llvm::cl::Option::getValueExpectedFlag(), Name, llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::StringRef::split(), llvm::StringRef::str(), and llvm::cl::ValueDisallowed.
Referenced by llvm::cl::ParseCommandLineOptions().
static Option* LookupOption | ( | StringRef & | Arg, |
StringRef & | Value, | ||
const StringMap< Option * > & | OptionsMap | ||
) | [static] |
LookupOption - Lookup the option specified by the specified option on the command line. If there is a value specified (after an equal sign) return that as well. This assumes that leading dashes have already been stripped.
Definition at line 201 of file CommandLine.cpp.
References llvm::StringRef::empty(), llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringRef::find(), llvm::StringMap< ValueTy, AllocatorTy >::find(), I, llvm::StringRef::npos, llvm::StringMapEntry< ValueTy >::second, and llvm::StringRef::substr().
Referenced by llvm::cl::ParseCommandLineOptions().
static int OptNameCompare | ( | const void * | LHS, |
const void * | RHS | ||
) | [static] |
Definition at line 1427 of file CommandLine.cpp.
References llvm::LibFunc::strcmp.
Referenced by sortOpts().
static size_t parseBackslash | ( | StringRef | Src, |
size_t | I, | ||
SmallString< 128 > & | Token | ||
) | [static] |
Backslashes are interpreted in a rather complicated way in the Windows-style command line, because backslashes are used both to separate path and to escape double quote. This method consumes runs of backslashes as well as the following double quote if it's escaped.
If an even number of backslashes is followed by a double quote, one backslash is output for every pair of backslashes, and the last double quote remains unconsumed. The double quote will later be interpreted as the start or end of a quoted string in the main loop outside of this function.
If an odd number of backslashes is followed by a double quote, one backslash is output for every pair of backslashes, and a double quote is output for the last pair of backslash-double quote. The double quote is consumed in this case.
Otherwise, backslashes are interpreted literally.
Definition at line 551 of file CommandLine.cpp.
References llvm::SmallString< InternalLen >::append(), I, llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), and llvm::StringRef::size().
Referenced by llvm::cl::TokenizeWindowsCommandLine().
static bool parseDouble | ( | Option & | O, |
StringRef | Arg, | ||
double & | Value | ||
) | [static] |
Definition at line 1255 of file CommandLine.cpp.
References llvm::StringRef::begin(), llvm::SmallString< InternalLen >::c_str(), llvm::StringRef::end(), llvm::cl::Option::error(), and llvm::LibFunc::strtod.
static void printHelpStr | ( | StringRef | HelpStr, |
size_t | Indent, | ||
size_t | FirstLineIndentedBy | ||
) | [static] |
Definition at line 1136 of file CommandLine.cpp.
References llvm::raw_ostream::indent(), llvm::outs(), Split(), and llvm::StringRef::split().
Referenced by llvm::cl::generic_parser_base::printOptionInfo(), and llvm::cl::basic_parser_impl::printOptionInfo().
static bool ProvideOption | ( | Option * | Handler, |
StringRef | ArgName, | ||
StringRef | Value, | ||
int | argc, | ||
const char *const * | argv, | ||
int & | i | ||
) | [inline, static] |
ProvideOption - For Value, this differentiates between an empty value ("") and a null value (StringRef()). The later is accepted for arguments that don't allow a value (-foo) the former is rejected (-foo=).
Definition at line 306 of file CommandLine.cpp.
References CommaSeparateAndAddOccurrence(), llvm::StringRef::data(), llvm::cl::Option::error(), llvm::cl::Option::getNumAdditionalVals(), llvm::cl::Option::getValueExpectedFlag(), llvm::cl::ValueDisallowed, llvm::cl::ValueOptional, and llvm::cl::ValueRequired.
Referenced by HandlePrefixedOrGroupedOption(), llvm::cl::ParseCommandLineOptions(), and ProvidePositionalOption().
static bool ProvidePositionalOption | ( | Option * | Handler, |
StringRef | Arg, | ||
int | i | ||
) | [static] |
Definition at line 362 of file CommandLine.cpp.
References llvm::cl::Option::ArgStr, llvm::NVPTXISD::Dummy, and ProvideOption().
Referenced by llvm::cl::ParseCommandLineOptions().
static bool RequiresValue | ( | const Option * | O | ) | [static] |
Definition at line 454 of file CommandLine.cpp.
References llvm::cl::Option::getNumOccurrencesFlag(), llvm::cl::OneOrMore, and llvm::cl::Required.
Referenced by llvm::cl::ParseCommandLineOptions().
static void sortOpts | ( | StringMap< Option * > & | OptMap, |
SmallVectorImpl< std::pair< const char *, Option * > > & | Opts, | ||
bool | ShowHidden | ||
) | [static] |
Definition at line 1435 of file CommandLine.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::begin(), llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::cl::Hidden, I, llvm::SmallPtrSetImpl< PtrType >::insert(), OptNameCompare(), llvm::LibFunc::qsort, and llvm::cl::ReallyHidden.
Referenced by llvm::cl::PrintOptionValues().
static HelpPrinter UncategorizedHiddenPrinter | ( | true | ) | [static] |
Referenced by llvm::cl::PrintHelpMessage().
static HelpPrinter UncategorizedNormalPrinter | ( | false | ) | [static] |
Referenced by llvm::cl::PrintHelpMessage().
static HelpPrinterWrapper WrappedHiddenPrinter | ( | UncategorizedHiddenPrinter | , |
CategorizedHiddenPrinter | |||
) | [static] |
static HelpPrinterWrapper WrappedNormalPrinter | ( | UncategorizedNormalPrinter | , |
CategorizedNormalPrinter | |||
) | [static] |
std::vector<void (*)()>* ExtraVersionPrinters = nullptr [static] |
Definition at line 1730 of file CommandLine.cpp.
Referenced by llvm::cl::AddExtraVersionPrinter().
cl::opt<HelpPrinterWrapper, true, parser<bool> > HHOp("help-hidden", cl::desc("Display all available options"), cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed) [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) [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) [static] |
cl::opt<HelpPrinterWrapper, true, parser<bool> > HOp("help", cl::desc("Display available options (-help-hidden for more)"), cl::location(WrappedNormalPrinter), cl::ValueDisallowed) [static] |
const size_t MaxOptWidth = 8 [static] |
Definition at line 1338 of file CommandLine.cpp.
Referenced by llvm::cl::generic_parser_base::printGenericOptionDiff().
ManagedStatic<std::vector<const char*> > MoreHelp [static] |
Definition at line 89 of file CommandLine.cpp.
Referenced by llvm::cl::extrahelp::extrahelp(), and llvm::cl::ParseCommandLineOptions().
bool OptionListChanged = false [static] |
Definition at line 96 of file CommandLine.cpp.
Referenced by llvm::cl::MarkOptionsChanged(), and llvm::cl::ParseCommandLineOptions().
void(* OverrideVersionPrinter)() = nullptr [static] |
Definition at line 1728 of file CommandLine.cpp.
Referenced by llvm::cl::SetVersionPrinter().
cl::opt<bool> PrintAllOptions("print-all-options", cl::desc("Print all option values after command line parsing"), cl::Hidden, cl::init(false)) [static] |
Referenced by llvm::cl::PrintOptionValues().
cl::opt<bool> PrintOptions("print-options", cl::desc("Print non-default options after command line parsing"), cl::Hidden, cl::init(false)) [static] |
Referenced by llvm::cl::PrintOptionValues().
char ProgramName[80] = "<premain>" [static] |
Definition at line 85 of file CommandLine.cpp.
Referenced by llvm::cl::Option::error(), GetOptionInfo(), and llvm::cl::ParseCommandLineOptions().
const char* ProgramOverview = nullptr [static] |
Definition at line 86 of file CommandLine.cpp.
Referenced by llvm::cl::ParseCommandLineOptions().
Definition at line 124 of file CommandLine.cpp.
Option* RegisteredOptionList = nullptr [static] |
RegisteredOptionList - This is the list of the command line options that have statically constructed themselves.
Definition at line 105 of file CommandLine.cpp.
Referenced by llvm::cl::Option::addArgument(), GetOptionInfo(), and llvm::cl::Option::removeArgument().
VersionPrinter VersionPrinterInstance [static] |
Definition at line 1786 of file CommandLine.cpp.
Referenced by llvm::cl::PrintVersionMessage().