blob: 3f1c6e158b23738f4b787ddf7a712f73c606e3ca [file] [log] [blame]
Dan Gohman3469ee12016-01-12 20:30:51 +00001//==-- 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
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011/// This file declares WebAssembly-specific target streamer classes.
Dan Gohman3469ee12016-01-12 20:30:51 +000012/// 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
Zachary Turner264b5d92017-06-07 03:48:56 +000019#include "llvm/BinaryFormat/Wasm.h"
Dan Gohman3469ee12016-01-12 20:30:51 +000020#include "llvm/MC/MCStreamer.h"
David Blaikie13e77db2018-03-23 23:58:25 +000021#include "llvm/Support/MachineValueType.h"
Dan Gohman3469ee12016-01-12 20:30:51 +000022
23namespace llvm {
24
Dan Gohman18eafb62017-02-22 01:23:18 +000025class MCWasmStreamer;
Dan Gohmandb1916a2018-02-09 23:13:22 +000026class MCSymbolWasm;
Dan Gohman3469ee12016-01-12 20:30:51 +000027
28/// WebAssembly-specific streamer interface, to implement support
29/// WebAssembly-specific assembly directives.
30class WebAssemblyTargetStreamer : public MCTargetStreamer {
31public:
32 explicit WebAssemblyTargetStreamer(MCStreamer &S);
33
34 /// .param
Dan Gohmand934cb82017-02-24 23:18:00 +000035 virtual void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) = 0;
Dan Gohman3469ee12016-01-12 20:30:51 +000036 /// .result
Dan Gohmand934cb82017-02-24 23:18:00 +000037 virtual void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) = 0;
Dan Gohman3469ee12016-01-12 20:30:51 +000038 /// .local
39 virtual void emitLocal(ArrayRef<MVT> Types) = 0;
40 /// .endfunc
41 virtual void emitEndFunc() = 0;
Derek Schuff5859a9ed2016-06-03 18:34:36 +000042 /// .functype
Derek Schuff77a7a382018-10-03 22:22:48 +000043 virtual void emitIndirectFunctionType(MCSymbolWasm *Symbol) = 0;
Derek Schuffc64d7652016-08-01 22:25:02 +000044 /// .indidx
45 virtual void emitIndIdx(const MCExpr *Value) = 0;
Wouter van Oortmerssen3231e512018-11-02 00:45:00 +000046 /// .globaltype
47 virtual void emitGlobalType(MCSymbolWasm *Sym) = 0;
Heejin Ahnda419bd2018-11-14 02:46:21 +000048 /// .eventtype
49 virtual void emitEventType(MCSymbolWasm *Sym) = 0;
Dan Gohmandb1916a2018-02-09 23:13:22 +000050 /// .import_module
51 virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0;
Derek Schuffb8795392017-03-16 20:49:48 +000052
53protected:
54 void emitValueType(wasm::ValType Type);
Dan Gohman3469ee12016-01-12 20:30:51 +000055};
56
57/// This part is for ascii assembly output
58class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
59 formatted_raw_ostream &OS;
60
61public:
62 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
63
Dan Gohmand934cb82017-02-24 23:18:00 +000064 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
65 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000066 void emitLocal(ArrayRef<MVT> Types) override;
67 void emitEndFunc() override;
Derek Schuff77a7a382018-10-03 22:22:48 +000068 void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000069 void emitIndIdx(const MCExpr *Value) override;
Wouter van Oortmerssen3231e512018-11-02 00:45:00 +000070 void emitGlobalType(MCSymbolWasm *Sym) override;
Heejin Ahnda419bd2018-11-14 02:46:21 +000071 void emitEventType(MCSymbolWasm *Sym) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000072 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000073};
74
Dan Gohman18eafb62017-02-22 01:23:18 +000075/// This part is for Wasm object output
76class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
77public:
78 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
79
Dan Gohmand934cb82017-02-24 23:18:00 +000080 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
81 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000082 void emitLocal(ArrayRef<MVT> Types) override;
83 void emitEndFunc() override;
Derek Schuff77a7a382018-10-03 22:22:48 +000084 void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000085 void emitIndIdx(const MCExpr *Value) override;
Wouter van Oortmerssen3231e512018-11-02 00:45:00 +000086 void emitGlobalType(MCSymbolWasm *Sym) override;
Heejin Ahnda419bd2018-11-14 02:46:21 +000087 void emitEventType(MCSymbolWasm *Sym) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000088 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000089};
90
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000091/// This part is for null output
92class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer {
93public:
94 explicit WebAssemblyTargetNullStreamer(MCStreamer &S)
95 : WebAssemblyTargetStreamer(S) {}
96
97 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override {}
98 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override {}
99 void emitLocal(ArrayRef<MVT> Types) override {}
100 void emitEndFunc() override {}
101 void emitIndirectFunctionType(MCSymbolWasm *Symbol) override {}
102 void emitIndIdx(const MCExpr *Value) override {}
103 void emitGlobalType(MCSymbolWasm *Sym) override {}
104 void emitEventType(MCSymbolWasm *Sym) override {}
105 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override {}
106};
107
Dan Gohman3469ee12016-01-12 20:30:51 +0000108} // end namespace llvm
109
110#endif