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