1 //==-- WebAssemblyTargetStreamer.h - WebAssembly Target Streamer -*- C++ -*-==// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// \file 10 /// This file declares WebAssembly-specific target streamer classes. 11 /// These are for implementing support for target-specific assembly directives. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H 16 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H 17 18 #include "llvm/BinaryFormat/Wasm.h" 19 #include "llvm/MC/MCStreamer.h" 20 #include "llvm/Support/MachineValueType.h" 21 22 namespace llvm { 23 24 class MCSymbolWasm; 25 26 /// WebAssembly-specific streamer interface, to implement support 27 /// WebAssembly-specific assembly directives. 28 class WebAssemblyTargetStreamer : public MCTargetStreamer { 29 public: 30 explicit WebAssemblyTargetStreamer(MCStreamer &S); 31 32 /// .local 33 virtual void emitLocal(ArrayRef<wasm::ValType> Types) = 0; 34 /// .endfunc 35 virtual void emitEndFunc() = 0; 36 /// .functype 37 virtual void emitFunctionType(const MCSymbolWasm *Sym) = 0; 38 /// .indidx 39 virtual void emitIndIdx(const MCExpr *Value) = 0; 40 /// .globaltype 41 virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0; 42 /// .tabletype 43 virtual void emitTableType(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 /// .export_name 53 virtual void emitExportName(const MCSymbolWasm *Sym, 54 StringRef ExportName) = 0; 55 56 protected: 57 void emitValueType(wasm::ValType Type); 58 }; 59 60 /// This part is for ascii assembly output 61 class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer { 62 formatted_raw_ostream &OS; 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 emitTableType(const MCSymbolWasm *Sym) override; 73 void emitEventType(const MCSymbolWasm *Sym) override; 74 void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override; 75 void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override; 76 void emitExportName(const MCSymbolWasm *Sym, StringRef ExportName) override; 77 }; 78 79 /// This part is for Wasm object output 80 class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer { 81 public: 82 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S); 83 84 void emitLocal(ArrayRef<wasm::ValType> Types) override; 85 void emitEndFunc() override; 86 void emitFunctionType(const MCSymbolWasm *Sym) override {} 87 void emitIndIdx(const MCExpr *Value) override; 88 void emitGlobalType(const MCSymbolWasm *Sym) override {} 89 void emitTableType(const MCSymbolWasm *Sym) override {} 90 void emitEventType(const MCSymbolWasm *Sym) override {} 91 void emitImportModule(const MCSymbolWasm *Sym, 92 StringRef ImportModule) override {} 93 void emitImportName(const MCSymbolWasm *Sym, 94 StringRef ImportName) override {} 95 void emitExportName(const MCSymbolWasm *Sym, 96 StringRef ExportName) override {} 97 }; 98 99 /// This part is for null output 100 class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer { 101 public: 102 explicit WebAssemblyTargetNullStreamer(MCStreamer &S) 103 : WebAssemblyTargetStreamer(S) {} 104 105 void emitLocal(ArrayRef<wasm::ValType>) override {} 106 void emitEndFunc() override {} 107 void emitFunctionType(const MCSymbolWasm *) override {} 108 void emitIndIdx(const MCExpr *) override {} 109 void emitGlobalType(const MCSymbolWasm *) override {} 110 void emitTableType(const MCSymbolWasm *) override {} 111 void emitEventType(const MCSymbolWasm *) override {} 112 void emitImportModule(const MCSymbolWasm *, StringRef) override {} 113 void emitImportName(const MCSymbolWasm *, StringRef) override {} 114 void emitExportName(const MCSymbolWasm *, StringRef) override {} 115 }; 116 117 } // end namespace llvm 118 119 #endif 120