122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===- RelocData.h --------------------------------------------------------===//
222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//
322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//                     The MCLinker Project
422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//
522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao// This file is distributed under the University of Illinois Open Source
622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao// License. See LICENSE.TXT for details.
722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//
822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===//
987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#ifndef MCLD_LD_RELOCDATA_H
1087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#define MCLD_LD_RELOCDATA_H
1122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
1222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#include <mcld/Config/Config.h>
13d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <mcld/Fragment/Relocation.h>
1422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#include <mcld/Support/Allocators.h>
1522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#include <mcld/Support/GCFactoryListTraits.h>
1622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
17d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <llvm/ADT/ilist.h>
18d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <llvm/ADT/ilist_node.h>
19d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao#include <llvm/Support/DataTypes.h>
2022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
2187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#include <list>
2287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
2322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaonamespace mcld {
2422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
2522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoclass LDSection;
2622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
2722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao/** \class RelocData
28d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao *  \brief RelocData stores Relocation.
29d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao *
3022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao *  Since Relocations are created by GCFactory, we use GCFactoryListTraits for the
31d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao *  RelocationList here to avoid iplist to delete Relocations.
3222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao */
3322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoclass RelocData
3422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao{
3522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoprivate:
36d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  friend class Chunk<RelocData, MCLD_SECTIONS_PER_INPUT>;
37d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao
3822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  RelocData();
39d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  explicit RelocData(LDSection &pSection);
4022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
4122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  RelocData(const RelocData &);            // DO NOT IMPLEMENT
4222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  RelocData& operator=(const RelocData &); // DO NOT IMPLEMENT
4322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
4422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaopublic:
45d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  typedef llvm::iplist<Relocation,
46d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao                       GCFactoryListTraits<Relocation> > RelocationListType;
4722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
48d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  typedef RelocationListType::reference reference;
49d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  typedef RelocationListType::const_reference const_reference;
5022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
51d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  typedef RelocationListType::iterator iterator;
52d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  typedef RelocationListType::const_iterator const_iterator;
5322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
54d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  typedef RelocationListType::reverse_iterator reverse_iterator;
55d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  typedef RelocationListType::const_reverse_iterator const_reverse_iterator;
5622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
5722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaopublic:
58d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  static RelocData* Create(LDSection& pSection);
5922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
6022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  static void Destroy(RelocData*& pSection);
6122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
62d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  static void Clear();
63d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao
64d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const LDSection& getSection() const { return *m_pSection; }
65d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  LDSection&       getSection()       { return *m_pSection; }
66d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao
67d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const RelocationListType& getRelocationList() const { return m_Relocations; }
68d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  RelocationListType&       getRelocationList()       { return m_Relocations; }
6922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
70d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  size_t size() const { return m_Relocations.size(); }
7122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
72d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  bool empty() const { return m_Relocations.empty(); }
7322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
74d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  RelocData& append(Relocation& pRelocation);
7587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  Relocation& remove(Relocation& pRelocation);
7622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
77d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  reference              front ()       { return m_Relocations.front();  }
78d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const_reference        front () const { return m_Relocations.front();  }
79d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  reference              back  ()       { return m_Relocations.back();   }
80d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const_reference        back  () const { return m_Relocations.back();   }
8122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
82d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const_iterator         begin () const { return m_Relocations.begin();  }
83d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  iterator               begin ()       { return m_Relocations.begin();  }
84d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const_iterator         end   () const { return m_Relocations.end();    }
85d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  iterator               end   ()       { return m_Relocations.end();    }
86d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const_reverse_iterator rbegin() const { return m_Relocations.rbegin(); }
87d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  reverse_iterator       rbegin()       { return m_Relocations.rbegin(); }
88d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  const_reverse_iterator rend  () const { return m_Relocations.rend();   }
89d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  reverse_iterator       rend  ()       { return m_Relocations.rend();   }
9022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
9187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  template<class Comparator> void sort(Comparator pComparator) {
9287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines    /* FIXME: use llvm::iplist::sort */
9387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines    std::list<Relocation*> relocs;
9487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines    for (iterator it = begin(), ie = end(); it != ie; ++it)
9587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines      relocs.push_back(it);
9687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines    relocs.sort(pComparator);
9787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines    m_Relocations.clear();
9887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines    for (std::list<Relocation*>::iterator it = relocs.begin(),
9987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines      ie = relocs.end(); it != ie; ++it)
10087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines      m_Relocations.push_back(*it);
10187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines  }
10287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
10322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liaoprivate:
104d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  RelocationListType m_Relocations;
105d0fbbb227051be16931a1aa9b4a7722ac039c698Shih-wei Liao  LDSection* m_pSection;
10622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
10722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao};
10822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
10922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao} // namespace of mcld
11022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
11122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#endif
11222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
113