LDSymbol.h revision cedee4b38f4786845183be7f5916dd520a170ae0
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/ADT/Uncopyable.h>
18#include <mcld/LD/ResolveInfo.h>
19#include <mcld/LD/FragmentRef.h>
20
21namespace mcld
22{
23
24/** \class LDSymbol
25 *  \brief LDSymbol provides a consistent abstraction for different formats
26 *  in different targets.
27 */
28class LDSymbol
29{
30public:
31  // FIXME: use SizeTrait<32> or SizeTrait<64> instead of big type
32  typedef ResolveInfo::SizeType SizeType;
33  typedef uint64_t ValueType;
34  typedef FragmentRef::Offset Offset;
35
36public:
37  LDSymbol();
38  LDSymbol(const LDSymbol& pCopy);
39  LDSymbol& operator=(const LDSymbol& pCopy);
40  ~LDSymbol();
41
42  // -----  observers  ----- //
43  const char* name() const {
44    assert(NULL != m_pResolveInfo);
45    return m_pResolveInfo->name();
46  }
47
48  unsigned int nameSize() const {
49    assert(NULL != m_pResolveInfo);
50    return m_pResolveInfo->nameSize();
51  }
52
53  llvm::StringRef str() const {
54    assert(NULL != m_pResolveInfo);
55    return llvm::StringRef(m_pResolveInfo->name(), m_pResolveInfo->nameSize());
56  }
57
58  bool isDyn() const {
59    assert(NULL != m_pResolveInfo);
60    return m_pResolveInfo->isDyn();
61  }
62
63  unsigned int type() const {
64    assert(NULL != m_pResolveInfo);
65    return m_pResolveInfo->type();
66  }
67 unsigned int desc() const {
68    assert(NULL != m_pResolveInfo);
69    return m_pResolveInfo->desc();
70  }
71  unsigned int binding() const {
72    assert(NULL != m_pResolveInfo);
73    return m_pResolveInfo->binding();
74  }
75
76  uint8_t other() const {
77    assert(NULL != m_pResolveInfo);
78    return m_pResolveInfo->other();
79  }
80
81  uint8_t visibility() const {
82    assert(NULL != m_pResolveInfo);
83    return m_pResolveInfo->other();
84  }
85
86  ValueType value() const
87  { return m_Value; }
88
89  const FragmentRef* fragRef() const
90  { return m_pFragRef; }
91
92  SizeType size() const
93  { return m_pResolveInfo->size(); }
94
95  ResolveInfo* resolveInfo()
96  { return m_pResolveInfo; }
97
98  const ResolveInfo* resolveInfo() const
99  { return m_pResolveInfo; }
100
101  bool hasFragRef() const
102  { return (NULL != m_pFragRef); }
103
104  // -----  modifiers  ----- //
105  void setSize(SizeType pSize) {
106    assert(NULL != m_pResolveInfo);
107    m_pResolveInfo->setSize(pSize);
108  }
109
110  void setValue(ValueType pValue)
111  { m_Value = pValue; }
112
113  void setFragmentRef(FragmentRef* pFragmentRef);
114
115  void setResolveInfo(const ResolveInfo& pInfo);
116
117private:
118  // -----  Symbol's fields  ----- //
119  ResolveInfo* m_pResolveInfo;
120  FragmentRef* m_pFragRef;
121  ValueType m_Value;
122
123};
124
125} // namespace mcld
126
127#endif
128
129