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