blob: 9085dbd1f5f5bcde80e9065d7a235dc333555896 [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
Heejin Ahn21d45a22018-12-11 00:53:59 +000039 virtual void emitFunctionType(const MCSymbolWasm *Sym) = 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
Heejin Ahn21d45a22018-12-11 00:53:59 +000043 virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0;
Heejin Ahnda419bd2018-11-14 02:46:21 +000044 /// .eventtype
Heejin Ahn21d45a22018-12-11 00:53:59 +000045 virtual void emitEventType(const MCSymbolWasm *Sym) = 0;
Dan Gohmandb1916a2018-02-09 23:13:22 +000046 /// .import_module
Heejin Ahn21d45a22018-12-11 00:53:59 +000047 virtual void emitImportModule(const MCSymbolWasm *Sym,
48 StringRef ModuleName) = 0;
Derek Schuffb8795392017-03-16 20:49:48 +000049
50protected:
51 void emitValueType(wasm::ValType Type);
Dan Gohman3469ee12016-01-12 20:30:51 +000052};
53
54/// This part is for ascii assembly output
55class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
56 formatted_raw_ostream &OS;
57
58public:
59 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
60
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000061 void emitLocal(ArrayRef<wasm::ValType> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000062 void emitEndFunc() override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000063 void emitFunctionType(const MCSymbolWasm *Sym) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000064 void emitIndIdx(const MCExpr *Value) override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000065 void emitGlobalType(const MCSymbolWasm *Sym) override;
66 void emitEventType(const MCSymbolWasm *Sym) override;
67 void emitImportModule(const MCSymbolWasm *Sym, StringRef ModuleName) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000068};
69
Dan Gohman18eafb62017-02-22 01:23:18 +000070/// This part is for Wasm object output
71class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
72public:
73 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
74
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000075 void emitLocal(ArrayRef<wasm::ValType> Types) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000076 void emitEndFunc() override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000077 void emitFunctionType(const MCSymbolWasm *Sym) override {}
Dan Gohman18eafb62017-02-22 01:23:18 +000078 void emitIndIdx(const MCExpr *Value) override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000079 void emitGlobalType(const MCSymbolWasm *Sym) override {}
80 void emitEventType(const MCSymbolWasm *Sym) override {}
81 void emitImportModule(const MCSymbolWasm *Sym,
82 StringRef ModuleName) override {}
Dan Gohman18eafb62017-02-22 01:23:18 +000083};
84
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000085/// This part is for null output
86class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer {
87public:
88 explicit WebAssemblyTargetNullStreamer(MCStreamer &S)
89 : WebAssemblyTargetStreamer(S) {}
90
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000091 void emitLocal(ArrayRef<wasm::ValType>) override {}
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000092 void emitEndFunc() override {}
Heejin Ahn21d45a22018-12-11 00:53:59 +000093 void emitFunctionType(const MCSymbolWasm *) override {}
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000094 void emitIndIdx(const MCExpr *) override {}
Heejin Ahn21d45a22018-12-11 00:53:59 +000095 void emitGlobalType(const MCSymbolWasm *) override {}
96 void emitEventType(const MCSymbolWasm *) override {}
97 void emitImportModule(const MCSymbolWasm *, StringRef) override {}
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000098};
99
Dan Gohman3469ee12016-01-12 20:30:51 +0000100} // end namespace llvm
101
102#endif