MCAsmLayout.h revision d52a2c0a31a49e1a8fa16f6b975d01b1e934a49f
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/DenseMap.h" 14#include "llvm/ADT/SmallVector.h" 15 16namespace llvm { 17class MCAssembler; 18class MCFragment; 19class MCSectionData; 20class MCSymbolData; 21 22/// Encapsulates the layout of an assembly file at a particular point in time. 23/// 24/// Assembly may require computing multiple layouts for a particular assembly 25/// file as part of the relaxation process. This class encapsulates the layout 26/// at a single point in time in such a way that it is always possible to 27/// efficiently compute the exact address of any symbol in the assembly file, 28/// even during the relaxation process. 29class MCAsmLayout { 30public: 31 typedef llvm::SmallVectorImpl<MCSectionData*>::const_iterator const_iterator; 32 typedef llvm::SmallVectorImpl<MCSectionData*>::iterator iterator; 33 34private: 35 MCAssembler &Assembler; 36 37 /// List of sections in layout order. 38 llvm::SmallVector<MCSectionData*, 16> SectionOrder; 39 40 /// The last fragment which was laid out, or 0 if nothing has been laid 41 /// out. Fragments are always laid out in order, so all fragments with a 42 /// lower ordinal will be valid. 43 mutable DenseMap<const MCSectionData*, MCFragment*> LastValidFragment; 44 45 /// \brief Make sure that the layout for the given fragment is valid, lazily 46 /// computing it if necessary. 47 void ensureValid(const MCFragment *F) const; 48 49 /// \brief Is the layout for this fragment valid? 50 bool isFragmentValid(const MCFragment *F) const; 51 52public: 53 MCAsmLayout(MCAssembler &_Assembler); 54 55 /// Get the assembler object this is a layout for. 56 MCAssembler &getAssembler() const { return Assembler; } 57 58 /// \brief Invalidate the fragments after F because it has been resized. 59 /// The fragment's size should have already been updated. 60 void invalidateFragmentsAfter(MCFragment *F); 61 62 /// \brief Perform layout for a single fragment, assuming that the previous 63 /// fragment has already been laid out correctly, and the parent section has 64 /// been initialized. 65 void layoutFragment(MCFragment *Fragment); 66 67 /// @name Section Access (in layout order) 68 /// @{ 69 70 llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() { 71 return SectionOrder; 72 } 73 const llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() const { 74 return SectionOrder; 75 } 76 77 /// @} 78 /// @name Fragment Layout Data 79 /// @{ 80 81 /// \brief Get the offset of the given fragment inside its containing section. 82 uint64_t getFragmentOffset(const MCFragment *F) const; 83 84 /// @} 85 /// @name Utility Functions 86 /// @{ 87 88 /// \brief Get the address space size of the given section, as it effects 89 /// layout. This may differ from the size reported by \see getSectionSize() by 90 /// not including section tail padding. 91 uint64_t getSectionAddressSize(const MCSectionData *SD) const; 92 93 /// \brief Get the data size of the given section, as emitted to the object 94 /// file. This may include additional padding, or be 0 for virtual sections. 95 uint64_t getSectionFileSize(const MCSectionData *SD) const; 96 97 /// \brief Get the offset of the given symbol, as computed in the current 98 /// layout. 99 uint64_t getSymbolOffset(const MCSymbolData *SD) const; 100 101 /// @} 102}; 103 104} // end namespace llvm 105 106#endif 107