diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-18 02:11:26 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-18 02:11:26 +0000 |
commit | 510d73200ec48496a2b10703385fe99b51e31fa5 (patch) | |
tree | a4b62172cb653f5fbf72eb6f0ec6301ce729cacb /tools/driver/driver.cpp | |
parent | c57bc595cf7d4e3a5219d30fc20653d595e16ffe (diff) |
Driver: Use custom diag printer to drop dependency on libFrontend and
libLex.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67155 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/driver/driver.cpp')
-rw-r--r-- | tools/driver/driver.cpp | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index 0724fbd08c..fac4403251 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -17,8 +17,7 @@ #include "clang/Driver/Option.h" #include "clang/Driver/Options.h" -#include "clang/Frontend/TextDiagnosticPrinter.h" - +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/Config/config.h" #include "llvm/Support/ManagedStatic.h" @@ -29,20 +28,52 @@ using namespace clang; using namespace clang::driver; +class DriverDiagnosticPrinter : public DiagnosticClient { + std::string ProgName; + llvm::raw_ostream &OS; + +public: + DriverDiagnosticPrinter(const std::string _ProgName, + llvm::raw_ostream &_OS) + : ProgName(_ProgName), + OS(_OS) {} + + virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, + const DiagnosticInfo &Info); +}; + +void DriverDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, + const DiagnosticInfo &Info) { + OS << ProgName << ": "; + + switch (Level) { + case Diagnostic::Ignored: assert(0 && "Invalid diagnostic type"); + case Diagnostic::Note: OS << "note: "; break; + case Diagnostic::Warning: OS << "warning: "; break; + case Diagnostic::Error: OS << "error: "; break; + case Diagnostic::Fatal: OS << "fatal error: "; break; + } + + llvm::SmallString<100> OutStr; + Info.FormatDiagnostic(OutStr); + OS.write(OutStr.begin(), OutStr.size()); + OS << '\n'; +} + int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); llvm::PrettyStackTraceProgram X(argc, argv); - llvm::OwningPtr<DiagnosticClient> - DiagClient(new TextDiagnosticPrinter(llvm::errs())); - - Diagnostic Diags(DiagClient.get()); - // FIXME: We should use GetMainExecutable here, probably, but we may // want to handle symbolic links slightly differently. The problem // is that the path derived from this will influence search paths. llvm::sys::Path Path(argv[0]); + llvm::OwningPtr<DiagnosticClient> + DiagClient(new DriverDiagnosticPrinter(Path.getBasename(), llvm::errs())); + + Diagnostic Diags(DiagClient.get()); + // FIXME: Use the triple of the host, not the triple that we were // compiled on. llvm::OwningPtr<Driver> TheDriver(new Driver(Path.getBasename().c_str(), |