blob: 102d7219a1e7494f366a0ef67766f6bafa6a44ae [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 Gohman46350172016-01-12 20:56:01 +000020#include "llvm/CodeGen/MachineValueType.h"
Dan Gohman3469ee12016-01-12 20:30:51 +000021#include "llvm/MC/MCStreamer.h"
22
23namespace llvm {
24
25class MCELFStreamer;
Dan Gohman18eafb62017-02-22 01:23:18 +000026class MCWasmStreamer;
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;
Dan Gohman82607f52017-02-24 23:46:05 +000040 /// .globalvar
Dan Gohman970d02c2017-03-30 23:58:19 +000041 virtual void emitGlobal(ArrayRef<wasm::Global> Globals) = 0;
42 /// .stack_pointer
43 virtual void emitStackPointer(uint32_t Index) = 0;
Dan Gohman3469ee12016-01-12 20:30:51 +000044 /// .endfunc
45 virtual void emitEndFunc() = 0;
Derek Schuff5859a9ed2016-06-03 18:34:36 +000046 /// .functype
Sam Clegg9bf73c02017-07-05 20:25:08 +000047 virtual void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman2726b882016-10-06 22:29:32 +000048 SmallVectorImpl<MVT> &Params,
Sam Cleggae03c1e72017-06-13 18:51:50 +000049 SmallVectorImpl<MVT> &Results) = 0;
Derek Schuffc64d7652016-08-01 22:25:02 +000050 /// .indidx
51 virtual void emitIndIdx(const MCExpr *Value) = 0;
Derek Schuff7747d703e2016-12-01 00:11:15 +000052 /// .import_global
53 virtual void emitGlobalImport(StringRef name) = 0;
Derek Schuffb8795392017-03-16 20:49:48 +000054
55protected:
56 void emitValueType(wasm::ValType Type);
Dan Gohman3469ee12016-01-12 20:30:51 +000057};
58
59/// This part is for ascii assembly output
60class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
61 formatted_raw_ostream &OS;
62
63public:
64 WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
65
Dan Gohmand934cb82017-02-24 23:18:00 +000066 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
67 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000068 void emitLocal(ArrayRef<MVT> Types) override;
Dan Gohman970d02c2017-03-30 23:58:19 +000069 void emitGlobal(ArrayRef<wasm::Global> Globals) override;
70 void emitStackPointer(uint32_t Index) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000071 void emitEndFunc() override;
Sam Clegg9bf73c02017-07-05 20:25:08 +000072 void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman2726b882016-10-06 22:29:32 +000073 SmallVectorImpl<MVT> &Params,
74 SmallVectorImpl<MVT> &Results) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000075 void emitIndIdx(const MCExpr *Value) override;
Derek Schuff7747d703e2016-12-01 00:11:15 +000076 void emitGlobalImport(StringRef name) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000077};
78
79/// This part is for ELF object output
80class WebAssemblyTargetELFStreamer final : public WebAssemblyTargetStreamer {
81public:
82 explicit WebAssemblyTargetELFStreamer(MCStreamer &S);
83
Dan Gohmand934cb82017-02-24 23:18:00 +000084 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
85 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000086 void emitLocal(ArrayRef<MVT> Types) override;
Dan Gohman970d02c2017-03-30 23:58:19 +000087 void emitGlobal(ArrayRef<wasm::Global> Globals) override;
88 void emitStackPointer(uint32_t Index) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000089 void emitEndFunc() override;
Sam Clegg9bf73c02017-07-05 20:25:08 +000090 void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman3acb1872016-10-24 23:27:49 +000091 SmallVectorImpl<MVT> &Params,
92 SmallVectorImpl<MVT> &Results) override;
Derek Schuffc64d7652016-08-01 22:25:02 +000093 void emitIndIdx(const MCExpr *Value) override;
Derek Schuff7747d703e2016-12-01 00:11:15 +000094 void emitGlobalImport(StringRef name) override;
Dan Gohman3469ee12016-01-12 20:30:51 +000095};
96
Dan Gohman18eafb62017-02-22 01:23:18 +000097/// This part is for Wasm object output
98class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
99public:
100 explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
101
Dan Gohmand934cb82017-02-24 23:18:00 +0000102 void emitParam(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
103 void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
Dan Gohman18eafb62017-02-22 01:23:18 +0000104 void emitLocal(ArrayRef<MVT> Types) override;
Dan Gohman970d02c2017-03-30 23:58:19 +0000105 void emitGlobal(ArrayRef<wasm::Global> Globals) override;
106 void emitStackPointer(uint32_t Index) override;
Dan Gohman18eafb62017-02-22 01:23:18 +0000107 void emitEndFunc() override;
Sam Clegg9bf73c02017-07-05 20:25:08 +0000108 void emitIndirectFunctionType(MCSymbol *Symbol,
Dan Gohman18eafb62017-02-22 01:23:18 +0000109 SmallVectorImpl<MVT> &Params,
110 SmallVectorImpl<MVT> &Results) override;
111 void emitIndIdx(const MCExpr *Value) override;
112 void emitGlobalImport(StringRef name) override;
113};
114
Dan Gohman3469ee12016-01-12 20:30:51 +0000115} // end namespace llvm
116
117#endif