1 //===- LDContext.h --------------------------------------------------------===// 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 #ifndef MCLD_LD_LDCONTEXT_H 10 #define MCLD_LD_LDCONTEXT_H 11 12 #include <vector> 13 #include <mcld/LD/LDFileFormat.h> 14 #include <llvm/Support/DataTypes.h> 15 #include <string> 16 #include <cassert> 17 18 namespace llvm { 19 class StringRef; 20 } 21 22 namespace mcld { 23 24 class LDSymbol; 25 class LDSection; 26 27 /** \class LDContext 28 * \brief LDContext stores the data which a object file should has 29 */ 30 class LDContext 31 { 32 public: 33 typedef std::vector<LDSection*> SectionTable; 34 typedef SectionTable::iterator sect_iterator; 35 typedef SectionTable::const_iterator const_sect_iterator; 36 37 typedef std::vector<LDSymbol*> SymbolTable; 38 typedef SymbolTable::iterator sym_iterator; 39 typedef SymbolTable::const_iterator const_sym_iterator; 40 41 public: 42 // ----- sections ----- // 43 LDContext& appendSection(LDSection& pSection); 44 45 const_sect_iterator sectBegin() const { return m_SectionTable.begin(); } 46 sect_iterator sectBegin() { return m_SectionTable.begin(); } 47 48 const_sect_iterator sectEnd() const { return m_SectionTable.end(); } 49 sect_iterator sectEnd() { return m_SectionTable.end(); } 50 51 const LDSection* getSection(unsigned int pIdx) const; 52 LDSection* getSection(unsigned int pIdx); 53 54 const LDSection* getSection(const std::string& pName) const; 55 LDSection* getSection(const std::string& pName); 56 57 size_t getSectionIdx(const std::string& pName) const; 58 59 size_t numOfSections() const 60 { return m_SectionTable.size(); } 61 62 // ----- symbols ----- // 63 const LDSymbol* getSymbol(unsigned int pIdx) const; 64 LDSymbol* getSymbol(unsigned int pIdx); 65 66 const LDSymbol* getSymbol(const llvm::StringRef& pName) const; 67 LDSymbol* getSymbol(const llvm::StringRef& pName); 68 69 void addSymbol(LDSymbol* pSym) 70 { m_SymTab.push_back(pSym); } 71 72 const_sym_iterator symTabBegin() const { return m_SymTab.begin(); } 73 sym_iterator symTabBegin() { return m_SymTab.begin(); } 74 75 const_sym_iterator symTabEnd() const { return m_SymTab.end(); } 76 sym_iterator symTabEnd() { return m_SymTab.end(); } 77 78 // ----- relocations ----- // 79 const_sect_iterator relocSectBegin() const { return m_RelocSections.begin(); } 80 sect_iterator relocSectBegin() { return m_RelocSections.begin(); } 81 82 const_sect_iterator relocSectEnd() const { return m_RelocSections.end(); } 83 sect_iterator relocSectEnd() { return m_RelocSections.end(); } 84 85 private: 86 SectionTable m_SectionTable; 87 SymbolTable m_SymTab; 88 SectionTable m_RelocSections; 89 90 // FIXME : maintain a map<section name, section index> 91 }; 92 93 94 } // namespace of mcld 95 96 #endif 97 98