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