Home | History | Annotate | Download | only in LD
      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 
     19 namespace llvm {
     20 
     21 // forware declaration
     22 template<class T> void* object_creator();
     23 
     24 } // namespace of llvm
     25 
     26 namespace mcld {
     27 
     28 class FragmentRef;
     29 
     30 /** \class LDSymbol
     31  *  \brief LDSymbol provides a consistent abstraction for different formats
     32  *  in different targets.
     33  */
     34 class LDSymbol
     35 {
     36 public:
     37   // FIXME: use SizeTrait<32> or SizeTrait<64> instead of big type
     38   typedef ResolveInfo::SizeType SizeType;
     39   typedef uint64_t ValueType;
     40 
     41 public:
     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   FragmentRef* fragRef()
    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 
    135 private:
    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 
    143 private:
    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