diff options
author | Chris Lattner <sabre@nondot.org> | 2010-11-17 08:03:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-11-17 08:03:32 +0000 |
commit | 6e30c6a1d32f187804d24ecd1868d63c60330b22 (patch) | |
tree | a9dec37c628d25e374869c4e7b3e0b3c6fdf14f7 /lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp | |
parent | a38941d458273946594d3592ed5debdc9730db08 (diff) |
rearrange how the handler in SourceMgr is installed, eliminating the use of
the cookie argument to setDiagHandler
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119483 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp')
-rw-r--r-- | lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp index 861f738e5d..25ce25c325 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -34,6 +34,34 @@ #include "llvm/Support/raw_ostream.h" 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. void AsmPrinter::EmitInlineAsm(StringRef Str, const MDNode *LocMDNode) const { 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; + SrcMgrDiagInfo DiagInfo; // If the current LLVMContext has an inline asm handler, set it in SourceMgr. LLVMContext &LLVMCtx = MMI->getModule()->getContext(); bool HasDiagHandler = false; if (void *DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler()) { - unsigned LocCookie = 0; - if (LocMDNode && LocMDNode->getNumOperands() > 0) - if (const ConstantInt *CI = - dyn_cast<ConstantInt>(LocMDNode->getOperand(0))) - LocCookie = CI->getZExtValue(); - - SrcMgr.setDiagHandler((SourceMgr::DiagHandlerTy)(intptr_t)DiagHandler, - LLVMCtx.getInlineAsmDiagnosticContext(), LocCookie); + // If the source manager has an issue, we arrange for SrcMgrDiagHandler + // to be invoked, getting DiagInfo passed into it. + DiagInfo.LocInfo = LocMDNode; + DiagInfo.DiagHandler = DiagHandler; + DiagInfo.DiagContext = LLVMCtx.getInlineAsmDiagnosticContext(); + SrcMgr.setDiagHandler(SrcMgrDiagHandler, &DiagInfo); HasDiagHandler = true; } |