1 //===- NamePool.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_NAME_POOL_H 10 #define MCLD_NAME_POOL_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <utility> 16 17 #include <llvm/ADT/StringRef.h> 18 19 #include <mcld/ADT/HashTable.h> 20 #include <mcld/ADT/StringHash.h> 21 #include <mcld/ADT/Uncopyable.h> 22 #include <mcld/LD/ResolveInfo.h> 23 #include <mcld/LD/Resolver.h> 24 #include <mcld/LD/ResolveInfoFactory.h> 25 26 namespace mcld 27 { 28 29 class Resolver; 30 class StringTable; 31 class SymbolTableIF; 32 class SectionData; 33 34 /** \class NamePool 35 * \brief Store symbol and search symbol by name. Can help symbol resolution. 36 * 37 * - MCLinker is responsed for creating NamePool. 38 */ 39 class NamePool : private Uncopyable 40 { 41 public: 42 typedef HashTable<ResolveInfo, StringHash<ELF>, ResolveInfoFactory> Table; 43 typedef size_t size_type; 44 45 public: 46 NamePool(const Resolver& pResolver, size_type pSize = 3); 47 ~NamePool(); 48 49 // ----- modifiers ----- // 50 /// createSymbol - create a symbol but do not insert into the pool. 51 ResolveInfo* createSymbol(const llvm::StringRef& pName, 52 bool pIsDyn, 53 ResolveInfo::Type pType, 54 ResolveInfo::Desc pDesc, 55 ResolveInfo::Binding pBinding, 56 ResolveInfo::SizeType pSize, 57 ResolveInfo::Visibility pVisibility = ResolveInfo::Default); 58 59 /// insertSymbol - insert a symbol and resolve the symbol immediately 60 /// @param pOldInfo - if pOldInfo is not NULL, the old ResolveInfo being 61 /// overriden is kept in pOldInfo. 62 /// @param pResult the result of symbol resultion. 63 /// @note pResult.override is true if the output LDSymbol also need to be 64 /// overriden 65 void insertSymbol(const llvm::StringRef& pName, 66 bool pIsDyn, 67 ResolveInfo::Type pType, 68 ResolveInfo::Desc pDesc, 69 ResolveInfo::Binding pBinding, 70 ResolveInfo::SizeType pSize, 71 ResolveInfo::Visibility pVisibility, 72 ResolveInfo* pOldInfo, 73 Resolver::Result& pResult); 74 75 /// findSymbol - find the resolved output LDSymbol 76 LDSymbol* findSymbol(const llvm::StringRef& pName); 77 const LDSymbol* findSymbol(const llvm::StringRef& pName) const; 78 79 /// findInfo - find the resolved ResolveInfo 80 ResolveInfo* findInfo(const llvm::StringRef& pName); 81 const ResolveInfo* findInfo(const llvm::StringRef& pName) const; 82 83 /// insertString - insert a string 84 /// if the string has existed, modify pString to the existing string 85 /// @return the StringRef points to the hash table 86 llvm::StringRef insertString(const llvm::StringRef& pString); 87 88 // ----- observers ----- // size()89 size_type size() const 90 { return m_Table.numOfEntries(); } 91 empty()92 bool empty() const 93 { return m_Table.empty(); } 94 95 // ----- capacity ----- // 96 void reserve(size_type pN); 97 98 size_type capacity() const; 99 100 private: 101 const Resolver* m_pResolver; 102 Table m_Table; 103 104 }; 105 106 } // namespace of mcld 107 108 #endif 109 110