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 
13 #ifndef LLVM_MC_MCSECTIONWASM_H
14 #define LLVM_MC_MCSECTIONWASM_H
15 
16 #include "llvm/MC/MCSection.h"
17 
18 namespace llvm {
19 
20 class MCSymbol;
21 class MCSymbolWasm;
22 class StringRef;
23 class raw_ostream;
24 
25 /// This represents a section on wasm.
26 class MCSectionWasm final : public MCSection {
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 
40   // Whether this data segment is passive
41   bool IsPassive = false;
42 
43   // The storage of Name is owned by MCContext's WasmUniquingMap.
44   friend class MCContext;
45   MCSectionWasm(StringRef Name, SectionKind K, const MCSymbolWasm *group,
46                 unsigned UniqueID, MCSymbol *Begin)
47       : MCSection(SV_Wasm, Name, K, Begin), UniqueID(UniqueID), Group(group) {}
48 
49 public:
50   /// Decides whether a '.section' directive should be printed before the
51   /// section name
52   bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
53 
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 {
63     return Kind.isGlobalWriteableData() || Kind.isReadOnly() ||
64            Kind.isThreadLocal();
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 
76   bool getPassive() const {
77     assert(isWasmData());
78     return IsPassive;
79   }
80   void setPassive(bool V = true) {
81     assert(isWasmData());
82     IsPassive = V;
83   }
84   static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
85 };
86 
87 } // end namespace llvm
88 
89 #endif
90