diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-07-11 17:11:11 +0000 | 
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-07-11 17:11:11 +0000 | 
| commit | 3f27e57adeb5fc262e07c191eca07f28977a1f3b (patch) | |
| tree | a616409148b8aeb7e6643f7536b0a6844071ebd0 /llvm/lib/DebugInfo | |
| parent | 14eeb5a5c0fd8c79a71aed6ce240a32cd8f18e85 (diff) | |
| download | bcm5719-llvm-3f27e57adeb5fc262e07c191eca07f28977a1f3b.tar.gz bcm5719-llvm-3f27e57adeb5fc262e07c191eca07f28977a1f3b.zip | |
[DebugInfo] Make children iterator bidirectional
Make the DIE iterator bidirectional so we can move to the previous
sibling of a DIE.
Differential revision: https://reviews.llvm.org/D49173
llvm-svn: 336823
Diffstat (limited to 'llvm/lib/DebugInfo')
| -rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDie.cpp | 12 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 33 | 
2 files changed, 45 insertions, 0 deletions
| diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index 0ef65c2b0b6..904ceab7b28 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -555,12 +555,24 @@ DWARFDie DWARFDie::getSibling() const {    return DWARFDie();  } +DWARFDie DWARFDie::getPreviousSibling() const { +  if (isValid()) +    return U->getPreviousSibling(Die); +  return DWARFDie(); +} +  DWARFDie DWARFDie::getFirstChild() const {    if (isValid())      return U->getFirstChild(Die);    return DWARFDie();  } +DWARFDie DWARFDie::getLastChild() const { +  if (isValid()) +    return U->getLastChild(Die); +  return DWARFDie(); +} +  iterator_range<DWARFDie::attribute_iterator> DWARFDie::attributes() const {    return make_range(attribute_iterator(*this, false),                      attribute_iterator(*this, true)); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index 6b7970d426b..7581575e2a4 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -584,6 +584,24 @@ DWARFDie DWARFUnit::getSibling(const DWARFDebugInfoEntry *Die) {    return DWARFDie();  } +DWARFDie DWARFUnit::getPreviousSibling(const DWARFDebugInfoEntry *Die) { +  if (!Die) +    return DWARFDie(); +  uint32_t Depth = Die->getDepth(); +  // Unit DIEs always have a depth of zero and never have siblings. +  if (Depth == 0) +    return DWARFDie(); + +  // Find the previous DIE whose depth is the same as the Die's depth. +  for (size_t I = getDIEIndex(Die) - 1; I >= 0; --I) { +    if (DieArray[I].getDepth() == Depth - 1) +      return DWARFDie(); +    if (DieArray[I].getDepth() == Depth) +      return DWARFDie(this, &DieArray[I]); +  } +  return DWARFDie(); +} +  DWARFDie DWARFUnit::getFirstChild(const DWARFDebugInfoEntry *Die) {    if (!Die->hasChildren())      return DWARFDie(); @@ -595,6 +613,21 @@ DWARFDie DWARFUnit::getFirstChild(const DWARFDebugInfoEntry *Die) {    return DWARFDie(this, &DieArray[I]);  } +DWARFDie DWARFUnit::getLastChild(const DWARFDebugInfoEntry *Die) { +  if (!Die->hasChildren()) +    return DWARFDie(); + +  uint32_t Depth = Die->getDepth(); +  for (size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size(); I < EndIdx; +       ++I) { +    if (DieArray[I].getDepth() == Depth + 1 && +        DieArray[I].getTag() == dwarf::DW_TAG_null) +      return DWARFDie(this, &DieArray[I]); +    assert(DieArray[I].getDepth() > Depth && "Not processing children?"); +  } +  return DWARFDie(); +} +  const DWARFAbbreviationDeclarationSet *DWARFUnit::getAbbreviations() const {    if (!Abbrevs)      Abbrevs = Abbrev->getAbbreviationDeclarationSet(Header.getAbbrOffset()); | 

