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