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   // For data sections, whether to use a passive segment
41   bool IsPassive = false;
42 
43   // For data sections, bitfield of WasmSegmentFlag
44   unsigned SegmentFlags;
45 
46   // The storage of Name is owned by MCContext's WasmUniquingMap.
47   friend class MCContext;
MCSectionWasm(StringRef Name,SectionKind K,unsigned SegmentFlags,const MCSymbolWasm * Group,unsigned UniqueID,MCSymbol * Begin)48   MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
49                 const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
50       : MCSection(SV_Wasm, Name, K, Begin), UniqueID(UniqueID), Group(Group),
51         SegmentFlags(SegmentFlags) {}
52 
53 public:
54   /// Decides whether a '.section' directive should be printed before the
55   /// section name
56   bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
57 
getGroup()58   const MCSymbolWasm *getGroup() const { return Group; }
getSegmentFlags()59   unsigned getSegmentFlags() const { return SegmentFlags; }
60 
61   void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
62                             raw_ostream &OS,
63                             const MCExpr *Subsection) const override;
64   bool UseCodeAlign() const override;
65   bool isVirtualSection() const override;
66 
isWasmData()67   bool isWasmData() const {
68     return Kind.isGlobalWriteableData() || Kind.isReadOnly() ||
69            Kind.isThreadLocal();
70   }
71 
isUnique()72   bool isUnique() const { return UniqueID != ~0U; }
getUniqueID()73   unsigned getUniqueID() const { return UniqueID; }
74 
getSectionOffset()75   uint64_t getSectionOffset() const { return SectionOffset; }
setSectionOffset(uint64_t Offset)76   void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; }
77 
getSegmentIndex()78   uint32_t getSegmentIndex() const { return SegmentIndex; }
setSegmentIndex(uint32_t Index)79   void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; }
80 
getPassive()81   bool getPassive() const {
82     assert(isWasmData());
83     return IsPassive;
84   }
85   void setPassive(bool V = true) {
86     assert(isWasmData());
87     IsPassive = V;
88   }
classof(const MCSection * S)89   static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
90 };
91 
92 } // end namespace llvm
93 
94 #endif
95