blob: 43c422d593a6b8a030dfcb09ba8df55e73c98996 [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;
Derek Schuff7747d703e2016-12-01 00:11:15 +000046 /// .import_global
47 virtual void emitGlobalImport(StringRef name) = 0;
Dan Gohmandb1916a2018-02-09 23:13:22 +000048 /// .import_module
49 virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0;
Derek Schuffb8795392017-03-16 20:49:48 +000050
51protected:
52 void emitValueType(wasm::ValType Type);
Dan Gohman3469ee12016-01-12 20:30:51 +000053};
54
55/// This part is for ascii assembly output
56class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
57 formatted_raw_ostream &OS;
58
59public:
60 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
61
Dan Gohmand934cb82017-02-24 23:18:00 +000062 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
63 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000064 void emitLocal(ArrayRef<MVT> Types) override;
65 void emitEndFunc() override;
Derek Schuff77a7a382018-10-03 22:22:48 +000066 void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000067 void emitIndIdx(const MCExpr *Value) override;
Derek Schuff7747d703e2016-12-01 00:11:15 +000068 void emitGlobalImport(StringRef name) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000069 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000070};
71
Dan Gohman18eafb62017-02-22 01:23:18 +000072/// This part is for Wasm object output
73class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
74public:
75 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
76
Dan Gohmand934cb82017-02-24 23:18:00 +000077 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
78 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000079 void emitLocal(ArrayRef<MVT> Types) override;
80 void emitEndFunc() override;
Derek Schuff77a7a382018-10-03 22:22:48 +000081 void emitIndirectFunctionType(MCSymbolWasm *Symbol) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000082 void emitIndIdx(const MCExpr *Value) override;
83 void emitGlobalImport(StringRef name) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000084 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000085};
86
Dan Gohman3469ee12016-01-12 20:30:51 +000087} // end namespace llvm
88
89#endif