1 //===- ELFSegmentFactory.cpp ----------------------------------------------===// 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 #include "mcld/LD/ELFSegmentFactory.h" 10 #include "mcld/LD/ELFSegment.h" 11 12 namespace mcld { 13 14 //===----------------------------------------------------------------------===// 15 // ELFSegmentFactory 16 //===----------------------------------------------------------------------===// 17 find(uint32_t pType,uint32_t pFlagSet,uint32_t pFlagClear)18 ELFSegmentFactory::iterator ELFSegmentFactory::find(uint32_t pType, 19 uint32_t pFlagSet, 20 uint32_t pFlagClear) { 21 iterator segment, segEnd = end(); 22 for (segment = begin(); segment != segEnd; ++segment) { 23 if ((*segment)->type() == pType && 24 ((*segment)->flag() & pFlagSet) == pFlagSet && 25 ((*segment)->flag() & pFlagClear) == 0x0) { 26 return segment; 27 } 28 } 29 return segEnd; 30 } 31 find(uint32_t pType,uint32_t pFlagSet,uint32_t pFlagClear) const32 ELFSegmentFactory::const_iterator ELFSegmentFactory::find( 33 uint32_t pType, 34 uint32_t pFlagSet, 35 uint32_t pFlagClear) const { 36 const_iterator segment, segEnd = end(); 37 for (segment = begin(); segment != segEnd; ++segment) { 38 if ((*segment)->type() == pType && 39 ((*segment)->flag() & pFlagSet) == pFlagSet && 40 ((*segment)->flag() & pFlagClear) == 0x0) { 41 return segment; 42 } 43 } 44 return segEnd; 45 } 46 find(uint32_t pType,const LDSection * pSection)47 ELFSegmentFactory::iterator ELFSegmentFactory::find(uint32_t pType, 48 const LDSection* pSection) { 49 iterator segment, segEnd = end(); 50 for (segment = begin(); segment != segEnd; ++segment) { 51 if ((*segment)->type() == pType) { 52 ELFSegment::iterator sect, sectEnd = (*segment)->end(); 53 for (sect = (*segment)->begin(); sect != sectEnd; ++sect) { 54 if (*sect == pSection) 55 return segment; 56 } // for each section 57 } 58 } // for each segment 59 return segEnd; 60 } 61 find(uint32_t pType,const LDSection * pSection) const62 ELFSegmentFactory::const_iterator ELFSegmentFactory::find( 63 uint32_t pType, 64 const LDSection* pSection) const { 65 const_iterator segment, segEnd = end(); 66 for (segment = begin(); segment != segEnd; ++segment) { 67 if ((*segment)->type() == pType) { 68 ELFSegment::const_iterator sect, sectEnd = (*segment)->end(); 69 for (sect = (*segment)->begin(); sect != sectEnd; ++sect) { 70 if (*sect == pSection) 71 return segment; 72 } // for each section 73 } 74 } // for each segment 75 return segEnd; 76 } 77 produce(uint32_t pType,uint32_t pFlag)78 ELFSegment* ELFSegmentFactory::produce(uint32_t pType, uint32_t pFlag) { 79 m_Segments.push_back(ELFSegment::Create(pType, pFlag)); 80 return back(); 81 } 82 insert(iterator pPosition,uint32_t pType,uint32_t pFlag)83 ELFSegment* ELFSegmentFactory::insert(iterator pPosition, 84 uint32_t pType, 85 uint32_t pFlag) { 86 return *(m_Segments.insert(pPosition, ELFSegment::Create(pType, pFlag))); 87 } 88 erase(iterator pSegment)89 void ELFSegmentFactory::erase(iterator pSegment) { 90 m_Segments.erase(pSegment); 91 } 92 93 } // namespace mcld 94