1 //===- MCAsmLayout.h - Assembly Layout Object -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASMLAYOUT_H
11 #define LLVM_MC_MCASMLAYOUT_H
13 #include "llvm/ADT/SmallVector.h"
21 /// Encapsulates the layout of an assembly file at a particular point in time.
23 /// Assembly may requiring compute multiple layouts for a particular assembly
24 /// file as part of the relaxation process. This class encapsulates the layout
25 /// at a single point in time in such a way that it is always possible to
26 /// efficiently compute the exact addresses of any symbol in the assembly file,
27 /// even during the relaxation process.
30 typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator;
31 typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator;
34 MCAssembler &Assembler;
36 /// List of sections in layout order.
37 llvm::SmallVector<MCSectionData*, 16> SectionOrder;
40 MCAsmLayout(MCAssembler &_Assembler);
42 /// Get the assembler object this is a layout for.
43 MCAssembler &getAssembler() const { return Assembler; }
45 /// \brief Update the layout because a fragment has been resized. The
46 /// fragments size should have already been updated, the \arg SlideAmount is
47 /// the delta from the old size.
48 void UpdateForSlide(MCFragment *F, int SlideAmount);
50 /// @name Section Access (in layout order)
53 llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() {
56 const llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() const {
61 /// @name Fragment Layout Data
64 /// \brief Get the effective size of the given fragment, as computed in the
66 uint64_t getFragmentEffectiveSize(const MCFragment *F) const;
68 /// \brief Set the effective size of the given fragment.
69 void setFragmentEffectiveSize(MCFragment *F, uint64_t Value);
71 /// \brief Get the offset of the given fragment inside its containing section.
72 uint64_t getFragmentOffset(const MCFragment *F) const;
74 /// \brief Set the offset of the given fragment inside its containing section.
75 void setFragmentOffset(MCFragment *F, uint64_t Value);
78 /// @name Section Layout Data
81 /// \brief Get the computed address of the given section.
82 uint64_t getSectionAddress(const MCSectionData *SD) const;
84 /// \brief Set the computed address of the given section.
85 void setSectionAddress(MCSectionData *SD, uint64_t Value);
87 /// \brief Get the data size of the given section, as emitted to the object
88 /// file. This may include additional padding, or be 0 for virtual sections.
89 uint64_t getSectionFileSize(const MCSectionData *SD) const;
91 /// \brief Set the data size of the given section.
92 void setSectionFileSize(MCSectionData *SD, uint64_t Value);
94 /// \brief Get the address space size of the given section, as it effects
95 /// layout. This may differ from the size reported by \see getSectionSize() by
96 /// not including section tail padding.
97 uint64_t getSectionAddressSize(const MCSectionData *SD) const;
99 /// \brief Set the address space size of the given section.
100 void setSectionAddressSize(MCSectionData *SD, uint64_t Value);
102 /// \brief Get the logical data size of the given section.
103 uint64_t getSectionSize(const MCSectionData *SD) const;
105 /// \brief Set the logical data size of the given section.
106 void setSectionSize(MCSectionData *SD, uint64_t Value);
109 /// @name Utility Functions
112 /// \brief Get the address of the given fragment, as computed in the current
114 uint64_t getFragmentAddress(const MCFragment *F) const;
116 /// \brief Get the address of the given symbol, as computed in the current
118 uint64_t getSymbolAddress(const MCSymbolData *SD) const;
123 } // end namespace llvm