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(MCSymbol *Symbol, 44 SmallVectorImpl<MVT> &Params, 45 SmallVectorImpl<MVT> &Results) = 0; 46 /// .indidx 47 virtual void emitIndIdx(const MCExpr *Value) = 0; 48 /// .import_global 49 virtual void emitGlobalImport(StringRef name) = 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(MCSymbol *Symbol, 69 SmallVectorImpl<MVT> &Params, 70 SmallVectorImpl<MVT> &Results) override; 71 void emitIndIdx(const MCExpr *Value) override; 72 void emitGlobalImport(StringRef name) override; 73 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override; 74 }; 75 76 /// This part is for Wasm object output 77 class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer { 78 public: 79 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S); 80 81 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override; 82 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override; 83 void emitLocal(ArrayRef<MVT> Types) override; 84 void emitEndFunc() override; 85 void emitIndirectFunctionType(MCSymbol *Symbol, 86 SmallVectorImpl<MVT> &Params, 87 SmallVectorImpl<MVT> &Results) override; 88 void emitIndIdx(const MCExpr *Value) override; 89 void emitGlobalImport(StringRef name) override; 90 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override; 91 }; 92 93 } // end namespace llvm 94 95 #endif 96