mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-30 16:17:05 +00:00 
			
		
		
		
	DWARFAbbreviationDeclaration: remove dead code, refactor parsing code and make it more robust. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193770 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		| @@ -14,38 +14,52 @@ | |||||||
| using namespace llvm; | using namespace llvm; | ||||||
| using namespace dwarf; | using namespace dwarf; | ||||||
|  |  | ||||||
| bool | void DWARFAbbreviationDeclaration::clear() { | ||||||
| DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){ |   Code = 0; | ||||||
|   return extract(data, offset_ptr, data.getULEB128(offset_ptr)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool |  | ||||||
| DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr, |  | ||||||
|                                       uint32_t code) { |  | ||||||
|   Code = code; |  | ||||||
|   Attribute.clear(); |  | ||||||
|   if (Code) { |  | ||||||
|     Tag = data.getULEB128(offset_ptr); |  | ||||||
|     HasChildren = data.getU8(offset_ptr); |  | ||||||
|  |  | ||||||
|     while (data.isValidOffset(*offset_ptr)) { |  | ||||||
|       uint16_t attr = data.getULEB128(offset_ptr); |  | ||||||
|       uint16_t form = data.getULEB128(offset_ptr); |  | ||||||
|  |  | ||||||
|       if (attr && form) |  | ||||||
|         Attribute.push_back(DWARFAttribute(attr, form)); |  | ||||||
|       else |  | ||||||
|         break; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return Tag != 0; |  | ||||||
|   } else { |  | ||||||
|   Tag = 0; |   Tag = 0; | ||||||
|   HasChildren = false; |   HasChildren = false; | ||||||
|  |   Attributes.clear(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() { | ||||||
|  |   clear(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bool | ||||||
|  | DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) { | ||||||
|  |   clear(); | ||||||
|  |   Code = Data.getULEB128(OffsetPtr); | ||||||
|  |   if (Code == 0) { | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |   Tag = Data.getULEB128(OffsetPtr); | ||||||
|  |   uint8_t ChildrenByte = Data.getU8(OffsetPtr); | ||||||
|  |   HasChildren = (ChildrenByte == DW_CHILDREN_yes); | ||||||
|  |  | ||||||
|  |   while (true) { | ||||||
|  |     uint32_t CurOffset = *OffsetPtr; | ||||||
|  |     uint16_t Attr = Data.getULEB128(OffsetPtr); | ||||||
|  |     if (CurOffset == *OffsetPtr) { | ||||||
|  |       clear(); | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  |     CurOffset = *OffsetPtr; | ||||||
|  |     uint16_t Form = Data.getULEB128(OffsetPtr); | ||||||
|  |     if (CurOffset == *OffsetPtr) { | ||||||
|  |       clear(); | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|  |     if (Attr == 0 && Form == 0) | ||||||
|  |       break; | ||||||
|  |     Attributes.push_back(AttributeSpec(Attr, Form)); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if (Tag == 0) { | ||||||
|  |     clear(); | ||||||
|  |     return false; | ||||||
|  |   } | ||||||
|  |   return true; | ||||||
|  | } | ||||||
|  |  | ||||||
| void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { | void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { | ||||||
|   const char *tagString = TagString(getTag()); |   const char *tagString = TagString(getTag()); | ||||||
| @@ -55,19 +69,19 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { | |||||||
|   else |   else | ||||||
|     OS << format("DW_TAG_Unknown_%x", getTag()); |     OS << format("DW_TAG_Unknown_%x", getTag()); | ||||||
|   OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n'; |   OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n'; | ||||||
|   for (unsigned i = 0, e = Attribute.size(); i != e; ++i) { |   for (unsigned i = 0, e = Attributes.size(); i != e; ++i) { | ||||||
|     OS << '\t'; |     OS << '\t'; | ||||||
|     const char *attrString = AttributeString(Attribute[i].getAttribute()); |     const char *attrString = AttributeString(Attributes[i].Attr); | ||||||
|     if (attrString) |     if (attrString) | ||||||
|       OS << attrString; |       OS << attrString; | ||||||
|     else |     else | ||||||
|       OS << format("DW_AT_Unknown_%x", Attribute[i].getAttribute()); |       OS << format("DW_AT_Unknown_%x", Attributes[i].Attr); | ||||||
|     OS << '\t'; |     OS << '\t'; | ||||||
|     const char *formString = FormEncodingString(Attribute[i].getForm()); |     const char *formString = FormEncodingString(Attributes[i].Form); | ||||||
|     if (formString) |     if (formString) | ||||||
|       OS << formString; |       OS << formString; | ||||||
|     else |     else | ||||||
|       OS << format("DW_FORM_Unknown_%x", Attribute[i].getForm()); |       OS << format("DW_FORM_Unknown_%x", Attributes[i].Form); | ||||||
|     OS << '\n'; |     OS << '\n'; | ||||||
|   } |   } | ||||||
|   OS << '\n'; |   OS << '\n'; | ||||||
| @@ -75,8 +89,8 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { | |||||||
|  |  | ||||||
| uint32_t | uint32_t | ||||||
| DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const { | DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const { | ||||||
|   for (uint32_t i = 0, e = Attribute.size(); i != e; ++i) { |   for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) { | ||||||
|     if (Attribute[i].getAttribute() == attr) |     if (Attributes[i].Attr == attr) | ||||||
|       return i; |       return i; | ||||||
|   } |   } | ||||||
|   return -1U; |   return -1U; | ||||||
|   | |||||||
| @@ -10,7 +10,6 @@ | |||||||
| #ifndef LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H | #ifndef LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H | ||||||
| #define LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H | #define LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H | ||||||
|  |  | ||||||
| #include "DWARFAttribute.h" |  | ||||||
| #include "llvm/ADT/SmallVector.h" | #include "llvm/ADT/SmallVector.h" | ||||||
| #include "llvm/Support/DataExtractor.h" | #include "llvm/Support/DataExtractor.h" | ||||||
|  |  | ||||||
| @@ -22,31 +21,33 @@ class DWARFAbbreviationDeclaration { | |||||||
|   uint32_t Code; |   uint32_t Code; | ||||||
|   uint32_t Tag; |   uint32_t Tag; | ||||||
|   bool HasChildren; |   bool HasChildren; | ||||||
|   SmallVector<DWARFAttribute, 8> Attribute; |  | ||||||
|  |   struct AttributeSpec { | ||||||
|  |     AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {} | ||||||
|  |     uint16_t Attr; | ||||||
|  |     uint16_t Form; | ||||||
|  |   }; | ||||||
|  |   SmallVector<AttributeSpec, 8> Attributes; | ||||||
| public: | public: | ||||||
|   enum { InvalidCode = 0 }; |   DWARFAbbreviationDeclaration(); | ||||||
|   DWARFAbbreviationDeclaration() |  | ||||||
|     : Code(InvalidCode), Tag(0), HasChildren(0) {} |  | ||||||
|  |  | ||||||
|   uint32_t getCode() const { return Code; } |   uint32_t getCode() const { return Code; } | ||||||
|   uint32_t getTag() const { return Tag; } |   uint32_t getTag() const { return Tag; } | ||||||
|   bool hasChildren() const { return HasChildren; } |   bool hasChildren() const { return HasChildren; } | ||||||
|   uint32_t getNumAttributes() const { return Attribute.size(); } |   uint32_t getNumAttributes() const { return Attributes.size(); } | ||||||
|   uint16_t getAttrByIndex(uint32_t idx) const { |   uint16_t getAttrByIndex(uint32_t idx) const { | ||||||
|     return Attribute.size() > idx ? Attribute[idx].getAttribute() : 0; |     return idx < Attributes.size() ? Attributes[idx].Attr : 0; | ||||||
|   } |   } | ||||||
|   uint16_t getFormByIndex(uint32_t idx) const { |   uint16_t getFormByIndex(uint32_t idx) const { | ||||||
|     return Attribute.size() > idx ? Attribute[idx].getForm() : 0; |     return idx < Attributes.size() ? Attributes[idx].Form : 0; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   uint32_t findAttributeIndex(uint16_t attr) const; |   uint32_t findAttributeIndex(uint16_t attr) const; | ||||||
|   bool extract(DataExtractor data, uint32_t* offset_ptr); |   bool extract(DataExtractor Data, uint32_t* OffsetPtr); | ||||||
|   bool extract(DataExtractor data, uint32_t* offset_ptr, uint32_t code); |  | ||||||
|   bool isValid() const { return Code != 0 && Tag != 0; } |  | ||||||
|   void dump(raw_ostream &OS) const; |   void dump(raw_ostream &OS) const; | ||||||
|   const SmallVectorImpl<DWARFAttribute> &getAttributes() const { |  | ||||||
|     return Attribute; | private: | ||||||
|   } |   void clear(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,30 +0,0 @@ | |||||||
| //===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===// |  | ||||||
| // |  | ||||||
| //                     The LLVM Compiler Infrastructure |  | ||||||
| // |  | ||||||
| // This file is distributed under the University of Illinois Open Source |  | ||||||
| // License. See LICENSE.TXT for details. |  | ||||||
| // |  | ||||||
| //===----------------------------------------------------------------------===// |  | ||||||
|  |  | ||||||
| #ifndef LLVM_DEBUGINFO_DWARFATTRIBUTE_H |  | ||||||
| #define LLVM_DEBUGINFO_DWARFATTRIBUTE_H |  | ||||||
|  |  | ||||||
| #include "llvm/Support/DataTypes.h" |  | ||||||
|  |  | ||||||
| namespace llvm { |  | ||||||
|  |  | ||||||
| class DWARFAttribute { |  | ||||||
|   uint16_t Attribute; |  | ||||||
|   uint16_t Form; |  | ||||||
|   public: |  | ||||||
|   DWARFAttribute(uint16_t attr, uint16_t form) |  | ||||||
|     : Attribute(attr), Form(form) {} |  | ||||||
|  |  | ||||||
|   uint16_t getAttribute() const { return Attribute; } |  | ||||||
|   uint16_t getForm() const { return Form; } |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #endif |  | ||||||
		Reference in New Issue
	
	Block a user