rearrange how the handler in SourceMgr is installed, eliminating the use of

the cookie argument to setDiagHandler

llvm-svn: 119483
This commit is contained in:
Chris Lattner 2010-11-17 08:03:32 +00:00
parent 2a7f6fd9d4
commit 300fa45d8b
1 changed files with 35 additions and 8 deletions

View File

@ -34,6 +34,34 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
namespace {
struct SrcMgrDiagInfo {
const MDNode *LocInfo;
void *DiagHandler;
void *DiagContext;
};
}
/// SrcMgrDiagHandler - This callback is invoked when the SourceMgr for an
/// inline asm has an error in it. diagInfo is a pointer to the SrcMgrDiagInfo
/// struct above.
static void SrcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo,
unsigned locCookie) {
SrcMgrDiagInfo *DiagInfo = static_cast<SrcMgrDiagInfo *>(diagInfo);
assert(DiagInfo && "Diagnostic context not passed down?");
unsigned LocCookie = 0;
if (const MDNode *LocInfo = DiagInfo->LocInfo)
if (LocInfo->getNumOperands() > 0)
if (const ConstantInt *CI = dyn_cast<ConstantInt>(LocInfo->getOperand(0)))
LocCookie = CI->getZExtValue();
SourceMgr::DiagHandlerTy ChainHandler =
(SourceMgr::DiagHandlerTy)(intptr_t)DiagInfo->DiagHandler;
ChainHandler(Diag, DiagInfo->DiagContext, LocCookie);
}
/// EmitInlineAsm - Emit a blob of inline asm to the output streamer. /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode) const { void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode) const {
assert(!Str.empty() && "Can't emit empty inline asm block"); assert(!Str.empty() && "Can't emit empty inline asm block");
@ -52,19 +80,18 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode) const {
} }
SourceMgr SrcMgr; SourceMgr SrcMgr;
SrcMgrDiagInfo DiagInfo;
// If the current LLVMContext has an inline asm handler, set it in SourceMgr. // If the current LLVMContext has an inline asm handler, set it in SourceMgr.
LLVMContext &LLVMCtx = MMI->getModule()->getContext(); LLVMContext &LLVMCtx = MMI->getModule()->getContext();
bool HasDiagHandler = false; bool HasDiagHandler = false;
if (void *DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler()) { if (void *DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler()) {
unsigned LocCookie = 0; // If the source manager has an issue, we arrange for SrcMgrDiagHandler
if (LocMDNode && LocMDNode->getNumOperands() > 0) // to be invoked, getting DiagInfo passed into it.
if (const ConstantInt *CI = DiagInfo.LocInfo = LocMDNode;
dyn_cast<ConstantInt>(LocMDNode->getOperand(0))) DiagInfo.DiagHandler = DiagHandler;
LocCookie = CI->getZExtValue(); DiagInfo.DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
SrcMgr.setDiagHandler(SrcMgrDiagHandler, &DiagInfo);
SrcMgr.setDiagHandler((SourceMgr::DiagHandlerTy)(intptr_t)DiagHandler,
LLVMCtx.getInlineAsmDiagnosticContext(), LocCookie);
HasDiagHandler = true; HasDiagHandler = true;
} }