Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- MCSectionWasm.h - Wasm Machine Code Sections -------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file declares the MCSectionWasm class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_MC_MCSECTIONWASM_H |
| 14 | #define LLVM_MC_MCSECTIONWASM_H |
| 15 | |
| 16 | #include "llvm/ADT/Twine.h" |
| 17 | #include "llvm/MC/MCSection.h" |
| 18 | #include "llvm/MC/MCSymbolWasm.h" |
| 19 | #include "llvm/Support/Debug.h" |
| 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | class MCSymbol; |
| 25 | |
| 26 | /// This represents a section on wasm. |
| 27 | class MCSectionWasm final : public MCSection { |
| 28 | /// This is the name of the section. The referenced memory is owned by |
| 29 | /// TargetLoweringObjectFileWasm's WasmUniqueMap. |
| 30 | StringRef SectionName; |
| 31 | |
| 32 | unsigned UniqueID; |
| 33 | |
| 34 | const MCSymbolWasm *Group; |
| 35 | |
| 36 | // The offset of the MC function/data section in the wasm code/data section. |
| 37 | // For data relocations the offset is relative to start of the data payload |
| 38 | // itself and does not include the size of the section header. |
| 39 | uint64_t SectionOffset = 0; |
| 40 | |
| 41 | // For data sections, this is the index of of the corresponding wasm data |
| 42 | // segment |
| 43 | uint32_t SegmentIndex = 0; |
| 44 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 45 | // Whether this data segment is passive |
| 46 | bool IsPassive = false; |
| 47 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 48 | friend class MCContext; |
| 49 | MCSectionWasm(StringRef Section, SectionKind K, const MCSymbolWasm *group, |
| 50 | unsigned UniqueID, MCSymbol *Begin) |
| 51 | : MCSection(SV_Wasm, K, Begin), SectionName(Section), UniqueID(UniqueID), |
| 52 | Group(group) {} |
| 53 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 54 | public: |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 55 | /// Decides whether a '.section' directive should be printed before the |
| 56 | /// section name |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 57 | bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 58 | |
| 59 | StringRef getSectionName() const { return SectionName; } |
| 60 | const MCSymbolWasm *getGroup() const { return Group; } |
| 61 | |
| 62 | void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, |
| 63 | raw_ostream &OS, |
| 64 | const MCExpr *Subsection) const override; |
| 65 | bool UseCodeAlign() const override; |
| 66 | bool isVirtualSection() const override; |
| 67 | |
| 68 | bool isWasmData() const { |
| 69 | return Kind.isGlobalWriteableData() || Kind.isReadOnly(); |
| 70 | } |
| 71 | |
| 72 | bool isUnique() const { return UniqueID != ~0U; } |
| 73 | unsigned getUniqueID() const { return UniqueID; } |
| 74 | |
| 75 | uint64_t getSectionOffset() const { return SectionOffset; } |
| 76 | void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; } |
| 77 | |
| 78 | uint32_t getSegmentIndex() const { return SegmentIndex; } |
| 79 | void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; } |
| 80 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 81 | bool getPassive() const { |
| 82 | assert(isWasmData()); |
| 83 | return IsPassive; |
| 84 | } |
| 85 | void setPassive(bool V = true) { |
| 86 | assert(isWasmData()); |
| 87 | IsPassive = V; |
| 88 | } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 89 | static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; } |
| 90 | }; |
| 91 | |
| 92 | } // end namespace llvm |
| 93 | |
| 94 | #endif |