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