[cfe-commits] r67155 - in /cfe/trunk/tools/driver: Makefile driver.cpp

Daniel Dunbar daniel at zuster.org
Tue Mar 17 19:11:26 PDT 2009


Author: ddunbar
Date: Tue Mar 17 21:11:26 2009
New Revision: 67155

URL: http://llvm.org/viewvc/llvm-project?rev=67155&view=rev
Log:
Driver: Use custom diag printer to drop dependency on libFrontend and
libLex.

Modified:
    cfe/trunk/tools/driver/Makefile
    cfe/trunk/tools/driver/driver.cpp

Modified: cfe/trunk/tools/driver/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/Makefile?rev=67155&r1=67154&r2=67155&view=diff

==============================================================================
--- cfe/trunk/tools/driver/Makefile (original)
+++ cfe/trunk/tools/driver/Makefile Tue Mar 17 21:11:26 2009
@@ -15,10 +15,7 @@
 # FIXME: It is unfortunate we need to pull in the bitcode reader and
 # writer just to get the serializer stuff used by clangBasic.
 LINK_COMPONENTS := system support bitreader bitwriter
-
-# FIXME: We shouldn't need clangLex.a here; we do because the
-# TextDiagnosticPrinter is pulling it in. :(
-USEDLIBS = clangDriver.a clangFrontend.a clangLex.a clangBasic.a
+USEDLIBS = clangDriver.a clangBasic.a
 
 # This tool has no plugins, optimize startup time.
 TOOL_NO_EXPORTS = 1

Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=67155&r1=67154&r2=67155&view=diff

==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Tue Mar 17 21:11:26 2009
@@ -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(),





More information about the cfe-commits mailing list