Home | History | Annotate | Download | only in Support
      1 //===- MsgHandling.cpp ----------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #include <mcld/LD/DiagnosticEngine.h>
     10 #include <mcld/LD/DiagnosticLineInfo.h>
     11 #include <mcld/LD/DiagnosticPrinter.h>
     12 #include <mcld/LD/TextDiagnosticPrinter.h>
     13 #include <mcld/LD/MsgHandler.h>
     14 #include <mcld/Support/MsgHandling.h>
     15 #include <mcld/Support/raw_ostream.h>
     16 
     17 #include <llvm/Support/ManagedStatic.h>
     18 #include <llvm/Support/raw_ostream.h>
     19 #include <llvm/Support/Signals.h>
     20 
     21 #include <cstdlib>
     22 
     23 using namespace mcld;
     24 
     25 //===----------------------------------------------------------------------===//
     26 // static variables
     27 //===----------------------------------------------------------------------===//
     28 static llvm::ManagedStatic<DiagnosticEngine> g_pEngine;
     29 
     30 void
     31 mcld::InitializeDiagnosticEngine(const mcld::LinkerConfig& pConfig,
     32                                  DiagnosticPrinter* pPrinter)
     33 {
     34   g_pEngine->reset(pConfig);
     35   if (NULL != pPrinter)
     36     g_pEngine->setPrinter(*pPrinter, false);
     37   else {
     38     DiagnosticPrinter* printer = new TextDiagnosticPrinter(mcld::errs(), pConfig);
     39     g_pEngine->setPrinter(*printer, true);
     40   }
     41 }
     42 
     43 DiagnosticEngine& mcld::getDiagnosticEngine()
     44 {
     45   return *g_pEngine;
     46 }
     47 
     48 bool mcld::Diagnose()
     49 {
     50   if (g_pEngine->getPrinter()->getNumErrors() > 0) {
     51     // If we reached here, we are failing ungracefully. Run the interrupt handlers
     52     // to make sure any special cleanups get done, in particular that we remove
     53     // files registered with RemoveFileOnSignal.
     54     llvm::sys::RunInterruptHandlers();
     55     g_pEngine->getPrinter()->finish();
     56     return false;
     57   }
     58   return true;
     59 }
     60 
     61 void mcld::FinalizeDiagnosticEngine()
     62 {
     63   g_pEngine->getPrinter()->finish();
     64 }
     65 
     66