diff options
-rw-r--r-- | include/llvm/Support/CommandLine.h | 9 | ||||
-rw-r--r-- | lib/Support/CommandLine.cpp | 25 |
2 files changed, 31 insertions, 3 deletions
diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index d609871..ba8fbee 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -59,6 +59,15 @@ void ParseEnvironmentOptions(const char *progName, const char *envvar, /// CommandLine utilities to print their own version string. void SetVersionPrinter(void (*func)()); +///===---------------------------------------------------------------------===// +/// AddExtraVersionPrinter - Add an extra printer to use in addition to the +/// default one. This can be called multiple times, +/// and each time it adds a new function to the list +/// which will be called after the basic LLVM version +/// printing is complete. Each can then add additional +/// information specific to the tool. +void AddExtraVersionPrinter(void (*func)()); + // PrintOptionValues - Print option values. // With -print-options print the difference between option values and defaults. diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 2914337..368cef9 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); +} |