"llvm/lib/git@repo.hca.bsc.es:rferrer/llvm-epi-0.8.git" did not exist on "aba48dd34cbf48b319723fc1521dcdbde37a2271"
Newer
Older
outs() << " -" << getOption(i);
outs().indent(GlobalWidth-L-8) << " - " << getDescription(i) << '\n';
}
}
//===----------------------------------------------------------------------===//
// --help and --help-hidden option implementation
static int OptNameCompare(const void *LHS, const void *RHS) {
typedef std::pair<const char *, Option*> pair_ty;
return strcmp(((pair_ty*)LHS)->first, ((pair_ty*)RHS)->first);
}
const Option *EmptyArg;
const bool ShowHidden;
explicit HelpPrinter(bool showHidden) : ShowHidden(showHidden) {
EmptyArg = 0;
}
void operator=(bool Value) {
if (Value == false) return;
Chris Lattner
committed
// Get all the options.
std::vector<Option*> PositionalOpts;
std::vector<Option*> SinkOpts;
StringMap<Option*> OptMap;
GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
// Copy Options into a vector so we can sort them as we like.
SmallVector<std::pair<const char *, Option*>, 128> Opts;
Chris Lattner
committed
SmallPtrSet<Option*, 128> OptionSet; // Duplicate option detection.
for (StringMap<Option*>::iterator I = OptMap.begin(), E = OptMap.end();
I != E; ++I) {
Chris Lattner
committed
// Ignore really-hidden options.
if (I->second->getOptionHiddenFlag() == ReallyHidden)
continue;
// Unless showhidden is set, ignore hidden flags.
if (I->second->getOptionHiddenFlag() == Hidden && !ShowHidden)
continue;
Chris Lattner
committed
// If we've already seen this option, don't add it to the list again.
if (!OptionSet.insert(I->second))
Chris Lattner
committed
continue;
Opts.push_back(std::pair<const char *, Option*>(I->getKey().data(),
I->second));
// Sort the options list alphabetically.
qsort(Opts.data(), Opts.size(), sizeof(Opts[0]), OptNameCompare);
outs() << "OVERVIEW: " << ProgramOverview << "\n";
outs() << "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])
outs() << " --" << PositionalOpts[i]->ArgStr;
outs() << " " << PositionalOpts[i]->HelpStr;
// Print the consume after option info if it exists...
if (CAOpt) outs() << " " << CAOpt->HelpStr;
// 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());
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)
} // 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;
static int TargetArraySortFn(const void *LHS, const void *RHS) {
typedef std::pair<const char *, const Target*> pair_ty;
return strcmp(((const pair_ty*)LHS)->first, ((const pair_ty*)RHS)->first);
}
namespace {
class VersionPrinter {
public:
void print() {
Benjamin Kramer
committed
outs() << "Low Level Virtual Machine (http://llvm.org/):\n"
<< " " << PACKAGE_NAME << " version " << PACKAGE_VERSION;
Benjamin Kramer
committed
outs() << LLVM_VERSION_INFO;
Benjamin Kramer
committed
outs() << "\n ";
Benjamin Kramer
committed
outs() << "DEBUG build";
#else
Benjamin Kramer
committed
outs() << "Optimized build";
Benjamin Kramer
committed
outs() << " with assertions";
#endif
Benjamin Kramer
committed
outs() << ".\n"
<< " Built " << __DATE__ << " (" << __TIME__ << ").\n"
<< " Host: " << sys::getHostTriple() << '\n'
Benjamin Kramer
committed
<< "\n"
<< " Registered Targets:\n";
std::vector<std::pair<const char *, const Target*> > Targets;
Benjamin Kramer
committed
size_t Width = 0;
for (TargetRegistry::iterator it = TargetRegistry::begin(),
ie = TargetRegistry::end(); it != ie; ++it) {
Targets.push_back(std::make_pair(it->getName(), &*it));
Width = std::max(Width, strlen(Targets.back().first));
Benjamin Kramer
committed
}
if (!Targets.empty())
qsort(&Targets[0], Targets.size(), sizeof(Targets[0]),
TargetArraySortFn);
Benjamin Kramer
committed
for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
outs() << " " << Targets[i].first;
outs().indent(Width - strlen(Targets[i].first)) << " - "
<< Targets[i].second->getShortDescription() << '\n';
Benjamin Kramer
committed
}
if (Targets.empty())
outs() << " (none)\n";
}
void operator=(bool OptionWasSpecified) {
if (!OptionWasSpecified) return;
if (OverrideVersionPrinter == 0) {
print();
exit(1);
}
(*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;
}