LLVM 22.0.0git
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"
23using namespace llvm;
24
26 : MCTargetStreamer(S) {}
27
30}
31
35
38
41 bool First = true;
42 for (auto Type : Types) {
43 if (First)
44 First = false;
45 else
46 OS << ", ";
48 }
49 OS << '\n';
50}
51
53 if (!Types.empty()) {
54 OS << "\t.local \t";
55 printTypes(OS, Types);
56 }
57}
58
60 assert(Sym->isFunction());
61 OS << "\t.functype\t" << Sym->getName() << " ";
62 OS << WebAssembly::signatureToString(Sym->getSignature());
63 OS << "\n";
64}
65
67 assert(Sym->isGlobal());
68 OS << "\t.globaltype\t" << Sym->getName() << ", "
70 static_cast<wasm::ValType>(Sym->getGlobalType().Type));
71 if (!Sym->getGlobalType().Mutable)
72 OS << ", immutable";
73 OS << '\n';
74}
75
77 assert(Sym->isTable());
78 const wasm::WasmTableType &Type = Sym->getTableType();
79 OS << "\t.tabletype\t" << Sym->getName() << ", "
80 << WebAssembly::typeToString(static_cast<wasm::ValType>(Type.ElemType));
81 bool HasMaximum = Type.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX;
82 if (Type.Limits.Minimum != 0 || HasMaximum) {
83 OS << ", " << Type.Limits.Minimum;
84 if (HasMaximum)
85 OS << ", " << Type.Limits.Maximum;
86 }
87 OS << '\n';
88}
89
91 assert(Sym->isTag());
92 OS << "\t.tagtype\t" << Sym->getName() << " ";
93 OS << WebAssembly::typeListToString(Sym->getSignature()->Params);
94 OS << "\n";
95}
96
98 StringRef ImportModule) {
99 OS << "\t.import_module\t" << Sym->getName() << ", "
100 << ImportModule << '\n';
101}
102
104 StringRef ImportName) {
105 OS << "\t.import_name\t" << Sym->getName() << ", "
106 << ImportName << '\n';
107}
108
110 StringRef ExportName) {
111 OS << "\t.export_name\t" << Sym->getName() << ", "
112 << ExportName << '\n';
113}
114
116 OS << "\t.indidx\t";
118 OS << '\n';
119}
120
123 for (auto Type : Types) {
124 if (Grouped.empty() || Grouped.back().first != Type)
125 Grouped.push_back(std::make_pair(Type, 1));
126 else
127 ++Grouped.back().second;
128 }
129
131 for (auto Pair : Grouped) {
132 Streamer.emitULEB128IntValue(Pair.second);
133 emitValueType(Pair.first);
134 }
135}
136
138 llvm_unreachable(".indidx encoding not yet implemented");
139}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Symbol * Sym
Definition: ELF_riscv.cpp:479
raw_pwrite_stream & OS
This file contains the declaration of the WebAssemblyMCAsmInfo class.
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
static void printTypes(formatted_raw_ostream &OS, ArrayRef< wasm::ValType > Types)
This file declares WebAssembly-specific target streamer classes.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
void printExpr(raw_ostream &, const MCExpr &) const
Definition: MCAsmInfo.cpp:153
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:412
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Streaming machine code generation interface.
Definition: MCStreamer.h:220
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:132
unsigned 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:160
Target specific streamer interface.
Definition: MCStreamer.h:93
MCContext & getContext()
Definition: MCStreamer.h:1117
MCStreamer & Streamer
Definition: MCStreamer.h:95
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:75
void emitIndIdx(const MCExpr *Value) override
.indidx
WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
void emitFunctionType(const MCSymbolWasm *Sym) override
.functype
void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override
.import_name
void emitExportName(const MCSymbolWasm *Sym, StringRef ExportName) override
.export_name
void emitGlobalType(const MCSymbolWasm *Sym) override
.globaltype
void emitTableType(const MCSymbolWasm *Sym) override
.tabletype
void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override
.import_module
void emitLocal(ArrayRef< wasm::ValType > Types) override
.local
void emitTagType(const MCSymbolWasm *Sym) override
.tagtype
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
void emitIndIdx(const MCExpr *Value) override
.indidx
void emitLocal(ArrayRef< wasm::ValType > Types) override
.local
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const char * typeToString(wasm::ValType Type)
std::string signatureToString(const wasm::WasmSignature *Sig)
std::string typeListToString(ArrayRef< wasm::ValType > List)
@ WASM_LIMITS_FLAG_HAS_MAX
Definition: Wasm.h:159
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.