Home | History | Annotate | Download | only in MC
      1 //===- MCSectionWasm.h - Wasm Machine Code Sections -------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file declares the MCSectionWasm class.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_MC_MCSECTIONWASM_H
     15 #define LLVM_MC_MCSECTIONWASM_H
     16 
     17 #include "llvm/ADT/Twine.h"
     18 #include "llvm/MC/MCSection.h"
     19 #include "llvm/MC/MCSymbolWasm.h"
     20 #include "llvm/Support/Debug.h"
     21 #include "llvm/Support/raw_ostream.h"
     22 
     23 namespace llvm {
     24 
     25 class MCSymbol;
     26 
     27 /// This represents a section on wasm.
     28 class MCSectionWasm final : public MCSection {
     29 private:
     30   /// This is the name of the section.  The referenced memory is owned by
     31   /// TargetLoweringObjectFileWasm's WasmUniqueMap.
     32   StringRef SectionName;
     33 
     34   /// This is the type of the section, from the enums in BinaryFormat/Wasm.h
     35   unsigned Type;
     36 
     37   unsigned UniqueID;
     38 
     39   const MCSymbolWasm *Group;
     40 
     41   // The offset of the MC function/data section in the wasm code/data section.
     42   // For data relocations the offset is relative to start of the data payload
     43   // itself and does not include the size of the section header.
     44   uint64_t SectionOffset;
     45 
     46   // For data sections, this is the offset of the corresponding wasm data
     47   // segment
     48   uint64_t MemoryOffset;
     49 
     50   friend class MCContext;
     51   MCSectionWasm(StringRef Section, unsigned type, SectionKind K,
     52                 const MCSymbolWasm *group, unsigned UniqueID, MCSymbol *Begin)
     53       : MCSection(SV_Wasm, K, Begin), SectionName(Section), Type(type),
     54         UniqueID(UniqueID), Group(group), SectionOffset(0) {
     55     assert(type == wasm::WASM_SEC_CODE || type == wasm::WASM_SEC_DATA);
     56   }
     57 
     58   void setSectionName(StringRef Name) { SectionName = Name; }
     59 
     60 public:
     61   ~MCSectionWasm();
     62 
     63   /// Decides whether a '.section' directive should be printed before the
     64   /// section name
     65   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
     66 
     67   StringRef getSectionName() const { return SectionName; }
     68   unsigned getType() const { return Type; }
     69   const MCSymbolWasm *getGroup() const { return Group; }
     70 
     71   void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     72                             raw_ostream &OS,
     73                             const MCExpr *Subsection) const override;
     74   bool UseCodeAlign() const override;
     75   bool isVirtualSection() const override;
     76 
     77   bool isUnique() const { return UniqueID != ~0U; }
     78   unsigned getUniqueID() const { return UniqueID; }
     79 
     80   uint64_t getSectionOffset() const { return SectionOffset; }
     81   void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; }
     82 
     83   uint32_t getMemoryOffset() const { return MemoryOffset; }
     84   void setMemoryOffset(uint32_t Offset) { MemoryOffset = Offset; }
     85 
     86   static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
     87 };
     88 
     89 } // end namespace llvm
     90 
     91 #endif
     92