1 //==-- WebAssemblyTargetStreamer.h - WebAssembly Target Streamer -*- C++ -*-==//
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
7 //===----------------------------------------------------------------------===//
10 /// This file declares WebAssembly-specific target streamer classes.
11 /// These are for implementing support for target-specific assembly directives.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
18 #include "llvm/BinaryFormat/Wasm.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/Support/MachineValueType.h"
25 class formatted_raw_ostream
;
27 /// WebAssembly-specific streamer interface, to implement support
28 /// WebAssembly-specific assembly directives.
29 class WebAssemblyTargetStreamer
: public MCTargetStreamer
{
31 explicit WebAssemblyTargetStreamer(MCStreamer
&S
);
34 virtual void emitLocal(ArrayRef
<wasm::ValType
> Types
) = 0;
36 virtual void emitEndFunc() = 0;
38 virtual void emitFunctionType(const MCSymbolWasm
*Sym
) = 0;
40 virtual void emitIndIdx(const MCExpr
*Value
) = 0;
42 virtual void emitGlobalType(const MCSymbolWasm
*Sym
) = 0;
44 virtual void emitTableType(const MCSymbolWasm
*Sym
) = 0;
46 virtual void emitTagType(const MCSymbolWasm
*Sym
) = 0;
48 virtual void emitImportModule(const MCSymbolWasm
*Sym
,
49 StringRef ImportModule
) = 0;
51 virtual void emitImportName(const MCSymbolWasm
*Sym
,
52 StringRef ImportName
) = 0;
54 virtual void emitExportName(const MCSymbolWasm
*Sym
,
55 StringRef ExportName
) = 0;
58 void emitValueType(wasm::ValType Type
);
61 /// This part is for ascii assembly output
62 class WebAssemblyTargetAsmStreamer final
: public WebAssemblyTargetStreamer
{
63 formatted_raw_ostream
&OS
;
66 WebAssemblyTargetAsmStreamer(MCStreamer
&S
, formatted_raw_ostream
&OS
);
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
;
80 /// This part is for Wasm object output
81 class WebAssemblyTargetWasmStreamer final
: public WebAssemblyTargetStreamer
{
83 explicit WebAssemblyTargetWasmStreamer(MCStreamer
&S
);
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
{}
100 /// This part is for null output
101 class WebAssemblyTargetNullStreamer final
: public WebAssemblyTargetStreamer
{
103 explicit WebAssemblyTargetNullStreamer(MCStreamer
&S
)
104 : WebAssemblyTargetStreamer(S
) {}
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
{}
118 } // end namespace llvm