Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 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> |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 12 | #include <mcld/LD/TextDiagnosticPrinter.h> |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 13 | #include <mcld/LD/MsgHandler.h> |
| 14 | #include <mcld/Support/MsgHandling.h> |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 15 | #include <mcld/Support/raw_ostream.h> |
| 16 | |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 17 | #include <llvm/Support/ManagedStatic.h> |
| 18 | #include <llvm/Support/raw_ostream.h> |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 19 | #include <llvm/Support/Signals.h> |
| 20 | |
| 21 | #include <cstdlib> |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 22 | |
| 23 | using namespace mcld; |
| 24 | |
| 25 | //===----------------------------------------------------------------------===// |
Shih-wei Liao | 67e37f1 | 2012-07-27 03:50:34 -0700 | [diff] [blame] | 26 | // static variables |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | static llvm::ManagedStatic<DiagnosticEngine> g_pEngine; |
| 29 | |
| 30 | void |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 31 | mcld::InitializeDiagnosticEngine(const mcld::LinkerConfig& pConfig, |
Shih-wei Liao | 67e37f1 | 2012-07-27 03:50:34 -0700 | [diff] [blame] | 32 | DiagnosticPrinter* pPrinter) |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 33 | { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 34 | g_pEngine->reset(pConfig); |
Shih-wei Liao | 67e37f1 | 2012-07-27 03:50:34 -0700 | [diff] [blame] | 35 | if (NULL != pPrinter) |
| 36 | g_pEngine->setPrinter(*pPrinter, false); |
| 37 | else { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 38 | DiagnosticPrinter* printer = new TextDiagnosticPrinter(mcld::errs(), pConfig); |
Shih-wei Liao | 67e37f1 | 2012-07-27 03:50:34 -0700 | [diff] [blame] | 39 | g_pEngine->setPrinter(*printer, true); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
| 43 | DiagnosticEngine& mcld::getDiagnosticEngine() |
| 44 | { |
Shih-wei Liao | 67e37f1 | 2012-07-27 03:50:34 -0700 | [diff] [blame] | 45 | return *g_pEngine; |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 46 | } |
| 47 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 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 | |