Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.8 KiB

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