LLVM  10.0.0svn
WebAssemblyTargetStreamer.cpp
Go to the documentation of this file.
1 //==-- WebAssemblyTargetStreamer.cpp - WebAssembly Target Streamer Methods --=//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines WebAssembly-specific target streamer classes.
11 /// These are for implementing support for target-specific assembly directives.
12 ///
13 //===----------------------------------------------------------------------===//
14 
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCSectionWasm.h"
21 #include "llvm/MC/MCSymbolWasm.h"
22 #include "llvm/Support/Casting.h"
25 using namespace llvm;
26 
28  : MCTargetStreamer(S) {}
29 
31  Streamer.EmitIntValue(uint8_t(Type), 1);
32 }
33 
36  : WebAssemblyTargetStreamer(S), OS(OS) {}
37 
40 
43  bool First = true;
44  for (auto Type : Types) {
45  if (First)
46  First = false;
47  else
48  OS << ", ";
50  }
51  OS << '\n';
52 }
53 
55  if (!Types.empty()) {
56  OS << "\t.local \t";
57  printTypes(OS, Types);
58  }
59 }
60 
61 void WebAssemblyTargetAsmStreamer::emitEndFunc() { OS << "\t.endfunc\n"; }
62 
64  assert(Sym->isFunction());
65  OS << "\t.functype\t" << Sym->getName() << " ";
67  OS << "\n";
68 }
69 
71  assert(Sym->isGlobal());
72  OS << "\t.globaltype\t" << Sym->getName() << ", "
74  static_cast<wasm::ValType>(Sym->getGlobalType().Type))
75  << '\n';
76 }
77 
79  assert(Sym->isEvent());
80  OS << "\t.eventtype\t" << Sym->getName() << " ";
82  OS << "\n";
83 }
84 
86  StringRef ImportModule) {
87  OS << "\t.import_module\t" << Sym->getName() << ", "
88  << ImportModule << '\n';
89 }
90 
92  StringRef ImportName) {
93  OS << "\t.import_name\t" << Sym->getName() << ", "
94  << ImportName << '\n';
95 }
96 
98  OS << "\t.indidx \t" << *Value << '\n';
99 }
100 
103  for (auto Type : Types) {
104  if (Grouped.empty() || Grouped.back().first != Type)
105  Grouped.push_back(std::make_pair(Type, 1));
106  else
107  ++Grouped.back().second;
108  }
109 
110  Streamer.EmitULEB128IntValue(Grouped.size());
111  for (auto Pair : Grouped) {
112  Streamer.EmitULEB128IntValue(Pair.second);
113  emitValueType(Pair.first);
114  }
115 }
116 
118  llvm_unreachable(".end_func is not needed for direct wasm output");
119 }
120 
122  llvm_unreachable(".indidx encoding not yet implemented");
123 }
bool isFunction() const
Definition: MCSymbolWasm.h:42
void emitGlobalType(const MCSymbolWasm *Sym) override
.globaltype
This class represents lattice values for constants.
Definition: AllocatorList.h:23
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
This class prints an WebAssembly MCInst to wasm file syntax.
Target specific streamer interface.
Definition: MCStreamer.h:85
const wasm::WasmGlobalType & getGlobalType() const
Definition: MCSymbolWasm.h:95
static void printTypes(formatted_raw_ostream &OS, ArrayRef< wasm::ValType > Types)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
std::string signatureToString(const wasm::WasmSignature *Sig)
SmallVector< ValType, 4 > Params
Definition: Wasm.h:355
bool isGlobal() const
Definition: MCSymbolWasm.h:44
void emitIndIdx(const MCExpr *Value) override
.indidx
const wasm::WasmSignature * getSignature() const
Definition: MCSymbolWasm.h:92
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override
.import_name
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:130
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
Streaming machine code generation interface.
Definition: MCStreamer.h:190
void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override
.import_module
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This file provides WebAssembly-specific target descriptions.
std::string typeListToString(ArrayRef< wasm::ValType > List)
void emitIndIdx(const MCExpr *Value) override
.indidx
WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
void emitLocal(ArrayRef< wasm::ValType > Types) override
.local
size_t size() const
Definition: SmallVector.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This file declares WebAssembly-specific target streamer classes.
void emitLocal(ArrayRef< wasm::ValType > Types) override
.local
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
MCStreamer & Streamer
Definition: MCStreamer.h:87
void EmitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:145
void emitFunctionType(const MCSymbolWasm *Sym) override
.functype
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
void emitEventType(const MCSymbolWasm *Sym) override
.eventtype
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:204
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
const char * typeToString(wasm::ValType Ty)
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143
bool isEvent() const
Definition: MCSymbolWasm.h:46