Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / MC / MCSectionWasm.h
blob0e576b7ba404fdf957671f3d84bdf159ce057443
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_MC_MCSECTIONWASM_H
14 #define LLVM_MC_MCSECTIONWASM_H
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"
22 namespace llvm {
24 class MCSymbol;
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;
32 unsigned UniqueID;
34 const MCSymbolWasm *Group;
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;
41 // For data sections, this is the index of of the corresponding wasm data
42 // segment
43 uint32_t SegmentIndex = 0;
45 friend class MCContext;
46 MCSectionWasm(StringRef Section, SectionKind K, const MCSymbolWasm *group,
47 unsigned UniqueID, MCSymbol *Begin)
48 : MCSection(SV_Wasm, K, Begin), SectionName(Section), UniqueID(UniqueID),
49 Group(group) {}
51 public:
52 /// Decides whether a '.section' directive should be printed before the
53 /// section name
54 bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
56 StringRef getSectionName() const { return SectionName; }
57 const MCSymbolWasm *getGroup() const { return Group; }
59 void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
60 raw_ostream &OS,
61 const MCExpr *Subsection) const override;
62 bool UseCodeAlign() const override;
63 bool isVirtualSection() const override;
65 bool isWasmData() const {
66 return Kind.isGlobalWriteableData() || Kind.isReadOnly();
69 bool isUnique() const { return UniqueID != ~0U; }
70 unsigned getUniqueID() const { return UniqueID; }
72 uint64_t getSectionOffset() const { return SectionOffset; }
73 void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; }
75 uint32_t getSegmentIndex() const { return SegmentIndex; }
76 void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; }
78 static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
81 } // end namespace llvm
83 #endif