summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-07-22 07:50:40 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-07-22 07:50:40 +0000
commit6d51d26a2479069f85a7676f664d6f998fc49a16 (patch)
tree520bafd4b49131af91ce39c8aa894e61d6504b3e /lib/Support
parent12b2772578103952fb623b551fcaeb3cce069467 (diff)
downloadllvm-6d51d26a2479069f85a7676f664d6f998fc49a16.tar.gz
llvm-6d51d26a2479069f85a7676f664d6f998fc49a16.tar.bz2
llvm-6d51d26a2479069f85a7676f664d6f998fc49a16.tar.xz
Add an extension point to the CommandLine library where clients can
register extra version information to be printed. This is designed to allow those tools which link in various targets to also print those registered targets under --version. Currently this printing logic is embedded into the Support library directly; a huge layering violation. This is the first step to hoisting it out into the tools without adding lots of duplicated code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135755 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/CommandLine.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index 2914337762..368cef91cf 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -1330,6 +1330,8 @@ void cl::PrintOptionValues() {
static void (*OverrideVersionPrinter)() = 0;
+static std::vector<void (*)()>* ExtraVersionPrinters = 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);
@@ -1387,11 +1389,21 @@ public:
void operator=(bool OptionWasSpecified) {
if (!OptionWasSpecified) return;
- if (OverrideVersionPrinter == 0) {
- print();
+ if (OverrideVersionPrinter != 0) {
+ (*OverrideVersionPrinter)();
exit(1);
}
- (*OverrideVersionPrinter)();
+ print();
+
+ // Iterate over any registered extra printers and call them to add further
+ // information.
+ if (ExtraVersionPrinters != 0) {
+ for (std::vector<void (*)()>::iterator I = ExtraVersionPrinters->begin(),
+ E = ExtraVersionPrinters->end();
+ I != E; ++I)
+ (*I)();
+ }
+
exit(1);
}
};
@@ -1424,3 +1436,10 @@ void cl::PrintVersionMessage() {
void cl::SetVersionPrinter(void (*func)()) {
OverrideVersionPrinter = func;
}
+
+void cl::AddExtraVersionPrinter(void (*func)()) {
+ if (ExtraVersionPrinters == 0)
+ ExtraVersionPrinters = new std::vector<void (*)()>;
+
+ ExtraVersionPrinters->push_back(func);
+}