Home | History | Annotate | Download | only in LD
      1 //===- LDSymbol.cpp -------------------------------------------------------===//
      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 #include <mcld/LD/LDSymbol.h>
     10 
     11 #include <mcld/Config/Config.h>
     12 #include <mcld/Fragment/FragmentRef.h>
     13 #include <mcld/Fragment/NullFragment.h>
     14 #include <mcld/Support/GCFactory.h>
     15 
     16 #include <cstring>
     17 
     18 #include <llvm/Support/ManagedStatic.h>
     19 
     20 using namespace mcld;
     21 
     22 typedef GCFactory<LDSymbol, MCLD_SYMBOLS_PER_INPUT> LDSymbolFactory;
     23 
     24 static llvm::ManagedStatic<LDSymbol> g_NullSymbol;
     25 static llvm::ManagedStatic<NullFragment> g_NullSymbolFragment;
     26 static llvm::ManagedStatic<LDSymbolFactory> g_LDSymbolFactory;
     27 
     28 //===----------------------------------------------------------------------===//
     29 // LDSymbol
     30 //===----------------------------------------------------------------------===//
     31 LDSymbol::LDSymbol()
     32   : m_pResolveInfo(NULL), m_pFragRef(NULL), m_Value(0) {
     33 }
     34 
     35 LDSymbol::~LDSymbol()
     36 {
     37 }
     38 
     39 LDSymbol::LDSymbol(const LDSymbol& pCopy)
     40   : m_pResolveInfo(pCopy.m_pResolveInfo),
     41     m_pFragRef(pCopy.m_pFragRef),
     42     m_Value(pCopy.m_Value) {
     43 }
     44 
     45 LDSymbol& LDSymbol::operator=(const LDSymbol& pCopy)
     46 {
     47   m_pResolveInfo = pCopy.m_pResolveInfo;
     48   m_pFragRef = pCopy.m_pFragRef;
     49   m_Value = pCopy.m_Value;
     50   return (*this);
     51 }
     52 
     53 LDSymbol* LDSymbol::Create(ResolveInfo& pResolveInfo)
     54 {
     55   LDSymbol* result = g_LDSymbolFactory->allocate();
     56   new (result) LDSymbol();
     57   result->setResolveInfo(pResolveInfo);
     58   return result;
     59 }
     60 
     61 void LDSymbol::Destroy(LDSymbol*& pSymbol)
     62 {
     63   pSymbol->~LDSymbol();
     64   g_LDSymbolFactory->deallocate(pSymbol);
     65   pSymbol = NULL;
     66 }
     67 
     68 void LDSymbol::Clear()
     69 {
     70   g_LDSymbolFactory->clear();
     71 }
     72 
     73 LDSymbol* LDSymbol::Null()
     74 {
     75   // lazy initialization
     76   if (NULL == g_NullSymbol->resolveInfo()) {
     77     g_NullSymbol->setResolveInfo(*ResolveInfo::Null());
     78     g_NullSymbol->setFragmentRef(FragmentRef::Create(*g_NullSymbolFragment, 0));
     79     ResolveInfo::Null()->setSymPtr(&*g_NullSymbol);
     80   }
     81   return &*g_NullSymbol;
     82 }
     83 
     84 void LDSymbol::setFragmentRef(FragmentRef* pFragmentRef)
     85 {
     86   m_pFragRef = pFragmentRef;
     87 }
     88 
     89 void LDSymbol::setResolveInfo(const ResolveInfo& pInfo)
     90 {
     91   m_pResolveInfo = const_cast<ResolveInfo*>(&pInfo);
     92 }
     93 
     94 bool LDSymbol::isNull() const
     95 {
     96   return (this == Null());
     97 }
     98 
     99 bool LDSymbol::hasFragRef() const
    100 {
    101   return !m_pFragRef->isNull();
    102 }
    103 
    104