[llvm-commits] [llvm] r119483 - /llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

Chris Lattner sabre at nondot.org
Wed Nov 17 00:03:32 PST 2010


Author: lattner
Date: Wed Nov 17 02:03:32 2010
New Revision: 119483

URL: http://llvm.org/viewvc/llvm-project?rev=119483&view=rev
Log:
rearrange how the handler in SourceMgr is installed, eliminating the use of 
the cookie argument to setDiagHandler

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=119483&r1=119482&r2=119483&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Wed Nov 17 02:03:32 2010
@@ -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 @@
   }
 
   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;
   }
 





More information about the llvm-commits mailing list