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