MCAsmLayout.h revision b69fc044db8c193348b6611f46432bb21b3cbe90
1//===- MCAsmLayout.h - Assembly Layout Object -------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_MC_MCASMLAYOUT_H
11#define LLVM_MC_MCASMLAYOUT_H
12
13#include "llvm/ADT/SmallVector.h"
14
15namespace llvm {
16class MCAssembler;
17class MCFragment;
18class MCSectionData;
19class MCSymbolData;
20
21/// Encapsulates the layout of an assembly file at a particular point in time.
22///
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.
28class MCAsmLayout {
29public:
30  typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator;
31  typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator;
32
33private:
34  MCAssembler &Assembler;
35
36  /// List of sections in layout order.
37  llvm::SmallVector<MCSectionData*, 16> SectionOrder;
38
39public:
40  MCAsmLayout(MCAssembler &_Assembler);
41
42  /// Get the assembler object this is a layout for.
43  MCAssembler &getAssembler() const { return Assembler; }
44
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);
49
50  /// \brief Update the layout because a fragment has been replaced.
51  void FragmentReplaced(MCFragment *Src, MCFragment *Dst);
52
53  /// \brief Perform a full layout.
54  void LayoutFile();
55
56  /// \brief Perform layout for a single fragment, assuming that the previous
57  /// fragment has already been layed out correctly, and the parent section has
58  /// been initialized.
59  void LayoutFragment(MCFragment *Fragment);
60
61  /// \brief Performs layout for a single section, assuming that the previous
62  /// section has already been layed out correctly.
63  void LayoutSection(MCSectionData *SD);
64
65  /// @name Section Access (in layout order)
66  /// @{
67
68  llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() {
69    return SectionOrder;
70  }
71  const llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() const {
72    return SectionOrder;
73  }
74
75  /// @}
76  /// @name Fragment Layout Data
77  /// @{
78
79  /// \brief Get the effective size of the given fragment, as computed in the
80  /// current layout.
81  uint64_t getFragmentEffectiveSize(const MCFragment *F) const;
82
83  /// \brief Set the effective size of the given fragment.
84  void setFragmentEffectiveSize(MCFragment *F, uint64_t Value);
85
86  /// \brief Get the offset of the given fragment inside its containing section.
87  uint64_t getFragmentOffset(const MCFragment *F) const;
88
89  /// \brief Set the offset of the given fragment inside its containing section.
90  void setFragmentOffset(MCFragment *F, uint64_t Value);
91
92  /// @}
93  /// @name Section Layout Data
94  /// @{
95
96  /// \brief Get the computed address of the given section.
97  uint64_t getSectionAddress(const MCSectionData *SD) const;
98
99  /// \brief Set the computed address of the given section.
100  void setSectionAddress(MCSectionData *SD, uint64_t Value);
101
102  /// @}
103  /// @name Utility Functions
104  /// @{
105
106  /// \brief Get the address of the given fragment, as computed in the current
107  /// layout.
108  uint64_t getFragmentAddress(const MCFragment *F) const;
109
110  /// \brief Get the address space size of the given section, as it effects
111  /// layout. This may differ from the size reported by \see getSectionSize() by
112  /// not including section tail padding.
113  uint64_t getSectionAddressSize(const MCSectionData *SD) const;
114
115  /// \brief Get the data size of the given section, as emitted to the object
116  /// file. This may include additional padding, or be 0 for virtual sections.
117  uint64_t getSectionFileSize(const MCSectionData *SD) const;
118
119  /// \brief Get the logical data size of the given section.
120  uint64_t getSectionSize(const MCSectionData *SD) const;
121
122  /// \brief Get the address of the given symbol, as computed in the current
123  /// layout.
124  uint64_t getSymbolAddress(const MCSymbolData *SD) const;
125
126  /// @}
127};
128
129} // end namespace llvm
130
131#endif
132