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_LD_NAMEPOOL_H 10#define MCLD_LD_NAMEPOOL_H 11 12#include <mcld/Config/Config.h> 13#include <mcld/ADT/HashTable.h> 14#include <mcld/ADT/StringHash.h> 15#include <mcld/ADT/Uncopyable.h> 16#include <mcld/LD/Resolver.h> 17#include <mcld/LD/ResolveInfo.h> 18#include <mcld/Support/GCFactory.h> 19 20#include <utility> 21 22#include <llvm/ADT/StringRef.h> 23 24namespace mcld { 25 26class StringTable; 27class SymbolTableIF; 28class SectionData; 29 30/** \class NamePool 31 * \brief Store symbol and search symbol by name. Can help symbol resolution. 32 * 33 * - MCLinker is responsed for creating NamePool. 34 */ 35class NamePool : private Uncopyable 36{ 37public: 38 typedef HashTable<ResolveInfo, hash::StringHash<hash::DJB> > Table; 39 typedef Table::iterator syminfo_iterator; 40 typedef Table::const_iterator const_syminfo_iterator; 41 42 typedef GCFactory<ResolveInfo*, 128> FreeInfoSet; 43 typedef FreeInfoSet::iterator freeinfo_iterator; 44 typedef FreeInfoSet::const_iterator const_freeinfo_iterator; 45 46 typedef size_t size_type; 47 48public: 49 explicit NamePool(size_type pSize = 3); 50 51 ~NamePool(); 52 53 // ----- modifiers ----- // 54 /// createSymbol - create a symbol but do not insert into the pool. 55 /// The created symbol did not go through the path of symbol resolution. 56 ResolveInfo* createSymbol(const llvm::StringRef& pName, 57 bool pIsDyn, 58 ResolveInfo::Type pType, 59 ResolveInfo::Desc pDesc, 60 ResolveInfo::Binding pBinding, 61 ResolveInfo::SizeType pSize, 62 ResolveInfo::Visibility pVisibility = ResolveInfo::Default); 63 64 /// insertSymbol - insert a symbol and resolve the symbol immediately 65 /// @param pOldInfo - if pOldInfo is not NULL, the old ResolveInfo being 66 /// overriden is kept in pOldInfo. 67 /// @param pResult the result of symbol resultion. 68 /// @note pResult.override is true if the output LDSymbol also need to be 69 /// overriden 70 void insertSymbol(const llvm::StringRef& pName, 71 bool pIsDyn, 72 ResolveInfo::Type pType, 73 ResolveInfo::Desc pDesc, 74 ResolveInfo::Binding pBinding, 75 ResolveInfo::SizeType pSize, 76 LDSymbol::ValueType pValue, 77 ResolveInfo::Visibility pVisibility, 78 ResolveInfo* pOldInfo, 79 Resolver::Result& pResult); 80 81 /// findSymbol - find the resolved output LDSymbol 82 const LDSymbol* findSymbol(const llvm::StringRef& pName) const; 83 LDSymbol* findSymbol(const llvm::StringRef& pName); 84 85 /// findInfo - find the resolved ResolveInfo 86 const ResolveInfo* findInfo(const llvm::StringRef& pName) const; 87 ResolveInfo* findInfo(const llvm::StringRef& pName); 88 89 /// insertString - insert a string 90 /// if the string has existed, modify pString to the existing string 91 /// @return the StringRef points to the hash table 92 llvm::StringRef insertString(const llvm::StringRef& pString); 93 94 // ----- observers ----- // 95 size_type size() const 96 { return m_Table.numOfEntries(); } 97 98 bool empty() const 99 { return m_Table.empty(); } 100 101 // syminfo_iterator - traverse the ResolveInfo in the resolved HashTable 102 syminfo_iterator syminfo_begin() 103 { return m_Table.begin(); } 104 105 syminfo_iterator syminfo_end() 106 { return m_Table.end(); } 107 108 const_syminfo_iterator syminfo_begin() const 109 { return m_Table.begin(); } 110 111 const_syminfo_iterator syminfo_end() const 112 { return m_Table.end(); } 113 114 // freeinfo_iterator - traverse the ResolveInfo those do not need to be 115 // resolved, for example, local symbols 116 freeinfo_iterator freeinfo_begin() 117 { return m_FreeInfoSet.begin(); } 118 119 freeinfo_iterator freeinfo_end() 120 { return m_FreeInfoSet.end(); } 121 122 const_freeinfo_iterator freeinfo_begin() const 123 { return m_FreeInfoSet.begin(); } 124 125 const_freeinfo_iterator freeinfo_end() const 126 { return m_FreeInfoSet.end(); } 127 128 // ----- capacity ----- // 129 void reserve(size_type pN); 130 131 size_type capacity() const; 132 133private: 134 Resolver* m_pResolver; 135 Table m_Table; 136 FreeInfoSet m_FreeInfoSet; 137}; 138 139} // namespace of mcld 140 141#endif 142 143