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