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 class formatted_raw_ostream; 26 27 /// WebAssembly-specific streamer interface, to implement support 28 /// WebAssembly-specific assembly directives. 29 class WebAssemblyTargetStreamer : public MCTargetStreamer { 30 public: 31 explicit WebAssemblyTargetStreamer(MCStreamer &S); 32 33 /// .local 34 virtual void emitLocal(ArrayRef<wasm::ValType> Types) = 0; 35 /// .endfunc 36 virtual void emitEndFunc() = 0; 37 /// .functype 38 virtual void emitFunctionType(const MCSymbolWasm *Sym) = 0; 39 /// .indidx 40 virtual void emitIndIdx(const MCExpr *Value) = 0; 41 /// .globaltype 42 virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0; 43 /// .tabletype 44 virtual void emitTableType(const MCSymbolWasm *Sym) = 0; 45 /// .tagtype 46 virtual void emitTagType(const MCSymbolWasm *Sym) = 0; 47 /// .import_module 48 virtual void emitImportModule(const MCSymbolWasm *Sym, 49 StringRef ImportModule) = 0; 50 /// .import_name 51 virtual void emitImportName(const MCSymbolWasm *Sym, 52 StringRef ImportName) = 0; 53 /// .export_name 54 virtual void emitExportName(const MCSymbolWasm *Sym, 55 StringRef ExportName) = 0; 56 57 protected: 58 void emitValueType(wasm::ValType Type); 59 }; 60 61 /// This part is for ascii assembly output 62 class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer { 63 formatted_raw_ostream &OS; 64 65 public: 66 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); 67 68 void emitLocal(ArrayRef<wasm::ValType> Types) override; 69 void emitEndFunc() override; 70 void emitFunctionType(const MCSymbolWasm *Sym) override; 71 void emitIndIdx(const MCExpr *Value) override; 72 void emitGlobalType(const MCSymbolWasm *Sym) override; 73 void emitTableType(const MCSymbolWasm *Sym) override; 74 void emitTagType(const MCSymbolWasm *Sym) override; 75 void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override; 76 void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override; 77 void emitExportName(const MCSymbolWasm *Sym, StringRef ExportName) override; 78 }; 79 80 /// This part is for Wasm object output 81 class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer { 82 public: 83 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S); 84 85 void emitLocal(ArrayRef<wasm::ValType> Types) override; 86 void emitEndFunc() override; 87 void emitFunctionType(const MCSymbolWasm *Sym) override {} 88 void emitIndIdx(const MCExpr *Value) override; 89 void emitGlobalType(const MCSymbolWasm *Sym) override {} 90 void emitTableType(const MCSymbolWasm *Sym) override {} 91 void emitTagType(const MCSymbolWasm *Sym) override {} 92 void emitImportModule(const MCSymbolWasm *Sym, 93 StringRef ImportModule) override {} 94 void emitImportName(const MCSymbolWasm *Sym, 95 StringRef ImportName) override {} 96 void emitExportName(const MCSymbolWasm *Sym, 97 StringRef ExportName) override {} 98 }; 99 100 /// This part is for null output 101 class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer { 102 public: 103 explicit WebAssemblyTargetNullStreamer(MCStreamer &S) 104 : WebAssemblyTargetStreamer(S) {} 105 106 void emitLocal(ArrayRef<wasm::ValType>) override {} 107 void emitEndFunc() override {} 108 void emitFunctionType(const MCSymbolWasm *) override {} 109 void emitIndIdx(const MCExpr *) override {} 110 void emitGlobalType(const MCSymbolWasm *) override {} 111 void emitTableType(const MCSymbolWasm *) override {} 112 void emitTagType(const MCSymbolWasm *) override {} 113 void emitImportModule(const MCSymbolWasm *, StringRef) override {} 114 void emitImportName(const MCSymbolWasm *, StringRef) override {} 115 void emitExportName(const MCSymbolWasm *, StringRef) override {} 116 }; 117 118 } // end namespace llvm 119 120 #endif 121