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 
11 #include <llvm/Support/MathExtras.h>
12 #include <mcld/LD/SectionData.h>
13 
14 using namespace mcld;
15 
16 //===----------------------------------------------------------------------===//
17 // AlignFragment
18 //===----------------------------------------------------------------------===//
AlignFragment(unsigned int pAlignment,int64_t pValue,unsigned int pValueSize,unsigned int pMaxBytesToEmit,SectionData * pSD)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), m_Alignment(pAlignment),
25     m_Value(pValue), m_ValueSize(pValueSize), m_MaxBytesToEmit(pMaxBytesToEmit),
26     m_bEmitNops(false) {
27 }
28 
size() const29 size_t AlignFragment::size() const
30 {
31   assert(hasOffset() && "AlignFragment::size() should not be called before layout.");
32   uint64_t size = llvm::OffsetToAlignment(getOffset(), m_Alignment);
33   if (size > m_MaxBytesToEmit)
34     return 0;
35 
36   return size;
37 }
38 
39