• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #include <llvm/ADT/StringRef.h>
14 
15 namespace mcld {
16 
17 //===----------------------------------------------------------------------===//
18 // LDContext
19 //===----------------------------------------------------------------------===//
appendSection(LDSection & pSection)20 LDContext& LDContext::appendSection(LDSection& pSection) {
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)28 LDSection* LDContext::getSection(unsigned int pIdx) {
29   if (pIdx >= m_SectionTable.size())
30     return NULL;
31   return m_SectionTable[pIdx];
32 }
33 
getSection(unsigned int pIdx) const34 const LDSection* LDContext::getSection(unsigned int pIdx) const {
35   if (pIdx >= m_SectionTable.size())
36     return NULL;
37   return m_SectionTable[pIdx];
38 }
39 
getSection(const std::string & pName)40 LDSection* LDContext::getSection(const std::string& pName) {
41   sect_iterator sect_iter, sect_end = sectEnd();
42   for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) {
43     if (*sect_iter != NULL && (*sect_iter)->name() == pName)
44       return *sect_iter;
45   }
46   return NULL;
47 }
48 
getSection(const std::string & pName) const49 const LDSection* LDContext::getSection(const std::string& pName) const {
50   const_sect_iterator sect_iter, sect_end = sectEnd();
51   for (sect_iter = sectBegin(); sect_iter != sect_end; ++sect_iter) {
52     if (*sect_iter != NULL && (*sect_iter)->name() == pName)
53       return *sect_iter;
54   }
55   return NULL;
56 }
57 
getSectionIdx(const std::string & pName) const58 size_t LDContext::getSectionIdx(const std::string& pName) const {
59   size_t result = 1;
60   size_t size = m_SectionTable.size();
61   for (; result != size; ++result)
62     if (m_SectionTable[result]->name() == pName)
63       return result;
64   return 0;
65 }
66 
getSymbol(unsigned int pIdx)67 LDSymbol* LDContext::getSymbol(unsigned int pIdx) {
68   if (pIdx >= m_SymTab.size())
69     return NULL;
70   return m_SymTab[pIdx];
71 }
72 
getSymbol(unsigned int pIdx) const73 const LDSymbol* LDContext::getSymbol(unsigned int pIdx) const {
74   if (pIdx >= m_SymTab.size())
75     return NULL;
76   return m_SymTab[pIdx];
77 }
78 
getSymbol(const llvm::StringRef & pName)79 LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) {
80   size_t sym = 1;
81   size_t size = m_SymTab.size();
82   for (; sym < size; ++sym)
83     if (m_SymTab[sym]->name() == pName)
84       return m_SymTab[sym];
85   return NULL;
86 }
87 
getSymbol(const llvm::StringRef & pName) const88 const LDSymbol* LDContext::getSymbol(const llvm::StringRef& pName) const {
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 
97 }  // namespace mcld
98