Newer
Older
GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
// Copy Options into a vector so we can sort them as we like...
std::vector<std::pair<std::string, Option*> > Opts;
Chris Lattner
committed
copy(OptMap.begin(), OptMap.end(), std::back_inserter(Opts));
// Eliminate Hidden or ReallyHidden arguments, depending on ShowHidden
Opts.erase(std::remove_if(Opts.begin(), Opts.end(),
std::ptr_fun(ShowHidden ? isReallyHidden : isHidden)),
Opts.end());
// Eliminate duplicate entries in table (from enum flags options, f.e.)
{ // Give OptionSet a scope
std::set<Option*> OptionSet;
for (unsigned i = 0; i != Opts.size(); ++i)
if (OptionSet.count(Opts[i].second) == 0)
OptionSet.insert(Opts[i].second); // Add new entry to set
Opts.erase(Opts.begin()+i--); // Erase duplicate
cout << "OVERVIEW: " << ProgramOverview << "\n";
Bill Wendling
committed
cout << "USAGE: " << ProgramName << " [options]";
Option *CAOpt = 0; // The cl::ConsumeAfter option, if it exists...
if (!PositionalOpts.empty() &&
Chris Lattner
committed
PositionalOpts[0]->getNumOccurrencesFlag() == ConsumeAfter)
CAOpt = PositionalOpts[0];
for (size_t i = CAOpt != 0, e = PositionalOpts.size(); i != e; ++i) {
Chris Lattner
committed
if (PositionalOpts[i]->ArgStr[0])
cout << " --" << PositionalOpts[i]->ArgStr;
cout << " " << PositionalOpts[i]->HelpStr;
// Print the consume after option info if it exists...
Bill Wendling
committed
if (CAOpt) cout << " " << CAOpt->HelpStr;
Bill Wendling
committed
cout << "\n\n";
// Compute the maximum argument length...
MaxArgLen = 0;
for (size_t i = 0, e = Opts.size(); i != e; ++i)
MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth());
Bill Wendling
committed
cout << "OPTIONS:\n";
for (size_t i = 0, e = Opts.size(); i != e; ++i)
Opts[i].second->printOptionInfo(MaxArgLen);
// Print any extra help the user has declared.
for (std::vector<const char *>::iterator I = MoreHelp->begin(),
E = MoreHelp->end(); I != E; ++I)
Bill Wendling
committed
cout << *I;
} // End anonymous namespace
// Define the two HelpPrinter instances that are used to print out help, or
// help-hidden...
//
static HelpPrinter NormalPrinter(false);
static HelpPrinter HiddenPrinter(true);
static cl::opt<HelpPrinter, true, parser<bool> >
HOp("help", cl::desc("Display available options (--help-hidden for more)"),
cl::location(NormalPrinter), cl::ValueDisallowed);
static cl::opt<HelpPrinter, true, parser<bool> >
HHOp("help-hidden", cl::desc("Display all available options"),
cl::location(HiddenPrinter), cl::Hidden, cl::ValueDisallowed);
static void (*OverrideVersionPrinter)() = 0;
namespace {
class VersionPrinter {
public:
void print() {
Bill Wendling
committed
cout << "Low Level Virtual Machine (http://llvm.org/):\n";
cout << " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
Bill Wendling
committed
cout << LLVM_VERSION_INFO;
Bill Wendling
committed
cout << "\n ";
Bill Wendling
committed
cout << "DEBUG build";
#else
Bill Wendling
committed
cout << "Optimized build";
Bill Wendling
committed
cout << " with assertions";
#endif
Bill Wendling
committed
cout << ".\n";
}
void operator=(bool OptionWasSpecified) {
if (OptionWasSpecified) {
if (OverrideVersionPrinter == 0) {
print();
exit(1);
} else {
(*OverrideVersionPrinter)();
exit(1);
}
}
}
};
} // End anonymous namespace
// Define the --version option that prints out the LLVM version for the tool
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);
// Utility function for printing the help message.
void cl::PrintHelpMessage() {
// This looks weird, but it actually prints the help message. The
// NormalPrinter variable is a HelpPrinter and the help gets printed when
// its operator= is invoked. That's because the "normal" usages of the
// help printer is to be assigned true/false depending on whether the
// --help option was given or not. Since we're circumventing that we have
// to make it look like --help was given, so we assign true.
/// Utility function for printing version number.
void cl::PrintVersionMessage() {
VersionPrinterInstance.print();
}
void cl::SetVersionPrinter(void (*func)()) {
OverrideVersionPrinter = func;
}