Home | History | Annotate | Download | only in MC
      1 //===- MCDataFragment.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 MCDATAFRAGMENT_H
     10 #define MCDATAFRAGMENT_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 #include <llvm/MC/MCAssembler.h>
     15 #include <llvm/MC/MCInst.h>
     16 #include <llvm/ADT/SmallString.h>
     17 #include "mcld/LD/Relocation.h"
     18 
     19 namespace mcld
     20 {
     21 
     22 /** \class MCDataFragment
     23  *  \brief MCDataFragment for mcld
     24  *
     25  *  \see
     26  *  \author Diana Chen <diana.chen (at) mediatek.com>
     27  */
     28 class MCDataFragment : public  llvm::MCFragment
     29 {
     30 public:
     31    typedef std::vector<Relocation*> RelocationsType;
     32 private:
     33 
     34   ///  m_pFragment - llvm MCDataFragment for this MCDataFragment
     35   llvm::MCDataFragment* m_pFragment;
     36 
     37   /// m_Relocation - The list of relocations in this fragment
     38   RelocationsType m_Relocations;
     39 
     40 public:
     41   typedef RelocationsType::const_iterator const_relocation_iterator;
     42   typedef RelocationsType::iterator relocation_iterator;
     43 
     44 public:
     45   MCDataFragment(llvm::MCDataFragment& pFragment)
     46     : m_pFragment(&pFragment) {
     47     setParent( pFragment.getParent() );
     48     setAtom( pFragment.getAtom() );
     49     setLayoutOrder( pFragment.getLayoutOrder());
     50   }
     51   ~MCDataFragment(){}
     52 
     53   // ------ observers ------//
     54   llvm::SmallString<32> &getContents() { return m_pFragment->getContents();  }
     55   const llvm::SmallString<32> &getContents() const { return m_pFragment->getContents();  }
     56 
     57   // relocation access
     58   void addRelocation(Relocation &pReloc){  m_Relocations.push_back(&pReloc); }
     59 
     60   RelocationsType &getRelocations() { return m_Relocations; }
     61   const RelocationsType &getRelcoations() const { return m_Relocations; }
     62 
     63   relocation_iterator relocation_begin() { return m_Relocations.begin(); }
     64   const_relocation_iterator relocation_begin() const { return m_Relocations.begin(); }
     65 
     66   relocation_iterator relocation_end() {return m_Relocations.end();}
     67   const_relocation_iterator relocation_end() const {return m_Relocations.end();}
     68 
     69   size_t relocations_size() const { return m_Relocations.size(); }
     70 
     71   // fragment identification
     72   static bool classof(const MCFragment *pF) {
     73     return pF->getKind() == llvm::MCFragment::FT_Data;
     74   }
     75   static bool classof(const MCDataFragment *) { return true; }
     76 
     77   // overwrite parent method
     78   FragmentType getKind() const { return m_pFragment->getKind(); }
     79 
     80 };
     81 
     82 } // namespace of mcld
     83 
     84 #endif
     85 
     86