add a method to decode a DILocation into a NewDebugLoc.
authorChris Lattner <sabre@nondot.org>
Thu, 1 Apr 2010 03:55:42 +0000 (03:55 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 1 Apr 2010 03:55:42 +0000 (03:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100081 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/DebugLoc.h
lib/VMCore/DebugLoc.cpp

index 3b8365efceeb6571f84e4f3f8a8a48c6b685730e..300d7401cec7052679acdcd63bf41a0ec3be6f0f 100644 (file)
@@ -40,6 +40,9 @@ namespace llvm {
     static NewDebugLoc get(unsigned Line, unsigned Col,
                            MDNode *Scope, MDNode *InlinedAt);
     
+    /// getFromDILocation - Translate the DILocation quad into a NewDebugLoc.
+    static NewDebugLoc getFromDILocation(MDNode *N);
+    
     /// isUnknown - Return true if this is an unknown location.
     bool isUnknown() const { return ScopeIdx == 0; }
     
@@ -96,7 +99,7 @@ namespace llvm {
     bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
   };
 
-    /// DebugLocTracker - This class tracks debug location information.
+  /// DebugLocTracker - This class tracks debug location information.
   ///
   struct DebugLocTracker {
     /// DebugLocations - A vector of unique DebugLocTuple's.
index 0fcbf2653aa723181c9802ba548b3b8f1d63e53a..d9f533a9d60a6c8962fffc2da264e78936b0154d 100644 (file)
@@ -111,6 +111,21 @@ MDNode *NewDebugLoc::getAsMDNode(const LLVMContext &Ctx) const {
   return MDNode::get(Ctx2, &Elts[0], 4);
 }
 
+/// getFromDILocation - Translate the DILocation quad into a NewDebugLoc.
+NewDebugLoc NewDebugLoc::getFromDILocation(MDNode *N) {
+  if (N == 0 || N->getNumOperands() != 4) return NewDebugLoc();
+  
+  MDNode *Scope = dyn_cast_or_null<MDNode>(N->getOperand(2));
+  if (Scope == 0) return NewDebugLoc();
+  
+  unsigned LineNo = 0, ColNo = 0;
+  if (ConstantInt *Line = dyn_cast_or_null<ConstantInt>(N->getOperand(0)))
+    LineNo = Line->getZExtValue();
+  if (ConstantInt *Col = dyn_cast_or_null<ConstantInt>(N->getOperand(1)))
+    ColNo = Col->getZExtValue();
+  
+  return get(LineNo, ColNo, Scope, dyn_cast_or_null<MDNode>(N->getOperand(3)));
+}
 
 //===----------------------------------------------------------------------===//
 // LLVMContextImpl Implementation