mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-24 20:44:51 +00:00
Make it possible to override the standard version printer. Not all tools
built with CommandLine.h will want the --version option to report that the tool belongs to LLVM. To override simply pass a void func() to the cl::SetVersionPrinter() function and that void func() will be called when it is time to print the version information. llvm-svn: 28687
This commit is contained in:
parent
f640054d89
commit
24f0a4a816
@ -48,6 +48,13 @@ void ParseCommandLineOptions(int &argc, char **argv,
|
||||
void ParseEnvironmentOptions(const char *progName, const char *envvar,
|
||||
const char *Overview = 0);
|
||||
|
||||
///===---------------------------------------------------------------------===//
|
||||
/// SetVersionPrinter - Override the default (LLVM specific) version printer
|
||||
/// used to print out the version when --version is given
|
||||
/// on the command line. This gives other systems using the
|
||||
/// CommandLine utilities to print their own version string.
|
||||
void SetVersionPrinter(void (*func)());
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Flags permitted to be passed to command line arguments
|
||||
//
|
||||
|
@ -951,24 +951,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class VersionPrinter {
|
||||
public:
|
||||
void operator=(bool OptionWasSpecified) {
|
||||
if (OptionWasSpecified) {
|
||||
std::cout << "Low Level Virtual Machine (" << PACKAGE_NAME << ") "
|
||||
<< PACKAGE_VERSION << " (see http://llvm.org/)";
|
||||
#ifndef NDEBUG
|
||||
std::cout << " ASSERTIONS ENABLED\n";
|
||||
#else
|
||||
std::cout << "\n";
|
||||
#endif
|
||||
getOpts().clear(); // Don't bother making option dtors remove from map.
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Define the two HelpPrinter instances that are used to print out help, or
|
||||
// help-hidden...
|
||||
//
|
||||
@ -983,6 +965,31 @@ cl::opt<HelpPrinter, true, parser<bool> >
|
||||
HHOp("help-hidden", cl::desc("Display all available options"),
|
||||
cl::location(HiddenPrinter), cl::Hidden, cl::ValueDisallowed);
|
||||
|
||||
void (*OverrideVersionPrinter)() = 0;
|
||||
|
||||
class VersionPrinter {
|
||||
public:
|
||||
void operator=(bool OptionWasSpecified) {
|
||||
if (OptionWasSpecified) {
|
||||
if (OverrideVersionPrinter == 0) {
|
||||
std::cout << "Low Level Virtual Machine (" << PACKAGE_NAME << ") "
|
||||
<< PACKAGE_VERSION << " (see http://llvm.org/)";
|
||||
#ifndef NDEBUG
|
||||
std::cout << " ASSERTIONS ENABLED\n";
|
||||
#else
|
||||
std::cout << "\n";
|
||||
#endif
|
||||
getOpts().clear(); // Don't bother making option dtors remove from map.
|
||||
exit(1);
|
||||
} else {
|
||||
(*OverrideVersionPrinter)();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Define the --version option that prints out the LLVM version for the tool
|
||||
VersionPrinter VersionPrinterInstance;
|
||||
cl::opt<VersionPrinter, true, parser<bool> >
|
||||
@ -1002,3 +1009,7 @@ void cl::PrintHelpMessage() {
|
||||
// to make it look like --help was given, so we assign true.
|
||||
NormalPrinter = true;
|
||||
}
|
||||
|
||||
void cl::SetVersionPrinter(void (*func)()) {
|
||||
OverrideVersionPrinter = func;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user