MC: Track section layout order explicitly, and use to simplify.
[oota-llvm.git] / include / llvm / MC / MCAsmLayout.h
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
15 namespace llvm {
16 class MCAssembler;
17 class MCFragment;
18 class MCSectionData;
19 class 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.
28 class MCAsmLayout {
29 public:
30   typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator;
31   typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator;
32
33 private:
34   MCAssembler &Assembler;
35
36   /// List of sections in layout order.
37   llvm::SmallVector<MCSectionData*, 16> SectionOrder;
38
39 public:
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   /// @name Section Access (in layout order)
51   /// @{
52
53   iterator begin() { return SectionOrder.begin(); }
54   const_iterator begin() const { return SectionOrder.begin(); }
55
56   iterator end() {return SectionOrder.end();}
57   const_iterator end() const {return SectionOrder.end();}
58
59   /// @}
60   /// @name Fragment Layout Data
61   /// @{
62
63   /// \brief Get the effective size of the given fragment, as computed in the
64   /// current layout.
65   uint64_t getFragmentEffectiveSize(const MCFragment *F) const;
66
67   /// \brief Set the effective size of the given fragment.
68   void setFragmentEffectiveSize(MCFragment *F, uint64_t Value);
69
70   /// \brief Get the offset of the given fragment inside its containing section.
71   uint64_t getFragmentOffset(const MCFragment *F) const;
72
73   /// \brief Set the offset of the given fragment inside its containing section.
74   void setFragmentOffset(MCFragment *F, uint64_t Value);
75
76   /// @}
77   /// @name Section Layout Data
78   /// @{
79
80   /// \brief Get the computed address of the given section.
81   uint64_t getSectionAddress(const MCSectionData *SD) const;
82
83   /// \brief Set the computed address of the given section.
84   void setSectionAddress(MCSectionData *SD, uint64_t Value);
85
86   /// \brief Get the data size of the given section, as emitted to the object
87   /// file. This may include additional padding, or be 0 for virtual sections.
88   uint64_t getSectionFileSize(const MCSectionData *SD) const;
89
90   /// \brief Set the data size of the given section.
91   void setSectionFileSize(MCSectionData *SD, uint64_t Value);
92
93   /// \brief Get the actual data size of the given section.
94   uint64_t getSectionSize(const MCSectionData *SD) const;
95
96   /// \brief Set the actual data size of the given section.
97   void setSectionSize(MCSectionData *SD, uint64_t Value);
98
99   /// @}
100   /// @name Utility Functions
101   /// @{
102
103   /// \brief Get the address of the given fragment, as computed in the current
104   /// layout.
105   uint64_t getFragmentAddress(const MCFragment *F) const;
106
107   /// \brief Get the address of the given symbol, as computed in the current
108   /// layout.
109   uint64_t getSymbolAddress(const MCSymbolData *SD) const;
110
111   /// @}
112 };
113
114 } // end namespace llvm
115
116 #endif