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