blob: 7bc942f63dd5e7dc97a1fd1718a76f0538e020c2 [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- 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"
13using namespace llvm;
14using namespace dwarf;
15
16bool
17DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){
18 return extract(data, offset_ptr, data.getULEB128(offset_ptr));
19}
20
21bool
22DWARFAbbreviationDeclaration::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;
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000041 } else {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000042 Tag = 0;
43 HasChildren = false;
44 }
45
46 return false;
47}
48
49void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
50 OS << '[' << getCode() << "] " << TagString(getTag()) << "\tDW_CHILDREN_"
51 << (hasChildren() ? "yes" : "no") << '\n';
52 for (unsigned i = 0, e = Attributes.size(); i != e; ++i)
53 OS << '\t' << AttributeString(Attributes[i].getAttribute())
54 << '\t' << FormEncodingString(Attributes[i].getForm()) << '\n';
55 OS << '\n';
56}
57
58uint32_t
59DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
60 for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
61 if (Attributes[i].getAttribute() == attr)
62 return i;
63 }
64 return -1U;
65}