LDSymbol.h revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
1//===- LDSymbol.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_SYMBOL_H
10#define MCLD_LD_SYMBOL_H
11#ifdef ENABLE_UNITTEST
12#include <gtest.h>
13#endif
14
15#include <cassert>
16
17#include <mcld/Config/Config.h>
18#include <mcld/ADT/Uncopyable.h>
19#include <mcld/LD/ResolveInfo.h>
20#include <mcld/Support/Allocators.h>
21
22namespace mcld {
23
24class FragmentRef;
25
26/** \class LDSymbol
27 *  \brief LDSymbol provides a consistent abstraction for different formats
28 *  in different targets.
29 */
30class LDSymbol
31{
32public:
33  // FIXME: use SizeTrait<32> or SizeTrait<64> instead of big type
34  typedef ResolveInfo::SizeType SizeType;
35  typedef uint64_t ValueType;
36
37public:
38  ~LDSymbol();
39
40  // -----  factory method ----- //
41  static LDSymbol* Create(ResolveInfo& pResolveInfo);
42
43  static void Destroy(LDSymbol*& pSymbol);
44
45  /// Clear - This function tells MCLinker to clear all created LDSymbols.
46  static void Clear();
47
48  /// NullSymbol() - This returns a reference to a LDSymbol that represents Null
49  /// symbol.
50  static LDSymbol* Null();
51
52  // -----  observers  ----- //
53  bool isNull() const;
54
55  const char* name() const {
56    assert(NULL != m_pResolveInfo);
57    return m_pResolveInfo->name();
58  }
59
60  unsigned int nameSize() const {
61    assert(NULL != m_pResolveInfo);
62    return m_pResolveInfo->nameSize();
63  }
64
65  llvm::StringRef str() const {
66    assert(NULL != m_pResolveInfo);
67    return llvm::StringRef(m_pResolveInfo->name(), m_pResolveInfo->nameSize());
68  }
69
70  bool isDyn() const {
71    assert(NULL != m_pResolveInfo);
72    return m_pResolveInfo->isDyn();
73  }
74
75  unsigned int type() const {
76    assert(NULL != m_pResolveInfo);
77    return m_pResolveInfo->type();
78  }
79 unsigned int desc() const {
80    assert(NULL != m_pResolveInfo);
81    return m_pResolveInfo->desc();
82  }
83  unsigned int binding() const {
84    assert(NULL != m_pResolveInfo);
85    return m_pResolveInfo->binding();
86  }
87
88  uint8_t other() const {
89    assert(NULL != m_pResolveInfo);
90    return m_pResolveInfo->other();
91  }
92
93  uint8_t visibility() const {
94    assert(NULL != m_pResolveInfo);
95    return m_pResolveInfo->other();
96  }
97
98  ValueType value() const
99  { return m_Value; }
100
101  const FragmentRef* fragRef() const
102  { return m_pFragRef; }
103
104  SizeType size() const
105  { return m_pResolveInfo->size(); }
106
107  ResolveInfo* resolveInfo()
108  { return m_pResolveInfo; }
109
110  const ResolveInfo* resolveInfo() const
111  { return m_pResolveInfo; }
112
113  bool hasFragRef() const;
114
115  // -----  modifiers  ----- //
116  void setSize(SizeType pSize) {
117    assert(NULL != m_pResolveInfo);
118    m_pResolveInfo->setSize(pSize);
119  }
120
121  void setValue(ValueType pValue)
122  { m_Value = pValue; }
123
124  void setFragmentRef(FragmentRef* pFragmentRef);
125
126  void setResolveInfo(const ResolveInfo& pInfo);
127
128private:
129  friend class Chunk<LDSymbol, MCLD_SYMBOLS_PER_INPUT>;
130
131  LDSymbol();
132  LDSymbol(const LDSymbol& pCopy);
133  LDSymbol& operator=(const LDSymbol& pCopy);
134
135private:
136  // -----  Symbol's fields  ----- //
137  ResolveInfo* m_pResolveInfo;
138  FragmentRef* m_pFragRef;
139  ValueType m_Value;
140
141};
142
143} // namespace mcld
144
145#endif
146
147