diff options
author | Eric Christopher <echristo@gmail.com> | 2013-08-07 01:18:33 +0000 |
---|---|---|
committer | Eric Christopher <echristo@gmail.com> | 2013-08-07 01:18:33 +0000 |
commit | b7669139e6309679acbe16ca26f1b1a2fdd91268 (patch) | |
tree | 24bde9978847230d86929c1e2b72d42980474b74 | |
parent | 028f3478a510ef0855abc891237882b3c6123671 (diff) | |
download | external_llvm-b7669139e6309679acbe16ca26f1b1a2fdd91268.zip external_llvm-b7669139e6309679acbe16ca26f1b1a2fdd91268.tar.gz external_llvm-b7669139e6309679acbe16ca26f1b1a2fdd91268.tar.bz2 |
Add a way to grab a particular attribute out of a DIE.
Use it when we're looking for a string in particular. Update comments
as well.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187844 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/AsmPrinter/DIE.cpp | 12 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/DIE.h | 4 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 20 |
3 files changed, 22 insertions, 14 deletions
diff --git a/lib/CodeGen/AsmPrinter/DIE.cpp b/lib/CodeGen/AsmPrinter/DIE.cpp index 0b15412..ab03861 100644 --- a/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/lib/CodeGen/AsmPrinter/DIE.cpp @@ -122,6 +122,18 @@ DIE *DIE::getCompileUnit() { llvm_unreachable("We should not have orphaned DIEs."); } +DIEValue *DIE::findAttribute(unsigned Attribute) { + const SmallVectorImpl<DIEValue *> &Values = getValues(); + const DIEAbbrev &Abbrevs = getAbbrev(); + + // Iterate through all the attributes until we find the one we're + // looking for, if we can't find it return NULL. + for (size_t i = 0; i < Values.size(); ++i) + if (Abbrevs.getData()[i].getAttribute() == Attribute) + return Values[i]; + return NULL; +} + #ifndef NDEBUG void DIE::print(raw_ostream &O, unsigned IndentCount) const { const std::string Indent(IndentCount, ' '); diff --git a/lib/CodeGen/AsmPrinter/DIE.h b/lib/CodeGen/AsmPrinter/DIE.h index e2f49d6..bfd7d1d 100644 --- a/lib/CodeGen/AsmPrinter/DIE.h +++ b/lib/CodeGen/AsmPrinter/DIE.h @@ -175,6 +175,10 @@ namespace llvm { Child->Parent = this; } + /// findAttribute - Find a value in the DIE with the attribute given, returns NULL + /// if no such attribute exists. + DIEValue *findAttribute(unsigned Attribute); + #ifndef NDEBUG void print(raw_ostream &O, unsigned IndentCount = 0) const; void dump(); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 859805c..9a09bc1 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -966,21 +966,13 @@ void DwarfDebug::collectDeadVariables() { typedef ArrayRef<uint8_t> HashValue; /// \brief Grabs the string in whichever attribute is passed in and returns -/// a reference to it. +/// a reference to it. Returns "" if the attribute doesn't exist. static StringRef getDIEStringAttr(DIE *Die, unsigned Attr) { - const SmallVectorImpl<DIEValue *> &Values = Die->getValues(); - const DIEAbbrev &Abbrevs = Die->getAbbrev(); - - // Iterate through all the attributes until we find the one we're - // looking for, if we can't find it return an empty string. - for (size_t i = 0; i < Values.size(); ++i) { - if (Abbrevs.getData()[i].getAttribute() == Attr) { - DIEValue *V = Values[i]; - assert(isa<DIEString>(V) && "String requested. Not a string."); - DIEString *S = cast<DIEString>(V); - return S->getString(); - } - } + DIEValue *V = Die->findAttribute(Attr); + + if (DIEString *S = dyn_cast_or_null<DIEString>(V)) + return S->getString(); + return StringRef(""); } |