blob: 0164f8e572efb4944d35fe92ac49171159ccd22d [file] [log] [blame]
Dan Gohman3469ee12016-01-12 20:30:51 +00001//==-- WebAssemblyTargetStreamer.h - WebAssembly Target Streamer -*- C++ -*-==//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Dan Gohman3469ee12016-01-12 20:30:51 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This file declares WebAssembly-specific target streamer classes.
Dan Gohman3469ee12016-01-12 20:30:51 +000011/// These are for implementing support for target-specific assembly directives.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
17
Zachary Turner264b5d92017-06-07 03:48:56 +000018#include "llvm/BinaryFormat/Wasm.h"
Dan Gohman3469ee12016-01-12 20:30:51 +000019#include "llvm/MC/MCStreamer.h"
David Blaikie13e77db2018-03-23 23:58:25 +000020#include "llvm/Support/MachineValueType.h"
Dan Gohman3469ee12016-01-12 20:30:51 +000021
22namespace llvm {
23
Dan Gohman18eafb62017-02-22 01:23:18 +000024class MCWasmStreamer;
Dan Gohmandb1916a2018-02-09 23:13:22 +000025class MCSymbolWasm;
Dan Gohman3469ee12016-01-12 20:30:51 +000026
27/// WebAssembly-specific streamer interface, to implement support
28/// WebAssembly-specific assembly directives.
29class WebAssemblyTargetStreamer : public MCTargetStreamer {
30public:
31 explicit WebAssemblyTargetStreamer(MCStreamer &S);
32
Dan Gohman3469ee12016-01-12 20:30:51 +000033 /// .local
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000034 virtual void emitLocal(ArrayRef<wasm::ValType> Types) = 0;
Dan Gohman3469ee12016-01-12 20:30:51 +000035 /// .endfunc
36 virtual void emitEndFunc() = 0;
Derek Schuff5859a9ed2016-06-03 18:34:36 +000037 /// .functype
Heejin Ahn21d45a22018-12-11 00:53:59 +000038 virtual void emitFunctionType(const MCSymbolWasm *Sym) = 0;
Derek Schuffc64d7652016-08-01 22:25:02 +000039 /// .indidx
40 virtual void emitIndIdx(const MCExpr *Value) = 0;
Wouter van Oortmerssen3231e512018-11-02 00:45:00 +000041 /// .globaltype
Heejin Ahn21d45a22018-12-11 00:53:59 +000042 virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0;
Heejin Ahnda419bd2018-11-14 02:46:21 +000043 /// .eventtype
Heejin Ahn21d45a22018-12-11 00:53:59 +000044 virtual void emitEventType(const MCSymbolWasm *Sym) = 0;
Dan Gohmandb1916a2018-02-09 23:13:22 +000045 /// .import_module
Heejin Ahn21d45a22018-12-11 00:53:59 +000046 virtual void emitImportModule(const MCSymbolWasm *Sym,
Dan Gohmanf726e442019-02-01 22:27:34 +000047 StringRef ImportModule) = 0;
48 /// .import_name
49 virtual void emitImportName(const MCSymbolWasm *Sym,
50 StringRef ImportName) = 0;
Derek Schuffb8795392017-03-16 20:49:48 +000051
52protected:
53 void emitValueType(wasm::ValType Type);
Dan Gohman3469ee12016-01-12 20:30:51 +000054};
55
56/// This part is for ascii assembly output
57class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
58 formatted_raw_ostream &OS;
59
60public:
61 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
62
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000063 void emitLocal(ArrayRef<wasm::ValType> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000064 void emitEndFunc() override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000065 void emitFunctionType(const MCSymbolWasm *Sym) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000066 void emitIndIdx(const MCExpr *Value) override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000067 void emitGlobalType(const MCSymbolWasm *Sym) override;
68 void emitEventType(const MCSymbolWasm *Sym) override;
Dan Gohmanf726e442019-02-01 22:27:34 +000069 void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override;
70 void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000071};
72
Dan Gohman18eafb62017-02-22 01:23:18 +000073/// This part is for Wasm object output
74class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
75public:
76 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
77
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000078 void emitLocal(ArrayRef<wasm::ValType> Types) override;
Dan Gohman18eafb62017-02-22 01:23:18 +000079 void emitEndFunc() override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000080 void emitFunctionType(const MCSymbolWasm *Sym) override {}
Dan Gohman18eafb62017-02-22 01:23:18 +000081 void emitIndIdx(const MCExpr *Value) override;
Heejin Ahn21d45a22018-12-11 00:53:59 +000082 void emitGlobalType(const MCSymbolWasm *Sym) override {}
83 void emitEventType(const MCSymbolWasm *Sym) override {}
84 void emitImportModule(const MCSymbolWasm *Sym,
Dan Gohmanf726e442019-02-01 22:27:34 +000085 StringRef ImportModule) override {}
86 void emitImportName(const MCSymbolWasm *Sym,
87 StringRef ImportName) override {}
Dan Gohman18eafb62017-02-22 01:23:18 +000088};
89
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000090/// This part is for null output
91class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer {
92public:
93 explicit WebAssemblyTargetNullStreamer(MCStreamer &S)
94 : WebAssemblyTargetStreamer(S) {}
95
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000096 void emitLocal(ArrayRef<wasm::ValType>) override {}
Heejin Ahne0f8b9b2018-11-18 11:58:47 +000097 void emitEndFunc() override {}
Heejin Ahn21d45a22018-12-11 00:53:59 +000098 void emitFunctionType(const MCSymbolWasm *) override {}
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000099 void emitIndIdx(const MCExpr *) override {}
Heejin Ahn21d45a22018-12-11 00:53:59 +0000100 void emitGlobalType(const MCSymbolWasm *) override {}
101 void emitEventType(const MCSymbolWasm *) override {}
102 void emitImportModule(const MCSymbolWasm *, StringRef) override {}
Dan Gohmanf726e442019-02-01 22:27:34 +0000103 void emitImportName(const MCSymbolWasm *, StringRef) override {}
Heejin Ahne0f8b9b2018-11-18 11:58:47 +0000104};
105
Dan Gohman3469ee12016-01-12 20:30:51 +0000106} // end namespace llvm
107
108#endif