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(const MCSymbolWasm *Sym) = 0; 40 /// .indidx 41 virtual void emitIndIdx(const MCExpr *Value) = 0; 42 /// .globaltype 43 virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0; 44 /// .eventtype 45 virtual void emitEventType(const MCSymbolWasm *Sym) = 0; 46 /// .import_module 47 virtual void emitImportModule(const MCSymbolWasm *Sym, 48 StringRef ImportModule) = 0; 49 /// .import_name 50 virtual void emitImportName(const MCSymbolWasm *Sym, 51 StringRef ImportName) = 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 void emitSignature(const wasm::WasmSignature *Sig); 61 void emitParamList(const wasm::WasmSignature *Sig); 62 void emitReturnList(const wasm::WasmSignature *Sig); 63 64 public: 65 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); 66 67 void emitLocal(ArrayRef<wasm::ValType> Types) override; 68 void emitEndFunc() override; 69 void emitFunctionType(const MCSymbolWasm *Sym) override; 70 void emitIndIdx(const MCExpr *Value) override; 71 void emitGlobalType(const MCSymbolWasm *Sym) override; 72 void emitEventType(const MCSymbolWasm *Sym) override; 73 void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override; 74 void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override; 75 }; 76 77 /// This part is for Wasm object output 78 class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer { 79 public: 80 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S); 81 82 void emitLocal(ArrayRef<wasm::ValType> Types) override; 83 void emitEndFunc() override; emitFunctionType(const MCSymbolWasm * Sym)84 void emitFunctionType(const MCSymbolWasm *Sym) override {} 85 void emitIndIdx(const MCExpr *Value) override; emitGlobalType(const MCSymbolWasm * Sym)86 void emitGlobalType(const MCSymbolWasm *Sym) override {} emitEventType(const MCSymbolWasm * Sym)87 void emitEventType(const MCSymbolWasm *Sym) override {} emitImportModule(const MCSymbolWasm * Sym,StringRef ImportModule)88 void emitImportModule(const MCSymbolWasm *Sym, 89 StringRef ImportModule) override {} emitImportName(const MCSymbolWasm * Sym,StringRef ImportName)90 void emitImportName(const MCSymbolWasm *Sym, 91 StringRef ImportName) override {} 92 }; 93 94 /// This part is for null output 95 class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer { 96 public: WebAssemblyTargetNullStreamer(MCStreamer & S)97 explicit WebAssemblyTargetNullStreamer(MCStreamer &S) 98 : WebAssemblyTargetStreamer(S) {} 99 emitLocal(ArrayRef<wasm::ValType>)100 void emitLocal(ArrayRef<wasm::ValType>) override {} emitEndFunc()101 void emitEndFunc() override {} emitFunctionType(const MCSymbolWasm *)102 void emitFunctionType(const MCSymbolWasm *) override {} emitIndIdx(const MCExpr *)103 void emitIndIdx(const MCExpr *) override {} emitGlobalType(const MCSymbolWasm *)104 void emitGlobalType(const MCSymbolWasm *) override {} emitEventType(const MCSymbolWasm *)105 void emitEventType(const MCSymbolWasm *) override {} emitImportModule(const MCSymbolWasm *,StringRef)106 void emitImportModule(const MCSymbolWasm *, StringRef) override {} emitImportName(const MCSymbolWasm *,StringRef)107 void emitImportName(const MCSymbolWasm *, StringRef) override {} 108 }; 109 110 } // end namespace llvm 111 112 #endif 113