SectionSymbolSet.h revision f7ac0f19a1c8d0ad14bcf6456ce368b830fea886
1//===- SectionSymbolSet.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_SECTIONSYMBOLSET_H
10#define MCLD_SECTIONSYMBOLSET_H
11#ifdef ENABLE_UNITTEST
12#include <gtest.h>
13#endif
14
15#include <mcld/ADT/HashTable.h>
16#include <mcld/ADT/HashEntry.h>
17#include <mcld/MC/SymbolCategory.h>
18
19namespace mcld
20{
21
22class LDSection;
23class NamePool;
24class LDSymbol;
25
26/** \class SectionSymbolSet
27 *  \brief SectionSymbolSet contains the section symbols defined by linker for
28 *   the output sections
29 */
30class SectionSymbolSet
31{
32public:
33  typedef SymbolCategory SymbolTable;
34
35public:
36  SectionSymbolSet();
37  ~SectionSymbolSet();
38
39  /// add - create and add an section symbol for the output
40  /// LDSection
41  bool add(LDSection& pOutSect, NamePool& pNamePool);
42
43  /// finalize - set section symbols' fragmentRef and push it into the output
44  /// symbol table
45  bool finalize(LDSection& pOutSect, SymbolTable& pSymTab, bool relocatable);
46
47  /// get - get the section symbol for section pOutpSect
48  LDSymbol* get(const LDSection& pOutSect);
49  const LDSymbol* get(const LDSection& pOutSect) const;
50
51private:
52  /// sectCompare - hash compare function for LDSection*
53  struct SectCompare
54  {
55    bool operator()(const LDSection* X, const LDSection* Y) const
56    { return (X==Y); }
57  };
58
59  /// SectPtrHash - hash function for LDSection*
60  struct SectPtrHash
61  {
62    size_t operator()(const LDSection* pKey) const
63    {
64      return (unsigned((uintptr_t)pKey) >> 4) ^
65             (unsigned((uintptr_t)pKey) >> 9);
66    }
67  };
68
69  typedef HashEntry<const LDSection*, LDSymbol*, SectCompare> SectHashEntryType;
70  typedef HashTable<SectHashEntryType,
71                    SectPtrHash,
72                    EntryFactory<SectHashEntryType> > SectHashTableType;
73
74private:
75  SectHashTableType* m_pSectionSymbolMap;
76};
77
78} // namespace of mcld
79
80#endif
81
82