You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
//===- MsgHandling.cpp ----------------------------------------------------===//
|
|
//
|
|
// The MCLinker Project
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#include "mcld/LD/DiagnosticEngine.h"
|
|
#include "mcld/LD/DiagnosticLineInfo.h"
|
|
#include "mcld/LD/DiagnosticPrinter.h"
|
|
#include "mcld/LD/MsgHandler.h"
|
|
#include "mcld/LD/TextDiagnosticPrinter.h"
|
|
#include "mcld/Support/MsgHandling.h"
|
|
#include "mcld/Support/raw_ostream.h"
|
|
|
|
#include <llvm/Support/ManagedStatic.h>
|
|
#include <llvm/Support/raw_ostream.h>
|
|
#include <llvm/Support/Signals.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
namespace mcld {
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// static variables
|
|
//===----------------------------------------------------------------------===//
|
|
static llvm::ManagedStatic<DiagnosticEngine> g_pEngine;
|
|
|
|
void InitializeDiagnosticEngine(const LinkerConfig& pConfig,
|
|
DiagnosticPrinter* pPrinter) {
|
|
g_pEngine->reset(pConfig);
|
|
if (pPrinter != NULL)
|
|
g_pEngine->setPrinter(*pPrinter, false);
|
|
else {
|
|
DiagnosticPrinter* printer =
|
|
new TextDiagnosticPrinter(errs(), pConfig);
|
|
g_pEngine->setPrinter(*printer, true);
|
|
}
|
|
}
|
|
|
|
DiagnosticEngine& getDiagnosticEngine() {
|
|
return *g_pEngine;
|
|
}
|
|
|
|
bool Diagnose() {
|
|
if (g_pEngine->getPrinter()->getNumErrors() > 0) {
|
|
// If we reached here, we are failing ungracefully. Run the interrupt
|
|
// handlers
|
|
// to make sure any special cleanups get done, in particular that we remove
|
|
// files registered with RemoveFileOnSignal.
|
|
llvm::sys::RunInterruptHandlers();
|
|
g_pEngine->getPrinter()->finish();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void FinalizeDiagnosticEngine() {
|
|
g_pEngine->getPrinter()->finish();
|
|
}
|
|
|
|
} // namespace mcld
|