MCAsmLayout.h revision 0cc8bd48619b943379f5c2cc11a19fb189342925
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
13namespace llvm {
14class MCAssembler;
15class MCFragment;
16class MCSectionData;
17class MCSymbolData;
18
19/// Encapsulates the layout of an assembly file at a particular point in time.
20///
21/// Assembly may requiring compute multiple layouts for a particular assembly
22/// file as part of the relaxation process. This class encapsulates the layout
23/// at a single point in time in such a way that it is always possible to
24/// efficiently compute the exact addresses of any symbol in the assembly file,
25/// even during the relaxation process.
26class MCAsmLayout {
27private:
28  MCAssembler &Assembler;
29
30public:
31  MCAsmLayout(MCAssembler &_Assembler) : Assembler(_Assembler) {}
32
33  /// Get the assembler object this is a layout for.
34  MCAssembler &getAssembler() const { return Assembler; }
35
36  /// \brief Update the layout because a fragment has been resized. The
37  /// fragments size should have already been updated, the \arg SlideAmount is
38  /// the delta from the old size.
39  void UpdateForSlide(MCFragment *F, int SlideAmount);
40
41  /// @name Fragment Layout Data
42  /// @{
43
44  /// \brief Get the effective size of the given fragment, as computed in the
45  /// current layout.
46  uint64_t getFragmentEffectiveSize(const MCFragment *F) const;
47
48  /// \brief Set the effective size of the given fragment.
49  void setFragmentEffectiveSize(MCFragment *F, uint64_t Value);
50
51  /// \brief Get the offset of the given fragment inside its containing section.
52  uint64_t getFragmentOffset(const MCFragment *F) const;
53
54  /// \brief Set the offset of the given fragment inside its containing section.
55  void setFragmentOffset(MCFragment *F, uint64_t Value);
56
57  /// @}
58  /// @name Section Layout Data
59  /// @{
60
61  /// \brief Get the computed address of the given section.
62  uint64_t getSectionAddress(const MCSectionData *SD) const;
63
64  /// \brief Set the computed address of the given section.
65  void setSectionAddress(MCSectionData *SD, uint64_t Value);
66
67  /// \brief Get the data size of the given section, as emitted to the object
68  /// file. This may include additional padding, or be 0 for virtual sections.
69  uint64_t getSectionFileSize(const MCSectionData *SD) const;
70
71  /// \brief Set the data size of the given section.
72  void setSectionFileSize(MCSectionData *SD, uint64_t Value);
73
74  /// \brief Get the actual data size of the given section.
75  uint64_t getSectionSize(const MCSectionData *SD) const;
76
77  /// \brief Set the actual data size of the given section.
78  void setSectionSize(MCSectionData *SD, uint64_t Value);
79
80  /// @}
81  /// @name Utility Functions
82  /// @{
83
84  /// \brief Get the address of the given fragment, as computed in the current
85  /// layout.
86  uint64_t getFragmentAddress(const MCFragment *F) const;
87
88  /// \brief Get the address of the given symbol, as computed in the current
89  /// layout.
90  uint64_t getSymbolAddress(const MCSymbolData *SD) const;
91
92  /// @}
93};
94
95} // end namespace llvm
96
97#endif
98