Don't use a potentially expensive shift if all we want is one set bit.
[oota-llvm.git] / lib / DebugInfo / DWARFAbbreviationDeclaration.cpp
index 74c975304af19696eae744710bb3594fd2a3b4a5..2de62ab9380dd00bbc6d2dff1135cd785937967c 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "DWARFAbbreviationDeclaration.h"
 #include "llvm/Support/Dwarf.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 using namespace dwarf;
@@ -22,7 +23,7 @@ bool
 DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr,
                                       uint32_t code) {
   Code = code;
-  Attributes.clear();
+  Attribute.clear();
   if (Code) {
     Tag = data.getULEB128(offset_ptr);
     HasChildren = data.getU8(offset_ptr);
@@ -32,7 +33,7 @@ DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr,
       uint16_t form = data.getULEB128(offset_ptr);
 
       if (attr && form)
-        Attributes.push_back(DWARFAttribute(attr, form));
+        Attribute.push_back(DWARFAttribute(attr, form));
       else
         break;
     }
@@ -48,22 +49,34 @@ DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr,
 
 void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
   const char *tagString = TagString(getTag());
-  OS << '[' << getCode() << "] " << (tagString ? tagString : "DW_TAG_Unknown")
-     << "\tDW_CHILDREN_"
-     << (hasChildren() ? "yes" : "no") << '\n';
-  for (unsigned i = 0, e = Attributes.size(); i != e; ++i) {
-    const char *attrString = AttributeString(Attributes[i].getAttribute());
-    const char *formString = FormEncodingString(Attributes[i].getForm());
-    OS << '\t' << (attrString ? attrString : "DW_AT_Unknown")
-       << '\t' << (formString ? formString : "DW_FORM_Unknown") << '\n';
+  OS << '[' << getCode() << "] ";
+  if (tagString)
+    OS << tagString;
+  else
+    OS << format("DW_TAG_Unknown_%x", getTag());
+  OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
+  for (unsigned i = 0, e = Attribute.size(); i != e; ++i) {
+    OS << '\t';
+    const char *attrString = AttributeString(Attribute[i].getAttribute());
+    if (attrString)
+      OS << attrString;
+    else
+      OS << format("DW_AT_Unknown_%x", Attribute[i].getAttribute());
+    OS << '\t';
+    const char *formString = FormEncodingString(Attribute[i].getForm());
+    if (formString)
+      OS << formString;
+    else
+      OS << format("DW_FORM_Unknown_%x", Attribute[i].getForm());
+    OS << '\n';
   }
   OS << '\n';
 }
 
 uint32_t
 DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
-  for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
-    if (Attributes[i].getAttribute() == attr)
+  for (uint32_t i = 0, e = Attribute.size(); i != e; ++i) {
+    if (Attribute[i].getAttribute() == attr)
       return i;
   }
   return -1U;