1317017Sdim//===- MCSectionWasm.h - Wasm Machine Code Sections -------------*- C++ -*-===//
2317017Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6317017Sdim//
7317017Sdim//===----------------------------------------------------------------------===//
8317017Sdim//
9317017Sdim// This file declares the MCSectionWasm class.
10317017Sdim//
11317017Sdim//===----------------------------------------------------------------------===//
12317017Sdim
13317017Sdim#ifndef LLVM_MC_MCSECTIONWASM_H
14317017Sdim#define LLVM_MC_MCSECTIONWASM_H
15317017Sdim
16317017Sdim#include "llvm/ADT/Twine.h"
17317017Sdim#include "llvm/MC/MCSection.h"
18317017Sdim#include "llvm/MC/MCSymbolWasm.h"
19317017Sdim#include "llvm/Support/Debug.h"
20317017Sdim#include "llvm/Support/raw_ostream.h"
21317017Sdim
22317017Sdimnamespace llvm {
23317017Sdim
24317017Sdimclass MCSymbol;
25317017Sdim
26317017Sdim/// This represents a section on wasm.
27317017Sdimclass MCSectionWasm final : public MCSection {
28317017Sdim  /// This is the name of the section.  The referenced memory is owned by
29317017Sdim  /// TargetLoweringObjectFileWasm's WasmUniqueMap.
30317017Sdim  StringRef SectionName;
31317017Sdim
32317017Sdim  unsigned UniqueID;
33317017Sdim
34317017Sdim  const MCSymbolWasm *Group;
35317017Sdim
36317778Sdim  // The offset of the MC function/data section in the wasm code/data section.
37317778Sdim  // For data relocations the offset is relative to start of the data payload
38317778Sdim  // itself and does not include the size of the section header.
39341825Sdim  uint64_t SectionOffset = 0;
40317017Sdim
41341825Sdim  // For data sections, this is the index of of the corresponding wasm data
42327952Sdim  // segment
43341825Sdim  uint32_t SegmentIndex = 0;
44327952Sdim
45353358Sdim  // Whether this data segment is passive
46353358Sdim  bool IsPassive = false;
47353358Sdim
48317017Sdim  friend class MCContext;
49327952Sdim  MCSectionWasm(StringRef Section, SectionKind K, const MCSymbolWasm *group,
50327952Sdim                unsigned UniqueID, MCSymbol *Begin)
51327952Sdim      : MCSection(SV_Wasm, K, Begin), SectionName(Section), UniqueID(UniqueID),
52341825Sdim        Group(group) {}
53317017Sdim
54317017Sdimpublic:
55317017Sdim  /// Decides whether a '.section' directive should be printed before the
56317017Sdim  /// section name
57353358Sdim  bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
58317017Sdim
59317017Sdim  StringRef getSectionName() const { return SectionName; }
60317017Sdim  const MCSymbolWasm *getGroup() const { return Group; }
61317017Sdim
62317017Sdim  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
63317017Sdim                            raw_ostream &OS,
64317017Sdim                            const MCExpr *Subsection) const override;
65317017Sdim  bool UseCodeAlign() const override;
66317017Sdim  bool isVirtualSection() const override;
67317017Sdim
68327952Sdim  bool isWasmData() const {
69353358Sdim    return Kind.isGlobalWriteableData() || Kind.isReadOnly() ||
70353358Sdim           Kind.isThreadLocal();
71327952Sdim  }
72327952Sdim
73317017Sdim  bool isUnique() const { return UniqueID != ~0U; }
74317017Sdim  unsigned getUniqueID() const { return UniqueID; }
75317017Sdim
76317017Sdim  uint64_t getSectionOffset() const { return SectionOffset; }
77317017Sdim  void setSectionOffset(uint64_t Offset) { SectionOffset = Offset; }
78317017Sdim
79341825Sdim  uint32_t getSegmentIndex() const { return SegmentIndex; }
80341825Sdim  void setSegmentIndex(uint32_t Index) { SegmentIndex = Index; }
81327952Sdim
82353358Sdim  bool getPassive() const {
83353358Sdim    assert(isWasmData());
84353358Sdim    return IsPassive;
85353358Sdim  }
86353358Sdim  void setPassive(bool V = true) {
87353358Sdim    assert(isWasmData());
88353358Sdim    IsPassive = V;
89353358Sdim  }
90317017Sdim  static bool classof(const MCSection *S) { return S->getVariant() == SV_Wasm; }
91317017Sdim};
92317017Sdim
93317017Sdim} // end namespace llvm
94317017Sdim
95317017Sdim#endif
96