X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=lib%2FIR%2FDebugLoc.cpp;h=72d5c0e618833fe2eec34376979408816fe3dfa1;hb=8a8582d6e930ade75caacae81f73be983f88166b;hp=075f295cfdce5a5abf9fa10ed4042b2e2eb261b8;hpb=37ac8d3622407cf5fd974407c5b8b301a2fdfcfd;p=oota-llvm.git diff --git a/lib/IR/DebugLoc.cpp b/lib/IR/DebugLoc.cpp index 075f295cfdc..72d5c0e6188 100644 --- a/lib/IR/DebugLoc.cpp +++ b/lib/IR/DebugLoc.cpp @@ -16,106 +16,87 @@ using namespace llvm; //===----------------------------------------------------------------------===// // DebugLoc Implementation //===----------------------------------------------------------------------===// +DebugLoc::DebugLoc(const DILocation *L) : Loc(const_cast(L)) {} +DebugLoc::DebugLoc(const MDNode *L) : Loc(const_cast(L)) {} -unsigned DebugLoc::getLine() const { return DILocation(Loc).getLineNumber(); } -unsigned DebugLoc::getCol() const { return DILocation(Loc).getColumnNumber(); } +DILocation *DebugLoc::get() const { + return cast_or_null(Loc.get()); +} + +unsigned DebugLoc::getLine() const { + assert(get() && "Expected valid DebugLoc"); + return get()->getLine(); +} -MDNode *DebugLoc::getScope() const { return DILocation(Loc).getScope(); } +unsigned DebugLoc::getCol() const { + assert(get() && "Expected valid DebugLoc"); + return get()->getColumn(); +} -MDNode *DebugLoc::getInlinedAt() const { - return DILocation(Loc).getOrigLocation(); +MDNode *DebugLoc::getScope() const { + assert(get() && "Expected valid DebugLoc"); + return get()->getScope(); } -/// Return both the Scope and the InlinedAt values. -void DebugLoc::getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA) const { - Scope = getScope(); - IA = getInlinedAt(); +DILocation *DebugLoc::getInlinedAt() const { + assert(get() && "Expected valid DebugLoc"); + return get()->getInlinedAt(); } -MDNode *DebugLoc::getScopeNode() const { - if (MDNode *InlinedAt = getInlinedAt()) - return DebugLoc::getFromDILocation(InlinedAt).getScopeNode(); - return getScope(); +MDNode *DebugLoc::getInlinedAtScope() const { + return cast(Loc)->getInlinedAtScope(); } DebugLoc DebugLoc::getFnDebugLoc() const { - const MDNode *Scope = getScopeNode(); - DISubprogram SP = getDISubprogram(Scope); - if (SP.isSubprogram()) - return DebugLoc::get(SP.getScopeLineNumber(), 0, SP); + // FIXME: Add a method on \a DILocation that does this work. + const MDNode *Scope = getInlinedAtScope(); + if (auto *SP = getDISubprogram(Scope)) + return DebugLoc::get(SP->getScopeLine(), 0, SP); return DebugLoc(); } -DebugLoc DebugLoc::get(unsigned Line, unsigned Col, - MDNode *Scope, MDNode *InlinedAt) { +DebugLoc DebugLoc::get(unsigned Line, unsigned Col, const MDNode *Scope, + const MDNode *InlinedAt) { // If no scope is available, this is an unknown location. if (!Scope) return DebugLoc(); - // Saturate line and col to "unknown". - // FIXME: Allow 16-bits for columns. - if (Col > 255) Col = 0; - if (Line >= (1 << 24)) Line = 0; - - return getFromDILocation( - MDLocation::get(Scope->getContext(), Line, Col, Scope, InlinedAt)); -} - -/// getAsMDNode - This method converts the compressed DebugLoc node into a -/// DILocation-compatible MDNode. -MDNode *DebugLoc::getAsMDNode() const { return Loc; } - -/// getFromDILocation - Translate the DILocation quad into a DebugLoc. -DebugLoc DebugLoc::getFromDILocation(MDNode *N) { - DebugLoc Loc; - Loc.Loc.reset(N); - return Loc; -} - -/// getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc. -DebugLoc DebugLoc::getFromDILexicalBlock(MDNode *N) { - DILexicalBlock LexBlock(N); - MDNode *Scope = LexBlock.getContext(); - if (!Scope) return DebugLoc(); - return get(LexBlock.getLineNumber(), LexBlock.getColumnNumber(), Scope, - nullptr); + return DILocation::get(Scope->getContext(), Line, Col, + const_cast(Scope), + const_cast(InlinedAt)); } void DebugLoc::dump() const { #ifndef NDEBUG - if (!isUnknown()) { - dbgs() << getLine(); - if (getCol() != 0) - dbgs() << ',' << getCol(); - DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(getInlinedAt()); - if (!InlinedAtDL.isUnknown()) { - dbgs() << " @ "; - InlinedAtDL.dump(); - } else - dbgs() << "\n"; - } + if (!Loc) + return; + + dbgs() << getLine(); + if (getCol() != 0) + dbgs() << ',' << getCol(); + if (DebugLoc InlinedAtDL = DebugLoc(getInlinedAt())) { + dbgs() << " @ "; + InlinedAtDL.dump(); + } else + dbgs() << "\n"; #endif } void DebugLoc::print(raw_ostream &OS) const { - if (!isUnknown()) { - // Print source line info. - DIScope Scope(getScope()); - assert((!Scope || Scope.isScope()) && - "Scope of a DebugLoc should be null or a DIScope."); - if (Scope) - OS << Scope.getFilename(); - else - OS << ""; - OS << ':' << getLine(); - if (getCol() != 0) - OS << ':' << getCol(); - DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(getInlinedAt()); - if (!InlinedAtDL.isUnknown()) { - OS << " @[ "; - InlinedAtDL.print(OS); - OS << " ]"; - } + if (!Loc) + return; + + // Print source line info. + auto *Scope = cast(getScope()); + OS << Scope->getFilename(); + OS << ':' << getLine(); + if (getCol() != 0) + OS << ':' << getCol(); + + if (DebugLoc InlinedAtDL = getInlinedAt()) { + OS << " @[ "; + InlinedAtDL.print(OS); + OS << " ]"; } }