1 //===- LDContext.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/LDContext.h> 10 #include <mcld/LD/LDSection.h> 11 #include <mcld/LD/LDSymbol.h> 12 #include <llvm/ADT/StringRef.h> 13 14 using namespace mcld; 15 16 //===----------------------------------------------------------------------===// 17 // LDContext 18 //===----------------------------------------------------------------------===// appendSection(LDSection & pSection)19LDContext& LDContext::appendSection(LDSection& pSection) 20 { 21 if (LDFileFormat::Relocation == pSection.kind()) 22 m_RelocSections.push_back(&pSection); 23 pSection.setIndex(m_SectionTable.size()); 24 m_SectionTable.push_back(&pSection); 25 return *this; 26 } 27 getSection(unsigned int pIdx)28LDSection* LDContext::getSection(unsigned int pIdx) 29 { 30 if (pIdx >= m_SectionTable.size()) 31 return NULL; 32 return m_SectionTable[pIdx]; 33 } 34 getSection(unsigned int pIdx) const35const LDSection* LDContext::getSection(unsigned int pIdx) const 36 { 37 if (pIdx >= m_SectionTable.size()) 38 return NULL; 39 return m_SectionTable[pIdx]; 40 } 41 getSection(const std::string & pName)42LDSection* LDContext::getSection(const std::string& pName) 43 { 44 sect_iterator sect_iter, sect_end = sectEnd(); 45 for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) { 46 if(NULL != *sect_iter && (*sect_iter)->name() == pName) 47 return *sect_iter; 48 } 49 return NULL; 50 } 51 getSection(const std::string & pName) const52const LDSection* LDContext::getSection(const std::string& pName) const 53 { 54 const_sect_iterator sect_iter, sect_end = sectEnd(); 55 for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) { 56 if(NULL != *sect_iter && (*sect_iter)->name() == pName) 57 return *sect_iter; 58 } 59 return NULL; 60 } 61 getSectionIdx(const std::string & pName) const62size_t LDContext::getSectionIdx(const std::string& pName) const 63 { 64 size_t result = 1; 65 size_t size = m_SectionTable.size(); 66 for (; result != size; ++result) 67 if (m_SectionTable[result]->name() == pName) 68 return result; 69 return 0; 70 } 71 getSymbol(unsigned int pIdx)72LDSymbol* LDContext::getSymbol(unsigned int pIdx) 73 { 74 if (pIdx >= m_SymTab.size()) 75 return NULL; 76 return m_SymTab[pIdx]; 77 } 78 getSymbol(unsigned int pIdx) const79const LDSymbol* LDContext::getSymbol(unsigned int pIdx) const 80 { 81 if (pIdx >= m_SymTab.size()) 82 return NULL; 83 return m_SymTab[pIdx]; 84 } 85 86 getSymbol(const llvm::StringRef & pName)87LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) 88 { 89 size_t sym = 1; 90 size_t size = m_SymTab.size(); 91 for (; sym < size; ++sym) 92 if (m_SymTab[sym]->name() == pName) 93 return m_SymTab[sym]; 94 return NULL; 95 } 96 getSymbol(const llvm::StringRef & pName) const97const LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) const 98 { 99 size_t sym = 1; 100 size_t size = m_SymTab.size(); 101 for (; sym < size; ++sym) 102 if (m_SymTab[sym]->name() == pName) 103 return m_SymTab[sym]; 104 return NULL; 105 } 106