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