Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:15

0001 //===- MCSectionWasm.h - Wasm Machine Code Sections -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the MCSectionWasm class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCSECTIONWASM_H
0014 #define LLVM_MC_MCSECTIONWASM_H
0015 
0016 #include "llvm/MC/MCSection.h"
0017 
0018 namespace llvm {
0019 
0020 class MCSymbol;
0021 class MCSymbolWasm;
0022 class StringRef;
0023 class raw_ostream;
0024 
0025 /// This represents a section on wasm.
0026 class MCSectionWasm final : public MCSection {
0027   unsigned UniqueID;
0028 
0029   const MCSymbolWasm *Group;
0030 
0031   // The offset of the MC function/data section in the wasm code/data section.
0032   // For data relocations the offset is relative to start of the data payload
0033   // itself and does not include the size of the section header.
0034   uint64_t SectionOffset = 0;
0035 
0036   // For data sections, this is the index of the corresponding wasm data
0037   // segment
0038   uint32_t SegmentIndex = 0;
0039 
0040   // For data sections, whether to use a passive segment
0041   bool IsPassive = false;
0042 
0043   bool IsWasmData;
0044 
0045   bool IsMetadata;
0046 
0047   // For data sections, bitfield of WasmSegmentFlag
0048   unsigned SegmentFlags;
0049 
0050   // The storage of Name is owned by MCContext's WasmUniquingMap.
0051   friend class MCContext;
0052   MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags,
0053                 const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin)
0054       : MCSection(SV_Wasm, Name, K.isText(), /*IsVirtual=*/false, Begin),
0055         UniqueID(UniqueID), Group(Group),
0056         IsWasmData(K.isReadOnly() || K.isWriteable()),
0057         IsMetadata(K.isMetadata()), SegmentFlags(SegmentFlags) {}
0058 
0059 public:
0060   /// Decides whether a '.section' directive should be printed before the
0061   /// section name
0062   bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
0063 
0064   const MCSymbolWasm *getGroup() const { return Group; }
0065   unsigned getSegmentFlags() const { return SegmentFlags; }
0066 
0067   void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
0068                             raw_ostream &OS,
0069                             uint32_t Subsection) const override;
0070   bool useCodeAlign() const override;
0071 
0072   bool isWasmData() const { return IsWasmData; }
0073   bool isMetadata() const { return IsMetadata; }
0074 
0075   bool isUnique() const { return UniqueID != ~0U; }
0076   unsigned getUniqueID() const { return UniqueID; }
0077 
0078   uint64_t getSectionOffset() const { return SectionOffset; }
0079   void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; }
0080 
0081   uint32_t getSegmentIndex() const { return SegmentIndex; }
0082   void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; }
0083 
0084   bool getPassive() const {
0085     assert(isWasmData());
0086     return IsPassive;
0087   }
0088   void setPassive(bool V = true) {
0089     assert(isWasmData());
0090     IsPassive = V;
0091   }
0092   static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
0093 };
0094 
0095 } // end namespace llvm
0096 
0097 #endif