1 //===- SectionMap.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_SECTION_MAP_H 10 #define MCLD_SECTION_MAP_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <llvm/Support/DataTypes.h> 16 #include <vector> 17 #include <string> 18 19 namespace mcld 20 { 21 22 /** \class SectionMap 23 * \brief descirbe the mappings of input section's name (or prefix) to 24 * its associated output section's name and offset 25 */ 26 class SectionMap 27 { 28 public: 29 // a mapping in SectionMap is the triple of 30 // {input substr, output section's name, output section's offset} 31 struct Mapping { 32 std::string inputSubStr; 33 std::string outputStr; 34 }; 35 36 typedef std::vector<struct Mapping> SectionMappingTy; 37 38 typedef SectionMappingTy::iterator iterator; 39 typedef SectionMappingTy::const_iterator const_iterator; 40 41 public: 42 SectionMap(); 43 ~SectionMap(); 44 45 // get the possible output section name based on the mapping table 46 // return NULL if not found 47 const std::string& getOutputSectName(const std::string& pInput); 48 49 // add a mapping from input substr to output name and offset. 50 bool push_back(const std::string& pInput, 51 const std::string& pOutput); 52 53 // find - return the iterator to the mapping 54 iterator find(const std::string& pInput); 55 56 // at - return the pointer to the mapping 57 Mapping* at(const std::string& pInput); 58 59 // ----- observers ----- // 60 bool empty() const 61 { return m_SectMap.empty(); } 62 63 size_t size() const 64 { return m_SectMap.size(); } 65 66 size_t capacity () const 67 { return m_SectMap.capacity(); } 68 69 // ----- iterators ----- // 70 iterator begin() 71 { return m_SectMap.begin(); } 72 73 iterator end() 74 { return m_SectMap.end(); } 75 76 const_iterator begin() const 77 { return m_SectMap.begin(); } 78 79 const_iterator end() const 80 { return m_SectMap.end(); } 81 82 // initStdSectionMap - add common mappings of ELF and other formats 83 // to SectionMap 84 bool initStdSectionMap(); 85 86 private: 87 struct SectionNameMapping { 88 const char* from; 89 const char* to; 90 }; 91 92 // used to store common mappings of ELF and other formants 93 static const SectionNameMapping m_StdSectionMap[]; 94 95 static const int m_StdSectionMapSize; 96 97 SectionMappingTy m_SectMap; 98 }; 99 100 } // namespace of mcld 101 102 #endif 103 104