diff options
author | Dimitry Andric <dimitry@andric.com> | 2017-06-06 21:54:04 +0000 |
---|---|---|
committer | Dimitry Andric <dimitry@andric.com> | 2017-06-06 21:54:04 +0000 |
commit | bc3feaaa884021ee3d76b70a3a2a2617eb261148 (patch) | |
tree | e09038c6ea8a10329be5ddf4ed2da8091f1793a7 /llvm/lib/Support/CommandLine.cpp | |
parent | ff9d80cc7a602001b5528b57fdc5632b6f251032 (diff) | |
download | bcm5719-llvm-bc3feaaa884021ee3d76b70a3a2a2617eb261148.tar.gz bcm5719-llvm-bc3feaaa884021ee3d76b70a3a2a2617eb261148.zip |
Allow VersionPrinter to print to arbitrary raw_ostreams
Summary:
I would like to add printing of registered targets to clang's version
information. For this to work correctly, the VersionPrinter logic in
CommandLine.cpp should support printing to arbitrary raw_ostreams,
instead of always defaulting to outs().
Add a raw_ostream& parameter to the function pointer type used for
VersionPrinter, and while doing so, introduce a typedef for convenience.
Note that VersionPrinter::print() will still default to using outs(),
the clang part will necessarily go into a separate review.
Reviewers: beanz, chandlerc, dberris, mehdi_amini, zturner
Reviewed By: mehdi_amini
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D33899
llvm-svn: 304835
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 34345901eab..de0ca940b40 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -2042,9 +2042,9 @@ void CommandLineParser::printOptionValues() { Opts[i].second->printOptionValue(MaxArgLen, PrintAllOptions); } -static void (*OverrideVersionPrinter)() = nullptr; +static VersionPrinterTy OverrideVersionPrinter = nullptr; -static std::vector<void (*)()> *ExtraVersionPrinters = nullptr; +static std::vector<VersionPrinterTy> *ExtraVersionPrinters = nullptr; namespace { class VersionPrinter { @@ -2084,7 +2084,7 @@ public: return; if (OverrideVersionPrinter != nullptr) { - (*OverrideVersionPrinter)(); + OverrideVersionPrinter(outs()); exit(0); } print(); @@ -2093,10 +2093,8 @@ public: // information. if (ExtraVersionPrinters != nullptr) { outs() << '\n'; - for (std::vector<void (*)()>::iterator I = ExtraVersionPrinters->begin(), - E = ExtraVersionPrinters->end(); - I != E; ++I) - (*I)(); + for (auto I : *ExtraVersionPrinters) + I(outs()); } exit(0); @@ -2134,11 +2132,11 @@ void cl::PrintHelpMessage(bool Hidden, bool Categorized) { /// Utility function for printing version number. void cl::PrintVersionMessage() { VersionPrinterInstance.print(); } -void cl::SetVersionPrinter(void (*func)()) { OverrideVersionPrinter = func; } +void cl::SetVersionPrinter(VersionPrinterTy func) { OverrideVersionPrinter = func; } -void cl::AddExtraVersionPrinter(void (*func)()) { +void cl::AddExtraVersionPrinter(VersionPrinterTy func) { if (!ExtraVersionPrinters) - ExtraVersionPrinters = new std::vector<void (*)()>; + ExtraVersionPrinters = new std::vector<VersionPrinterTy>; ExtraVersionPrinters->push_back(func); } |