Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 1 | //===-- DWARFAbbreviationDeclaration.cpp ----------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "DWARFAbbreviationDeclaration.h" |
| 11 | #include "llvm/Support/Dwarf.h" |
| 12 | #include "llvm/Support/raw_ostream.h" |
| 13 | using namespace llvm; |
| 14 | using namespace dwarf; |
| 15 | |
| 16 | bool |
| 17 | DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){ |
| 18 | return extract(data, offset_ptr, data.getULEB128(offset_ptr)); |
| 19 | } |
| 20 | |
| 21 | bool |
| 22 | DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr, |
| 23 | uint32_t code) { |
| 24 | Code = code; |
| 25 | Attributes.clear(); |
| 26 | if (Code) { |
| 27 | Tag = data.getULEB128(offset_ptr); |
| 28 | HasChildren = data.getU8(offset_ptr); |
| 29 | |
| 30 | while (data.isValidOffset(*offset_ptr)) { |
| 31 | uint16_t attr = data.getULEB128(offset_ptr); |
| 32 | uint16_t form = data.getULEB128(offset_ptr); |
| 33 | |
| 34 | if (attr && form) |
| 35 | Attributes.push_back(DWARFAttribute(attr, form)); |
| 36 | else |
| 37 | break; |
| 38 | } |
| 39 | |
| 40 | return Tag != 0; |
| 41 | } |
| 42 | else { |
| 43 | Tag = 0; |
| 44 | HasChildren = false; |
| 45 | } |
| 46 | |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { |
| 51 | OS << '[' << getCode() << "] " << TagString(getTag()) << "\tDW_CHILDREN_" |
| 52 | << (hasChildren() ? "yes" : "no") << '\n'; |
| 53 | for (unsigned i = 0, e = Attributes.size(); i != e; ++i) |
| 54 | OS << '\t' << AttributeString(Attributes[i].getAttribute()) |
| 55 | << '\t' << FormEncodingString(Attributes[i].getForm()) << '\n'; |
| 56 | OS << '\n'; |
| 57 | } |
| 58 | |
| 59 | uint32_t |
| 60 | DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const { |
| 61 | for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) { |
| 62 | if (Attributes[i].getAttribute() == attr) |
| 63 | return i; |
| 64 | } |
| 65 | return -1U; |
| 66 | } |