• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RELOCATION_DATA_H
10 #define MCLD_RELOCATION_DATA_H
11 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 
15 #include <mcld/Config/Config.h>
16 #include <mcld/Fragment/Relocation.h>
17 #include <mcld/Support/Allocators.h>
18 #include <mcld/Support/GCFactoryListTraits.h>
19 
20 #include <llvm/ADT/ilist.h>
21 #include <llvm/ADT/ilist_node.h>
22 #include <llvm/Support/DataTypes.h>
23 
24 namespace mcld {
25 
26 class LDSection;
27 
28 /** \class RelocData
29  *  \brief RelocData stores Relocation.
30  *
31  *  Since Relocations are created by GCFactory, we use GCFactoryListTraits for the
32  *  RelocationList here to avoid iplist to delete Relocations.
33  */
34 class RelocData
35 {
36 private:
37   friend class Chunk<RelocData, MCLD_SECTIONS_PER_INPUT>;
38 
39   RelocData();
40   explicit RelocData(LDSection &pSection);
41 
42   RelocData(const RelocData &);            // DO NOT IMPLEMENT
43   RelocData& operator=(const RelocData &); // DO NOT IMPLEMENT
44 
45 public:
46   typedef llvm::iplist<Relocation,
47                        GCFactoryListTraits<Relocation> > RelocationListType;
48 
49   typedef RelocationListType::reference reference;
50   typedef RelocationListType::const_reference const_reference;
51 
52   typedef RelocationListType::iterator iterator;
53   typedef RelocationListType::const_iterator const_iterator;
54 
55   typedef RelocationListType::reverse_iterator reverse_iterator;
56   typedef RelocationListType::const_reverse_iterator const_reverse_iterator;
57 
58 public:
59   static RelocData* Create(LDSection& pSection);
60 
61   static void Destroy(RelocData*& pSection);
62 
63   static void Clear();
64 
getSection()65   const LDSection& getSection() const { return *m_pSection; }
getSection()66   LDSection&       getSection()       { return *m_pSection; }
67 
getRelocationList()68   const RelocationListType& getRelocationList() const { return m_Relocations; }
getRelocationList()69   RelocationListType&       getRelocationList()       { return m_Relocations; }
70 
size()71   size_t size() const { return m_Relocations.size(); }
72 
empty()73   bool empty() const { return m_Relocations.empty(); }
74 
75   RelocData& append(Relocation& pRelocation);
76 
front()77   reference              front ()       { return m_Relocations.front();  }
front()78   const_reference        front () const { return m_Relocations.front();  }
back()79   reference              back  ()       { return m_Relocations.back();   }
back()80   const_reference        back  () const { return m_Relocations.back();   }
81 
begin()82   const_iterator         begin () const { return m_Relocations.begin();  }
begin()83   iterator               begin ()       { return m_Relocations.begin();  }
end()84   const_iterator         end   () const { return m_Relocations.end();    }
end()85   iterator               end   ()       { return m_Relocations.end();    }
rbegin()86   const_reverse_iterator rbegin() const { return m_Relocations.rbegin(); }
rbegin()87   reverse_iterator       rbegin()       { return m_Relocations.rbegin(); }
rend()88   const_reverse_iterator rend  () const { return m_Relocations.rend();   }
rend()89   reverse_iterator       rend  ()       { return m_Relocations.rend();   }
90 
91 private:
92   RelocationListType m_Relocations;
93   LDSection* m_pSection;
94 
95 };
96 
97 } // namespace of mcld
98 
99 #endif
100 
101