MsgHandling.cpp revision 67e37f1be98c926645219cfb47fab9e90d8c725c
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/MsgHandler.h>
13#include <mcld/Support/MsgHandling.h>
14#include <llvm/Support/ManagedStatic.h>
15#include <llvm/Support/raw_ostream.h>
16
17using namespace mcld;
18
19//===----------------------------------------------------------------------===//
20// static variables
21//===----------------------------------------------------------------------===//
22static llvm::ManagedStatic<DiagnosticEngine> g_pEngine;
23
24void
25mcld::InitializeDiagnosticEngine(const mcld::MCLDInfo& pLDInfo,
26                                 DiagnosticLineInfo* pLineInfo,
27                                 DiagnosticPrinter* pPrinter)
28{
29  g_pEngine->reset(pLDInfo);
30  if (NULL != pLineInfo)
31    g_pEngine->setLineInfo(*pLineInfo);
32
33  if (NULL != pPrinter)
34    g_pEngine->setPrinter(*pPrinter, false);
35  else {
36    DiagnosticPrinter* printer = new DiagnosticPrinter();
37    g_pEngine->setPrinter(*printer, true);
38  }
39}
40
41DiagnosticEngine& mcld::getDiagnosticEngine()
42{
43  return *g_pEngine;
44}
45
46