1 //==-- WebAssemblyTargetStreamer.h - WebAssembly Target Streamer -*- 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 /// \file
11 /// This file declares WebAssembly-specific target streamer classes.
12 /// These are for implementing support for target-specific assembly directives.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
18 
19 #include "llvm/BinaryFormat/Wasm.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/Support/MachineValueType.h"
22 
23 namespace llvm {
24 
25 class MCWasmStreamer;
26 class MCSymbolWasm;
27 
28 /// WebAssembly-specific streamer interface, to implement support
29 /// WebAssembly-specific assembly directives.
30 class WebAssemblyTargetStreamer : public MCTargetStreamer {
31 public:
32   explicit WebAssemblyTargetStreamer(MCStreamer &S);
33 
34   /// .local
35   virtual void emitLocal(ArrayRef<wasm::ValType> Types) = 0;
36   /// .endfunc
37   virtual void emitEndFunc() = 0;
38   /// .functype
39   virtual void emitFunctionType(MCSymbolWasm *Symbol) = 0;
40   /// .indidx
41   virtual void emitIndIdx(const MCExpr *Value) = 0;
42   /// .globaltype
43   virtual void emitGlobalType(MCSymbolWasm *Sym) = 0;
44   /// .eventtype
45   virtual void emitEventType(MCSymbolWasm *Sym) = 0;
46   /// .import_module
47   virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0;
48 
49 protected:
50   void emitValueType(wasm::ValType Type);
51 };
52 
53 /// This part is for ascii assembly output
54 class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
55   formatted_raw_ostream &OS;
56 
57 public:
58   WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
59 
60   void emitLocal(ArrayRef<wasm::ValType> Types) override;
61   void emitEndFunc() override;
62   void emitFunctionType(MCSymbolWasm *Symbol) override;
63   void emitIndIdx(const MCExpr *Value) override;
64   void emitGlobalType(MCSymbolWasm *Sym) override;
65   void emitEventType(MCSymbolWasm *Sym) override;
66   void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
67 };
68 
69 /// This part is for Wasm object output
70 class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
71 public:
72   explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
73 
74   void emitLocal(ArrayRef<wasm::ValType> Types) override;
75   void emitEndFunc() override;
76   void emitFunctionType(MCSymbolWasm *Symbol) override;
77   void emitIndIdx(const MCExpr *Value) override;
78   void emitGlobalType(MCSymbolWasm *Sym) override;
79   void emitEventType(MCSymbolWasm *Sym) override;
80   void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
81 };
82 
83 /// This part is for null output
84 class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer {
85 public:
86   explicit WebAssemblyTargetNullStreamer(MCStreamer &S)
87       : WebAssemblyTargetStreamer(S) {}
88 
89   void emitLocal(ArrayRef<wasm::ValType>) override {}
90   void emitEndFunc() override {}
91   void emitFunctionType(MCSymbolWasm *) override {}
92   void emitIndIdx(const MCExpr *) override {}
93   void emitGlobalType(MCSymbolWasm *) override {}
94   void emitEventType(MCSymbolWasm *) override {}
95   void emitImportModule(MCSymbolWasm *, StringRef) override {}
96 };
97 
98 } // end namespace llvm
99 
100 #endif
101