Home | History | Annotate | Download | only in Fragment
      1 //===- AlignFragment.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/Fragment/AlignFragment.h"
     10 #include "mcld/LD/SectionData.h"
     11 
     12 #include <llvm/Support/MathExtras.h>
     13 
     14 namespace mcld {
     15 
     16 //===----------------------------------------------------------------------===//
     17 // AlignFragment
     18 //===----------------------------------------------------------------------===//
     19 AlignFragment::AlignFragment(unsigned int pAlignment,
     20                              int64_t pValue,
     21                              unsigned int pValueSize,
     22                              unsigned int pMaxBytesToEmit,
     23                              SectionData* pSD)
     24     : Fragment(Fragment::Alignment, pSD),
     25       m_Alignment(pAlignment),
     26       m_Value(pValue),
     27       m_ValueSize(pValueSize),
     28       m_MaxBytesToEmit(pMaxBytesToEmit),
     29       m_bEmitNops(false) {
     30 }
     31 
     32 size_t AlignFragment::size() const {
     33   assert(hasOffset() &&
     34          "AlignFragment::size() should not be called before layout.");
     35   uint64_t size = llvm::OffsetToAlignment(getOffset(), m_Alignment);
     36   if (size > m_MaxBytesToEmit)
     37     return 0;
     38 
     39   return size;
     40 }
     41 
     42 }  // namespace mcld
     43