//===----------------------------------------------------------------------===//
#include "llvm/Support/DebugLoc.h"
+#include "llvm/ADT/DenseMapInfo.h"
#include "LLVMContextImpl.h"
using namespace llvm;
// DebugLoc Implementation
//===----------------------------------------------------------------------===//
-MDNode *NewDebugLoc::getScope(const LLVMContext &Ctx) const {
+MDNode *DebugLoc::getScope(const LLVMContext &Ctx) const {
if (ScopeIdx == 0) return 0;
if (ScopeIdx > 0) {
return Ctx.pImpl->ScopeInlinedAtRecords[-ScopeIdx-1].first.get();
}
-MDNode *NewDebugLoc::getInlinedAt(const LLVMContext &Ctx) const {
+MDNode *DebugLoc::getInlinedAt(const LLVMContext &Ctx) const {
// Positive ScopeIdx is an index into ScopeRecords, which has no inlined-at
// position specified. Zero is invalid.
if (ScopeIdx >= 0) return 0;
}
/// Return both the Scope and the InlinedAt values.
-void NewDebugLoc::getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
- const LLVMContext &Ctx) const {
+void DebugLoc::getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA,
+ const LLVMContext &Ctx) const {
if (ScopeIdx == 0) {
Scope = IA = 0;
return;
}
-NewDebugLoc NewDebugLoc::get(unsigned Line, unsigned Col,
- MDNode *Scope, MDNode *InlinedAt) {
- NewDebugLoc Result;
+DebugLoc DebugLoc::get(unsigned Line, unsigned Col,
+ MDNode *Scope, MDNode *InlinedAt) {
+ DebugLoc Result;
// If no scope is available, this is an unknown location.
if (Scope == 0) return Result;
/// getAsMDNode - This method converts the compressed DebugLoc node into a
/// DILocation compatible MDNode.
-MDNode *NewDebugLoc::getAsMDNode(const LLVMContext &Ctx) const {
+MDNode *DebugLoc::getAsMDNode(const LLVMContext &Ctx) const {
if (isUnknown()) return 0;
MDNode *Scope, *IA;
assert(Scope && "If scope is null, this should be isUnknown()");
LLVMContext &Ctx2 = Scope->getContext();
- const Type *Int32 = Type::getInt32Ty(Ctx2);
+ Type *Int32 = Type::getInt32Ty(Ctx2);
Value *Elts[] = {
ConstantInt::get(Int32, getLine()), ConstantInt::get(Int32, getCol()),
Scope, IA
};
- return MDNode::get(Ctx2, &Elts[0], 4);
+ return MDNode::get(Ctx2, Elts);
}
-/// getFromDILocation - Translate the DILocation quad into a NewDebugLoc.
-NewDebugLoc NewDebugLoc::getFromDILocation(MDNode *N) {
- if (N == 0 || N->getNumOperands() != 4) return NewDebugLoc();
+/// getFromDILocation - Translate the DILocation quad into a DebugLoc.
+DebugLoc DebugLoc::getFromDILocation(MDNode *N) {
+ if (N == 0 || N->getNumOperands() != 4) return DebugLoc();
MDNode *Scope = dyn_cast_or_null<MDNode>(N->getOperand(2));
- if (Scope == 0) return NewDebugLoc();
+ if (Scope == 0) return DebugLoc();
unsigned LineNo = 0, ColNo = 0;
if (ConstantInt *Line = dyn_cast_or_null<ConstantInt>(N->getOperand(0)))
return get(LineNo, ColNo, Scope, dyn_cast_or_null<MDNode>(N->getOperand(3)));
}
+/// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
+DebugLoc DebugLoc::getFromDILexicalBlock(MDNode *N) {
+ if (N == 0 || N->getNumOperands() < 3) return DebugLoc();
+
+ MDNode *Scope = dyn_cast_or_null<MDNode>(N->getOperand(1));
+ if (Scope == 0) return DebugLoc();
+
+ unsigned LineNo = 0, ColNo = 0;
+ if (ConstantInt *Line = dyn_cast_or_null<ConstantInt>(N->getOperand(2)))
+ LineNo = Line->getZExtValue();
+ if (ConstantInt *Col = dyn_cast_or_null<ConstantInt>(N->getOperand(3)))
+ ColNo = Col->getZExtValue();
+
+ return get(LineNo, ColNo, Scope, NULL);
+}
+
+void DebugLoc::dump(const LLVMContext &Ctx) const {
+#ifndef NDEBUG
+ if (!isUnknown()) {
+ dbgs() << getLine();
+ if (getCol() != 0)
+ dbgs() << ',' << getCol();
+ DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(getInlinedAt(Ctx));
+ if (!InlinedAtDL.isUnknown()) {
+ dbgs() << " @ ";
+ InlinedAtDL.dump(Ctx);
+ } else
+ dbgs() << "\n";
+ }
+#endif
+}
+
+//===----------------------------------------------------------------------===//
+// DenseMap specialization
+//===----------------------------------------------------------------------===//
+
+DebugLoc DenseMapInfo<DebugLoc>::getEmptyKey() {
+ return DebugLoc::getEmptyKey();
+}
+
+DebugLoc DenseMapInfo<DebugLoc>::getTombstoneKey() {
+ return DebugLoc::getTombstoneKey();
+}
+
+unsigned DenseMapInfo<DebugLoc>::getHashValue(const DebugLoc &Key) {
+ FoldingSetNodeID ID;
+ ID.AddInteger(Key.LineCol);
+ ID.AddInteger(Key.ScopeIdx);
+ return ID.ComputeHash();
+}
+
+bool DenseMapInfo<DebugLoc>::isEqual(const DebugLoc &LHS, const DebugLoc &RHS) {
+ return LHS == RHS;
+}
+
//===----------------------------------------------------------------------===//
// LLVMContextImpl Implementation
//===----------------------------------------------------------------------===//
/// deleted - The MDNode this is pointing to got deleted, so this pointer needs
/// to drop to null and we need remove our entry from the DenseMap.
void DebugRecVH::deleted() {
- // If this is a non-canonical reference, just drop the value to null, we know
+ // If this is a non-canonical reference, just drop the value to null, we know
// it doesn't have a map entry.
if (Idx == 0) {
setValPtr(0);