MCSectionWasm.h 3.0 KB

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