1 //===- AlignFragment.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_ALIGNFRAGMENT_H 10 #define MCLD_LD_ALIGNFRAGMENT_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <mcld/LD/Fragment.h> 16 17 namespace mcld 18 { 19 20 class SectionData; 21 22 class AlignFragment : public Fragment 23 { 24 public: 25 AlignFragment(unsigned int pAlignment, int64_t pValue, unsigned int pValueSize, 26 unsigned int pMaxBytesToEmit, SectionData *pSD = NULL); 27 getAlignment()28 unsigned int getAlignment() const { return m_Alignment; } 29 getValue()30 int64_t getValue() const { return m_Value; } 31 getValueSize()32 unsigned int getValueSize() const { return m_ValueSize; } 33 getMaxBytesToEmit()34 unsigned int getMaxBytesToEmit() const { return m_MaxBytesToEmit; } 35 hasEmitNops()36 bool hasEmitNops() const { return m_bEmitNops; } 37 setEmitNops(bool pValue)38 void setEmitNops(bool pValue) { m_bEmitNops = pValue; } 39 classof(const Fragment * F)40 static bool classof(const Fragment *F) { 41 return F->getKind() == Fragment::Alignment; 42 } classof(const AlignFragment *)43 static bool classof(const AlignFragment *) { return true; } 44 45 private: 46 /// Alignment - The alignment to ensure, in bytes. 47 unsigned int m_Alignment; 48 49 /// Value - Value to use for filling padding bytes. 50 int64_t m_Value; 51 52 /// ValueSize - The size of the integer (in bytes) of \arg Value. 53 unsigned int m_ValueSize; 54 55 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment 56 /// cannot be satisfied in this width then this fragment is ignored. 57 unsigned int m_MaxBytesToEmit; 58 59 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead 60 /// of using the provided value. The exact interpretation of this flag is 61 /// target dependent. 62 bool m_bEmitNops : 1; 63 64 }; 65 66 } // namespace of mcld 67 68 #endif 69 70