blob: 6211afef71dbdca8ecee0ab81885d59394550d05 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- MCSectionWasm.h - Wasm Machine Code Sections -------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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 Scull5e1ddfa2018-08-14 10:06:54 +01006//
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 Scull5e1ddfa2018-08-14 10:06:54 +010016#include "llvm/MC/MCSection.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010017
18namespace llvm {
19
20class MCSymbol;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020021class MCSymbolWasm;
22class StringRef;
23class raw_ostream;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010024
25/// This represents a section on wasm.
26class MCSectionWasm final : public MCSection {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010027 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 Walbran3d2c1972020-04-07 12:24:26 +010040 // Whether this data segment is passive
41 bool IsPassive = false;
42
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020043 // The storage of Name is owned by MCContext's WasmUniquingMap.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010044 friend class MCContext;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020045 MCSectionWasm(StringRef Name, SectionKind K, const MCSymbolWasm *group,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010046 unsigned UniqueID, MCSymbol *Begin)
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020047 : MCSection(SV_Wasm, Name, K, Begin), UniqueID(UniqueID), Group(group) {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010048
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010049public:
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050 /// Decides whether a '.section' directive should be printed before the
51 /// section name
Andrew Walbran16937d02019-10-22 13:54:20 +010052 bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010053
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010054 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 Deprezf4ef2d02021-04-20 13:36:24 +020063 return Kind.isGlobalWriteableData() || Kind.isReadOnly() ||
64 Kind.isThreadLocal();
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010065 }
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 Walbran3d2c1972020-04-07 12:24:26 +010076 bool getPassive() const {
77 assert(isWasmData());
78 return IsPassive;
79 }
80 void setPassive(bool V = true) {
81 assert(isWasmData());
82 IsPassive = V;
83 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010084 static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
85};
86
87} // end namespace llvm
88
89#endif