blob: 0416aa434d96e8111167e7693348b960d0b3323a [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
Dan Gohman3469ee12016-01-12 20:30:51 +000034 /// .local
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000035 virtual void emitLocal(ArrayRef<wasm::ValType> Types) = 0;
Dan Gohman3469ee12016-01-12 20:30:51 +000036 /// .endfunc
37 virtual void emitEndFunc() = 0;
Derek Schuff5859a9ed2016-06-03 18:34:36 +000038 /// .functype
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000039 virtual void emitFunctionType(MCSymbolWasm *Symbol) = 0;
Derek Schuffc64d7652016-08-01 22:25:02 +000040 /// .indidx
41 virtual void emitIndIdx(const MCExpr *Value) = 0;
Wouter van Oortmerssen3231e512018-11-02 00:45:00 +000042 /// .globaltype
43 virtual void emitGlobalType(MCSymbolWasm *Sym) = 0;
Heejin Ahnda419bd2018-11-14 02:46:21 +000044 /// .eventtype
45 virtual void emitEventType(MCSymbolWasm *Sym) = 0;
Dan Gohmandb1916a2018-02-09 23:13:22 +000046 /// .import_module
47 virtual void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) = 0;
Derek Schuffb8795392017-03-16 20:49:48 +000048
49protected:
50 void emitValueType(wasm::ValType Type);
Dan Gohman3469ee12016-01-12 20:30:51 +000051};
52
53/// This part is for ascii assembly output
54class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
55 formatted_raw_ostream &OS;
56
57public:
58 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
59
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000060 void emitLocal(ArrayRef<wasm::ValType> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000061 void emitEndFunc() override;
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000062 void emitFunctionType(MCSymbolWasm *Symbol) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000063 void emitIndIdx(const MCExpr *Value) override;
Wouter van Oortmerssen3231e512018-11-02 00:45:00 +000064 void emitGlobalType(MCSymbolWasm *Sym) override;
Heejin Ahnda419bd2018-11-14 02:46:21 +000065 void emitEventType(MCSymbolWasm *Sym) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000066 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000067};
68
Dan Gohman18eafb62017-02-22 01:23:18 +000069/// This part is for Wasm object output
70class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
71public:
72 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
73
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000074 void emitLocal(ArrayRef<wasm::ValType> Types) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000075 void emitEndFunc() override;
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000076 void emitFunctionType(MCSymbolWasm *Symbol) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000077 void emitIndIdx(const MCExpr *Value) override;
Wouter van Oortmerssen3231e512018-11-02 00:45:00 +000078 void emitGlobalType(MCSymbolWasm *Sym) override;
Heejin Ahnda419bd2018-11-14 02:46:21 +000079 void emitEventType(MCSymbolWasm *Sym) override;
Dan Gohmandb1916a2018-02-09 23:13:22 +000080 void emitImportModule(MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000081};
82
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000083/// This part is for null output
84class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer {
85public:
86 explicit WebAssemblyTargetNullStreamer(MCStreamer &S)
87 : WebAssemblyTargetStreamer(S) {}
88
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000089 void emitLocal(ArrayRef<wasm::ValType>) override {}
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000090 void emitEndFunc() override {}
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000091 void emitFunctionType(MCSymbolWasm *) override {}
92 void emitIndIdx(const MCExpr *) override {}
93 void emitGlobalType(MCSymbolWasm *) override {}
94 void emitEventType(MCSymbolWasm *) override {}
95 void emitImportModule(MCSymbolWasm *, StringRef) override {}
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000096};
97
Dan Gohman3469ee12016-01-12 20:30:51 +000098} // end namespace llvm
99
100#endif