summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/CommandLine.cpp
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
commitea7e55272c7bdfdffc6f8b5bc8adc0f01574eb10 (patch)
tree9cf2bd974f716e5895b8302c6798e179d6406ea5 /llvm/lib/Support/CommandLine.cpp
parent516a79e32c6a17bb74f266b9aa36bbf51a767e09 (diff)
downloadbcm5719-llvm-ea7e55272c7bdfdffc6f8b5bc8adc0f01574eb10.tar.gz
bcm5719-llvm-ea7e55272c7bdfdffc6f8b5bc8adc0f01574eb10.zip
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. llvm-svn: 135755
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r--llvm/lib/Support/CommandLine.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 29143377628..368cef91cf5 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/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);
+}
OpenPOWER on IntegriCloud