Home | History | Annotate | Download | only in Fragment
      1 //===- Fragment.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_FRAGMENT_FRAGMENT_H
     10 #define MCLD_FRAGMENT_FRAGMENT_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 
     15 #include <llvm/ADT/ilist_node.h>
     16 
     17 #include <llvm/Support/DataTypes.h>
     18 
     19 #include <cstddef>
     20 #include <cassert>
     21 
     22 namespace mcld {
     23 
     24 class SectionData;
     25 
     26 /** \class Fragment
     27  *  \brief Fragment is the minimun linking unit of MCLinker.
     28  */
     29 class Fragment : public llvm::ilist_node<Fragment>
     30 {
     31 public:
     32   enum Type {
     33     Alignment,
     34     Fillment,
     35     Region,
     36     Target,
     37     Stub,
     38     Null
     39   };
     40 
     41 public:
     42   Fragment();
     43 
     44   Fragment(Type pKind, SectionData *pParent = NULL);
     45 
     46   virtual ~Fragment();
     47 
     48   Type getKind() const { return m_Kind; }
     49 
     50   const SectionData* getParent() const { return m_pParent; }
     51   SectionData*       getParent()       { return m_pParent; }
     52 
     53   void setParent(SectionData *pValue) { m_pParent = pValue; }
     54 
     55   uint64_t getOffset() const;
     56 
     57   void setOffset(uint64_t pOffset) { m_Offset = pOffset; }
     58 
     59   bool hasOffset() const;
     60 
     61   static bool classof(const Fragment *O) { return true; }
     62 
     63   virtual size_t size() const {
     64     assert(false && "Can not call abstract Fragment::size()!");
     65     return 0;
     66   }
     67 
     68 private:
     69   Fragment(const Fragment& );            // DO NOT IMPLEMENT
     70   Fragment& operator=(const Fragment& ); // DO NOT IMPLEMENT
     71 
     72 private:
     73   Type m_Kind;
     74   SectionData* m_pParent;
     75 
     76   uint64_t m_Offset;
     77 
     78 };
     79 
     80 } // namespace of mcld
     81 
     82 #endif
     83 
     84