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