RelocData.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
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 <llvm/ADT/ilist.h>
16#include <llvm/ADT/ilist_node.h>
17#include <llvm/Support/DataTypes.h>
18
19#include <mcld/Config/Config.h>
20#include <mcld/Fragment/Fragment.h>
21#include <mcld/Support/Allocators.h>
22#include <mcld/Support/GCFactoryListTraits.h>
23
24
25namespace mcld {
26
27class LDSection;
28
29/** \class RelocData
30 *  \brief RelocData is the special SectionData to store Relocation fragments.
31 *  Since Relocations are created by GCFactory, we use GCFactoryListTraits for the
32 *  FragmentList here to avoid iplist to delete Relocations.
33 */
34class RelocData
35{
36private:
37  RelocData();
38  explicit RelocData(const LDSection &pSection);
39
40  RelocData(const RelocData &);            // DO NOT IMPLEMENT
41  RelocData& operator=(const RelocData &); // DO NOT IMPLEMENT
42
43public:
44  typedef llvm::iplist<Fragment,
45                       GCFactoryListTraits<Fragment> > FragmentListType;
46
47  typedef FragmentListType::reference reference;
48  typedef FragmentListType::const_reference const_reference;
49
50  typedef FragmentListType::iterator iterator;
51  typedef FragmentListType::const_iterator const_iterator;
52
53  typedef FragmentListType::reverse_iterator reverse_iterator;
54  typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
55
56public:
57  static RelocData* Create(const LDSection& pSection);
58
59  static RelocData* Create();
60
61  static void Destroy(RelocData*& pSection);
62
63  const LDSection &getSection() const
64  { assert(NULL != m_pSection ); return *m_pSection; }
65
66  FragmentListType &getFragmentList() { return m_Fragments; }
67  const FragmentListType &getFragmentList() const { return m_Fragments; }
68
69  size_t size() const { return m_Fragments.size(); }
70
71  bool empty() const { return m_Fragments.empty(); }
72
73  reference              front ()       { return m_Fragments.front();  }
74  const_reference        front () const { return m_Fragments.front();  }
75  reference              back  ()       { return m_Fragments.back();   }
76  const_reference        back  () const { return m_Fragments.back();   }
77
78  const_iterator         begin () const { return m_Fragments.begin();  }
79  iterator               begin ()       { return m_Fragments.begin();  }
80  const_iterator         end   () const { return m_Fragments.end();    }
81  iterator               end   ()       { return m_Fragments.end();    }
82  const_reverse_iterator rbegin() const { return m_Fragments.rbegin(); }
83  reverse_iterator       rbegin()       { return m_Fragments.rbegin(); }
84  const_reverse_iterator rend  () const { return m_Fragments.rend();   }
85  reverse_iterator       rend  ()       { return m_Fragments.rend();   }
86
87private:
88  FragmentListType m_Fragments;
89  const LDSection* m_pSection;
90
91};
92
93} // namespace of mcld
94
95#endif
96
97