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