aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h
blob: 522f6356c28b658e4ef25437c1aa767239d2402f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//==-- WebAssemblyTargetStreamer.h - WebAssembly Target Streamer -*- C++ -*-==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file declares WebAssembly-specific target streamer classes.
/// These are for implementing support for target-specific assembly directives.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H

#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Support/MachineValueType.h"

namespace llvm {

class MCSymbolWasm;
class formatted_raw_ostream;

/// WebAssembly-specific streamer interface, to implement support
/// WebAssembly-specific assembly directives.
class WebAssemblyTargetStreamer : public MCTargetStreamer {
public:
  explicit WebAssemblyTargetStreamer(MCStreamer &S);

  /// .local
  virtual void emitLocal(ArrayRef<wasm::ValType> Types) = 0;
  /// .functype
  virtual void emitFunctionType(const MCSymbolWasm *Sym) = 0;
  /// .indidx
  virtual void emitIndIdx(const MCExpr *Value) = 0;
  /// .globaltype
  virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0;
  /// .tabletype
  virtual void emitTableType(const MCSymbolWasm *Sym) = 0;
  /// .tagtype
  virtual void emitTagType(const MCSymbolWasm *Sym) = 0;
  /// .import_module
  virtual void emitImportModule(const MCSymbolWasm *Sym,
                                StringRef ImportModule) = 0;
  /// .import_name
  virtual void emitImportName(const MCSymbolWasm *Sym,
                              StringRef ImportName) = 0;
  /// .export_name
  virtual void emitExportName(const MCSymbolWasm *Sym,
                              StringRef ExportName) = 0;

protected:
  void emitValueType(wasm::ValType Type);
};

/// This part is for ascii assembly output
class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
  formatted_raw_ostream &OS;

public:
  WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);

  void emitLocal(ArrayRef<wasm::ValType> Types) override;
  void emitFunctionType(const MCSymbolWasm *Sym) override;
  void emitIndIdx(const MCExpr *Value) override;
  void emitGlobalType(const MCSymbolWasm *Sym) override;
  void emitTableType(const MCSymbolWasm *Sym) override;
  void emitTagType(const MCSymbolWasm *Sym) override;
  void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override;
  void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override;
  void emitExportName(const MCSymbolWasm *Sym, StringRef ExportName) override;
};

/// This part is for Wasm object output
class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
public:
  explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);

  void emitLocal(ArrayRef<wasm::ValType> Types) override;
  void emitFunctionType(const MCSymbolWasm *Sym) override {}
  void emitIndIdx(const MCExpr *Value) override;
  void emitGlobalType(const MCSymbolWasm *Sym) override {}
  void emitTableType(const MCSymbolWasm *Sym) override {}
  void emitTagType(const MCSymbolWasm *Sym) override {}
  void emitImportModule(const MCSymbolWasm *Sym,
                        StringRef ImportModule) override {}
  void emitImportName(const MCSymbolWasm *Sym,
                      StringRef ImportName) override {}
  void emitExportName(const MCSymbolWasm *Sym,
                      StringRef ExportName) override {}
};

/// This part is for null output
class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer {
public:
  explicit WebAssemblyTargetNullStreamer(MCStreamer &S)
      : WebAssemblyTargetStreamer(S) {}

  void emitLocal(ArrayRef<wasm::ValType>) override {}
  void emitFunctionType(const MCSymbolWasm *) override {}
  void emitIndIdx(const MCExpr *) override {}
  void emitGlobalType(const MCSymbolWasm *) override {}
  void emitTableType(const MCSymbolWasm *) override {}
  void emitTagType(const MCSymbolWasm *) override {}
  void emitImportModule(const MCSymbolWasm *, StringRef) override {}
  void emitImportName(const MCSymbolWasm *, StringRef) override {}
  void emitExportName(const MCSymbolWasm *, StringRef) override {}
};

} // end namespace llvm

#endif