blob: 165e71ad99f79d1e5d58bb62f384bd2e22b4940c [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
11/// \brief 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
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
25class MCELFStreamer;
Dan Gohman18eafb62017-02-22 01:23:18 +000026class MCWasmStreamer;
Dan Gohmandb1916a2018-02-09 23:13:22 +000027class MCSymbolWasm;
Dan Gohman3469ee12016-01-12 20:30:51 +000028
29/// WebAssembly-specific streamer interface, to implement support
30/// WebAssembly-specific assembly directives.
31class WebAssemblyTargetStreamer : public MCTargetStreamer {
32public:
33 explicit WebAssemblyTargetStreamer(MCStreamer &S);
34
35 /// .param
Dan Gohmand934cb82017-02-24 23:18:00 +000036 virtual void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) = 0;
Dan Gohman3469ee12016-01-12 20:30:51 +000037 /// .result
Dan Gohmand934cb82017-02-24 23:18:00 +000038 virtual void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) = 0;
Dan Gohman3469ee12016-01-12 20:30:51 +000039 /// .local
40 virtual void emitLocal(ArrayRef<MVT> Types) = 0;
41 /// .endfunc
42 virtual void emitEndFunc() = 0;
Derek Schuff5859a9ed2016-06-03 18:34:36 +000043 /// .functype
Sam Clegg9bf73c02017-07-05 20:25:08 +000044 virtual void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman2726b882016-10-06 22:29:32 +000045 SmallVectorImpl<MVT> &Params,
Sam Cleggae03c1e72017-06-13 18:51:50 +000046 SmallVectorImpl<MVT> &Results) = 0;
Derek Schuffc64d7652016-08-01 22:25:02 +000047 /// .indidx
48 virtual void emitIndIdx(const MCExpr *Value) = 0;
Derek Schuff7747d703e2016-12-01 00:11:15 +000049 /// .import_global
50 virtual void emitGlobalImport(StringRef name) = 0;
Dan Gohmandb1916a2018-02-09 23:13:22 +000051 /// .import_module
52 virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0;
Derek Schuffb8795392017-03-16 20:49:48 +000053
54protected:
55 void emitValueType(wasm::ValType Type);
Dan Gohman3469ee12016-01-12 20:30:51 +000056};
57
58/// This part is for ascii assembly output
59class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
60 formatted_raw_ostream &OS;
61
62public:
63 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
64
Dan Gohmand934cb82017-02-24 23:18:00 +000065 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
66 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000067 void emitLocal(ArrayRef<MVT> Types) override;
68 void emitEndFunc() override;
Sam Clegg9bf73c02017-07-05 20:25:08 +000069 void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman2726b882016-10-06 22:29:32 +000070 SmallVectorImpl<MVT> &Params,
71 SmallVectorImpl<MVT> &Results) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000072 void emitIndIdx(const MCExpr *Value) override;
Derek Schuff7747d703e2016-12-01 00:11:15 +000073 void emitGlobalImport(StringRef name) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000074 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000075};
76
77/// This part is for ELF object output
78class WebAssemblyTargetELFStreamer final : public WebAssemblyTargetStreamer {
79public:
80 explicit WebAssemblyTargetELFStreamer(MCStreamer &S);
81
Dan Gohmand934cb82017-02-24 23:18:00 +000082 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
83 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000084 void emitLocal(ArrayRef<MVT> Types) override;
85 void emitEndFunc() override;
Sam Clegg9bf73c02017-07-05 20:25:08 +000086 void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman3acb1872016-10-24 23:27:49 +000087 SmallVectorImpl<MVT> &Params,
88 SmallVectorImpl<MVT> &Results) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000089 void emitIndIdx(const MCExpr *Value) override;
Derek Schuff7747d703e2016-12-01 00:11:15 +000090 void emitGlobalImport(StringRef name) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000091 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000092};
93
Dan Gohman18eafb62017-02-22 01:23:18 +000094/// This part is for Wasm object output
95class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
96public:
97 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
98
Dan Gohmand934cb82017-02-24 23:18:00 +000099 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
100 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman18eafb62017-02-22 01:23:18 +0000101 void emitLocal(ArrayRef<MVT> Types) override;
102 void emitEndFunc() override;
Sam Clegg9bf73c02017-07-05 20:25:08 +0000103 void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman18eafb62017-02-22 01:23:18 +0000104 SmallVectorImpl<MVT> &Params,
105 SmallVectorImpl<MVT> &Results) override;
106 void emitIndIdx(const MCExpr *Value) override;
107 void emitGlobalImport(StringRef name) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +0000108 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman18eafb62017-02-22 01:23:18 +0000109};
110
Dan Gohman3469ee12016-01-12 20:30:51 +0000111} // end namespace llvm
112
113#endif