1 //===- RelocData.h --------------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef MCLD_LD_RELOCDATA_H_ 10 #define MCLD_LD_RELOCDATA_H_ 11 12 #include "mcld/ADT/ilist_sort.h" 13 #include "mcld/Config/Config.h" 14 #include "mcld/Fragment/Relocation.h" 15 #include "mcld/Support/Allocators.h" 16 #include "mcld/Support/Compiler.h" 17 #include "mcld/Support/GCFactoryListTraits.h" 18 19 #include <llvm/ADT/ilist.h> 20 #include <llvm/ADT/ilist_node.h> 21 #include <llvm/Support/DataTypes.h> 22 23 #include <list> 24 25 namespace mcld { 26 27 class LDSection; 28 29 /** \class RelocData 30 * \brief RelocData stores Relocation. 31 * 32 * Since Relocations are created by GCFactory, we use GCFactoryListTraits for 33 *the 34 * RelocationList here to avoid iplist to delete Relocations. 35 */ 36 class RelocData { 37 private: 38 friend class Chunk<RelocData, MCLD_SECTIONS_PER_INPUT>; 39 40 RelocData(); 41 explicit RelocData(LDSection& pSection); 42 43 public: 44 typedef llvm::iplist<Relocation, GCFactoryListTraits<Relocation> > 45 RelocationListType; 46 47 typedef RelocationListType::reference reference; 48 typedef RelocationListType::const_reference const_reference; 49 50 typedef RelocationListType::iterator iterator; 51 typedef RelocationListType::const_iterator const_iterator; 52 53 typedef RelocationListType::reverse_iterator reverse_iterator; 54 typedef RelocationListType::const_reverse_iterator const_reverse_iterator; 55 56 public: 57 static RelocData* Create(LDSection& pSection); 58 59 static void Destroy(RelocData*& pSection); 60 61 static void Clear(); 62 getSection()63 const LDSection& getSection() const { return *m_pSection; } getSection()64 LDSection& getSection() { return *m_pSection; } 65 getRelocationList()66 const RelocationListType& getRelocationList() const { return m_Relocations; } getRelocationList()67 RelocationListType& getRelocationList() { return m_Relocations; } 68 size()69 size_t size() const { return m_Relocations.size(); } 70 empty()71 bool empty() const { return m_Relocations.empty(); } 72 73 RelocData& append(Relocation& pRelocation); 74 Relocation& remove(Relocation& pRelocation); 75 front()76 const_reference front() const { return m_Relocations.front(); } front()77 reference front() { return m_Relocations.front(); } back()78 const_reference back() const { return m_Relocations.back(); } back()79 reference back() { return m_Relocations.back(); } 80 begin()81 const_iterator begin() const { return m_Relocations.begin(); } begin()82 iterator begin() { return m_Relocations.begin(); } end()83 const_iterator end() const { return m_Relocations.end(); } end()84 iterator end() { return m_Relocations.end(); } rbegin()85 const_reverse_iterator rbegin() const { return m_Relocations.rbegin(); } rbegin()86 reverse_iterator rbegin() { return m_Relocations.rbegin(); } rend()87 const_reverse_iterator rend() const { return m_Relocations.rend(); } rend()88 reverse_iterator rend() { return m_Relocations.rend(); } 89 90 template <class Comparator> sort(Comparator pComparator)91 void sort(Comparator pComparator) { 92 mcld::sort(m_Relocations, pComparator); 93 } 94 95 private: 96 RelocationListType m_Relocations; 97 LDSection* m_pSection; 98 99 private: 100 DISALLOW_COPY_AND_ASSIGN(RelocData); 101 }; 102 103 } // namespace mcld 104 105 #endif // MCLD_LD_RELOCDATA_H_ 106