Home | History | Annotate | Download | only in LD
      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 #include <vector>
     15 
     16 namespace mcld
     17 {
     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 {
     27 public:
     28   typedef std::vector<ELFSegment*> Segments;
     29   typedef Segments::const_iterator const_iterator;
     30   typedef Segments::iterator iterator;
     31 
     32   const_iterator begin() const { return m_Segments.begin(); }
     33   iterator       begin()       { return m_Segments.begin(); }
     34   const_iterator end()   const { return m_Segments.end(); }
     35   iterator       end()         { return m_Segments.end(); }
     36 
     37   const ELFSegment* front() const { return m_Segments.front(); }
     38   ELFSegment*       front()       { return m_Segments.front(); }
     39   const ELFSegment* back()  const { return m_Segments.back(); }
     40   ELFSegment*       back()        { return m_Segments.back(); }
     41 
     42   size_t size() const { return m_Segments.size(); }
     43 
     44   bool empty() const { return m_Segments.empty(); }
     45 
     46   iterator find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear);
     47 
     48   const_iterator
     49   find(uint32_t pType, uint32_t pFlagSet, 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   void erase(iterator pSegment);
     61 
     62 private:
     63   Segments m_Segments;
     64 };
     65 
     66 } // namespace of mcld
     67 
     68 #endif
     69 
     70