MCSectionWasm.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MCSectionWasm.h - Wasm Machine Code Sections -------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the MCSectionWasm class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCSECTIONWASM_H
  18. #define LLVM_MC_MCSECTIONWASM_H
  19. #include "llvm/MC/MCSection.h"
  20. namespace llvm {
  21. class MCSymbol;
  22. class MCSymbolWasm;
  23. class StringRef;
  24. class raw_ostream;
  25. /// This represents a section on wasm.
  26. class MCSectionWasm final : public MCSection {
  27. unsigned UniqueID;
  28. const MCSymbolWasm *Group;
  29. // The offset of the MC function/data section in the wasm code/data section.
  30. // For data relocations the offset is relative to start of the data payload
  31. // itself and does not include the size of the section header.
  32. uint64_t SectionOffset = 0;
  33. // For data sections, this is the index of of the corresponding wasm data
  34. // segment
  35. uint32_t SegmentIndex = 0;
  36. // For data sections, whether to use a passive segment
  37. bool IsPassive = false;
  38. // For data sections, bitfield of WasmSegmentFlag
  39. unsigned SegmentFlags;
  40. // The storage of Name is owned by MCContext's WasmUniquingMap.
  41. friend class MCContext;
  42. MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
  43. const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
  44. : MCSection(SV_Wasm, Name, K, Begin), UniqueID(UniqueID), Group(Group),
  45. SegmentFlags(SegmentFlags) {}
  46. public:
  47. /// Decides whether a '.section' directive should be printed before the
  48. /// section name
  49. bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
  50. const MCSymbolWasm *getGroup() const { return Group; }
  51. unsigned getSegmentFlags() const { return SegmentFlags; }
  52. void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
  53. raw_ostream &OS,
  54. const MCExpr *Subsection) const override;
  55. bool useCodeAlign() const override;
  56. bool isVirtualSection() const override;
  57. bool isWasmData() const {
  58. return Kind.isGlobalWriteableData() || Kind.isReadOnly() ||
  59. Kind.isThreadLocal();
  60. }
  61. bool isUnique() const { return UniqueID != ~0U; }
  62. unsigned getUniqueID() const { return UniqueID; }
  63. uint64_t getSectionOffset() const { return SectionOffset; }
  64. void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; }
  65. uint32_t getSegmentIndex() const { return SegmentIndex; }
  66. void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; }
  67. bool getPassive() const {
  68. assert(isWasmData());
  69. return IsPassive;
  70. }
  71. void setPassive(bool V = true) {
  72. assert(isWasmData());
  73. IsPassive = V;
  74. }
  75. static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
  76. };
  77. } // end namespace llvm
  78. #endif
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif