| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===// |
| 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 | |
| Greg Clayton | a76dd62 | 2011-09-12 04:20:38 +0000 | [diff] [blame] | 10 | #ifndef SymbolFileDWARF_DWARFAttribute_h_ |
| 11 | #define SymbolFileDWARF_DWARFAttribute_h_ |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallVector.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "DWARFDefines.h" |
| 15 | #include <vector> |
| 16 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 17 | class DWARFCompileUnit; |
| 18 | class DWARFFormValue; |
| 19 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | class DWARFAttribute |
| 21 | { |
| 22 | public: |
| 23 | DWARFAttribute(dw_attr_t attr, dw_form_t form) : |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 24 | m_attr (attr), |
| 25 | m_form (form) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | { |
| 27 | } |
| 28 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 29 | void set (dw_attr_t attr, dw_form_t form) { m_attr = attr; m_form = form; } |
| 30 | void set_attr (dw_attr_t attr) { m_attr = attr; } |
| 31 | void set_form (dw_form_t form) { m_form = form; } |
| 32 | dw_attr_t get_attr () const { return m_attr; } |
| 33 | dw_form_t get_form () const { return m_form; } |
| 34 | void get (dw_attr_t& attr, dw_form_t& form) const |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | { |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 36 | attr = m_attr; |
| 37 | form = m_form; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | } |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 39 | bool operator == (const DWARFAttribute& rhs) const { return m_attr == rhs.m_attr && m_form == rhs.m_form; } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | typedef std::vector<DWARFAttribute> collection; |
| 41 | typedef collection::iterator iterator; |
| 42 | typedef collection::const_iterator const_iterator; |
| 43 | |
| 44 | protected: |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 45 | dw_attr_t m_attr; |
| 46 | dw_form_t m_form; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | |
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 50 | class DWARFAttributes |
| 51 | { |
| 52 | public: |
| 53 | DWARFAttributes(); |
| 54 | ~DWARFAttributes(); |
| 55 | |
| 56 | void Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form); |
| 57 | const DWARFCompileUnit * CompileUnitAtIndex(uint32_t i) const { return m_infos[i].cu; } |
| 58 | dw_offset_t DIEOffsetAtIndex(uint32_t i) const { return m_infos[i].die_offset; } |
| 59 | dw_attr_t AttributeAtIndex(uint32_t i) const { return m_infos[i].attr.get_attr(); } |
| 60 | dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].attr.get_form(); } |
| 61 | bool ExtractFormValueAtIndex (uint32_t i, DWARFFormValue &form_value) const; |
| 62 | uint64_t FormValueAsUnsignedAtIndex (uint32_t i, uint64_t fail_value) const; |
| 63 | uint64_t FormValueAsUnsigned (dw_attr_t attr, uint64_t fail_value) const; |
| 64 | uint32_t FindAttributeIndex(dw_attr_t attr) const; |
| 65 | bool ContainsAttribute(dw_attr_t attr) const; |
| 66 | bool RemoveAttribute(dw_attr_t attr); |
| 67 | void Clear() { m_infos.clear(); } |
| 68 | size_t Size() const { return m_infos.size(); } |
| 69 | |
| 70 | protected: |
| 71 | struct AttributeValue |
| 72 | { |
| 73 | const DWARFCompileUnit *cu; // Keep the compile unit with each attribute in case we have DW_FORM_ref_addr values |
| 74 | dw_offset_t die_offset; |
| 75 | DWARFAttribute attr; |
| 76 | }; |
| 77 | typedef llvm::SmallVector<AttributeValue, 8> collection; |
| 78 | collection m_infos; |
| 79 | }; |
| 80 | |
| Greg Clayton | a76dd62 | 2011-09-12 04:20:38 +0000 | [diff] [blame] | 81 | #endif // SymbolFileDWARF_DWARFAttribute_h_ |