add a method to decode a DILocation into a NewDebugLoc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100081 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-04-01 03:55:42 +00:00
parent ec306a9771
commit 68c5513499
2 changed files with 19 additions and 1 deletions
+15
View 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