• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class LDSymbol;
28 class LDSection;
29 
30 /** \class LDContext
31  *  \brief LDContext stores the data which a object file should has
32  */
33 class LDContext
34 {
35 public:
36   typedef std::vector<LDSection*> SectionTable;
37   typedef SectionTable::iterator sect_iterator;
38   typedef SectionTable::const_iterator const_sect_iterator;
39 
40   typedef std::vector<LDSymbol*> SymbolTable;
41   typedef SymbolTable::iterator sym_iterator;
42   typedef SymbolTable::const_iterator const_sym_iterator;
43 
44 public:
45   // -----  sections  ----- //
46   LDContext& appendSection(LDSection& pSection);
47 
sectBegin()48   const_sect_iterator sectBegin() const { return m_SectionTable.begin(); }
sectBegin()49   sect_iterator       sectBegin()       { return m_SectionTable.begin(); }
50 
sectEnd()51   const_sect_iterator sectEnd() const { return m_SectionTable.end(); }
sectEnd()52   sect_iterator       sectEnd()       { return m_SectionTable.end(); }
53 
54   const LDSection* getSection(unsigned int pIdx) const;
55   LDSection*       getSection(unsigned int pIdx);
56 
57   const LDSection* getSection(const std::string& pName) const;
58   LDSection*       getSection(const std::string& pName);
59 
60   size_t getSectionIdx(const std::string& pName) const;
61 
numOfSections()62   size_t numOfSections() const
63   { return m_SectionTable.size(); }
64 
65   // -----  symbols  ----- //
66   const LDSymbol* getSymbol(unsigned int pIdx) const;
67   LDSymbol*       getSymbol(unsigned int pIdx);
68 
69   const LDSymbol* getSymbol(const llvm::StringRef& pName) const;
70   LDSymbol*       getSymbol(const llvm::StringRef& pName);
71 
addSymbol(LDSymbol * pSym)72   void addSymbol(LDSymbol* pSym)
73   { m_SymTab.push_back(pSym); }
74 
75   // -----  relocations  ----- //
relocSectBegin()76   const_sect_iterator relocSectBegin() const { return m_RelocSections.begin(); }
relocSectBegin()77   sect_iterator       relocSectBegin()       { return m_RelocSections.begin(); }
78 
relocSectEnd()79   const_sect_iterator relocSectEnd() const { return m_RelocSections.end(); }
relocSectEnd()80   sect_iterator       relocSectEnd()       { return m_RelocSections.end(); }
81 
82 private:
83   SectionTable m_SectionTable;
84   SymbolTable m_SymTab;
85   SectionTable m_RelocSections;
86 
87   // FIXME : maintain a map<section name, section index>
88 };
89 
90 
91 } // namespace of mcld
92 
93 #endif
94 
95