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   /// .param
35   virtual void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) = 0;
36   /// .result
37   virtual void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) = 0;
38   /// .local
39   virtual void emitLocal(ArrayRef<MVT> Types) = 0;
40   /// .endfunc
41   virtual void emitEndFunc() = 0;
42   /// .functype
43   virtual void emitIndirectFunctionType(MCSymbolWasm *Symbol) = 0;
44   /// .indidx
45   virtual void emitIndIdx(const MCExpr *Value) = 0;
46   /// .globaltype
47   virtual void emitGlobalType(MCSymbolWasm *Sym) = 0;
48   /// .eventtype
49   virtual void emitEventType(MCSymbolWasm *Sym) = 0;
50   /// .import_module
51   virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0;
52 
53 protected:
54   void emitValueType(wasm::ValType Type);
55 };
56 
57 /// This part is for ascii assembly output
58 class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
59   formatted_raw_ostream &OS;
60 
61 public:
62   WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
63 
64   void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
65   void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
66   void emitLocal(ArrayRef<MVT> Types) override;
67   void emitEndFunc() override;
68   void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
69   void emitIndIdx(const MCExpr *Value) override;
70   void emitGlobalType(MCSymbolWasm *Sym) override;
71   void emitEventType(MCSymbolWasm *Sym) override;
72   void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
73 };
74 
75 /// This part is for Wasm object output
76 class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
77 public:
78   explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
79 
80   void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
81   void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
82   void emitLocal(ArrayRef<MVT> Types) override;
83   void emitEndFunc() override;
84   void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
85   void emitIndIdx(const MCExpr *Value) override;
86   void emitGlobalType(MCSymbolWasm *Sym) override;
87   void emitEventType(MCSymbolWasm *Sym) override;
88   void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
89 };
90 
91 } // end namespace llvm
92 
93 #endif
94