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 using namespace mcld;
13
14 //===----------------------------------------------------------------------===//
15 // ELFSegmentFactory
16 //===----------------------------------------------------------------------===//
17
18 ELFSegmentFactory::iterator
find(uint32_t pType,uint32_t pFlagSet,uint32_t pFlagClear)19 ELFSegmentFactory::find(uint32_t pType, uint32_t pFlagSet, uint32_t pFlagClear)
20 {
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
32 ELFSegmentFactory::const_iterator
find(uint32_t pType,uint32_t pFlagSet,uint32_t pFlagClear) const33 ELFSegmentFactory::find(uint32_t pType,
34 uint32_t pFlagSet,
35 uint32_t pFlagClear) const
36 {
37 const_iterator segment, segEnd = end();
38 for (segment = begin(); segment != segEnd; ++segment) {
39 if ((*segment)->type() == pType &&
40 ((*segment)->flag() & pFlagSet) == pFlagSet &&
41 ((*segment)->flag() & pFlagClear) == 0x0) {
42 return segment;
43 }
44 }
45 return segEnd;
46 }
47
48 ELFSegmentFactory::iterator
find(uint32_t pType,const LDSection * pSection)49 ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection)
50 {
51 iterator segment, segEnd = end();
52 for (segment = begin(); segment != segEnd; ++segment) {
53 if ((*segment)->type() == pType) {
54 ELFSegment::iterator sect, sectEnd = (*segment)->end();
55 for (sect = (*segment)->begin(); sect != sectEnd; ++sect) {
56 if (*sect == pSection)
57 return segment;
58 } // for each section
59 }
60 } // for each segment
61 return segEnd;
62 }
63
64 ELFSegmentFactory::const_iterator
find(uint32_t pType,const LDSection * pSection) const65 ELFSegmentFactory::find(uint32_t pType, const LDSection* pSection) const
66 {
67 const_iterator segment, segEnd = end();
68 for (segment = begin(); segment != segEnd; ++segment) {
69 if ((*segment)->type() == pType) {
70 ELFSegment::const_iterator sect, sectEnd = (*segment)->end();
71 for (sect = (*segment)->begin(); sect != sectEnd; ++sect) {
72 if (*sect == pSection)
73 return segment;
74 } // for each section
75 }
76 } // for each segment
77 return segEnd;
78 }
79
produce(uint32_t pType,uint32_t pFlag)80 ELFSegment* ELFSegmentFactory::produce(uint32_t pType, uint32_t pFlag)
81 {
82 m_Segments.push_back(ELFSegment::Create(pType, pFlag));
83 return back();
84 }
85
erase(iterator pSegment)86 void ELFSegmentFactory::erase(iterator pSegment)
87 {
88 m_Segments.erase(pSegment);
89 }
90