1 //===- ELFSegmentFactory.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_ELFSEGMENTFACTORY_H_
10 #define MCLD_LD_ELFSEGMENTFACTORY_H_
11 
12 #include <llvm/Support/DataTypes.h>
13 #include <llvm/Support/ELF.h>
14 
15 #include <vector>
16 
17 namespace mcld {
18 
19 class ELFSegment;
20 class LDSection;
21 
22 /** \class ELFSegmentFactory
23  *  \brief provide the interface to create and delete an ELFSegment
24  */
25 class ELFSegmentFactory {
26  public:
27   typedef std::vector<ELFSegment*> Segments;
28   typedef Segments::const_iterator const_iterator;
29   typedef Segments::iterator iterator;
30 
begin()31   const_iterator begin() const { return m_Segments.begin(); }
begin()32   iterator begin() { return m_Segments.begin(); }
end()33   const_iterator end() const { return m_Segments.end(); }
end()34   iterator end() { return m_Segments.end(); }
35 
front()36   const ELFSegment* front() const { return m_Segments.front(); }
front()37   ELFSegment* front() { return m_Segments.front(); }
back()38   const ELFSegment* back() const { return m_Segments.back(); }
back()39   ELFSegment* back() { return m_Segments.back(); }
40 
size()41   size_t size() const { return m_Segments.size(); }
42 
empty()43   bool empty() const { return m_Segments.empty(); }
44 
45   iterator find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear);
46 
47   const_iterator find(uint32_t pType,
48                       uint32_t pFlagSet,
49                       uint32_t pFlagClear) const;
50 
51   iterator find(uint32_t pType, const LDSection* pSection);
52 
53   const_iterator find(uint32_t pType, const LDSection* pSection) const;
54 
55   /// produce - produce an empty ELF segment information.
56   /// this function will create an ELF segment
57   /// @param pType - p_type in ELF program header
58   ELFSegment* produce(uint32_t pType, uint32_t pFlag = llvm::ELF::PF_R);
59 
60   ELFSegment* insert(iterator pPosition,
61                      uint32_t pType,
62                      uint32_t pFlag = llvm::ELF::PF_R);
63 
64   void erase(iterator pSegment);
65 
66  private:
67   Segments m_Segments;
68 };
69 
70 }  // namespace mcld
71 
72 #endif  // MCLD_LD_ELFSEGMENTFACTORY_H_
73