LLVM 20.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
17#include "llvm/MC/MCContext.h"
22using namespace llvm;
23
25 : MCTargetStreamer(S) {}
26
29}
30
34
37
40 bool First = true;
41 for (auto Type : Types) {
42 if (First)
43 First = false;
44 else
45 OS << ", ";
47 }
48 OS << '\n';
49}
50
52 if (!Types.empty()) {
53 OS << "\t.local \t";
54 printTypes(OS, Types);
55 }
56}
57
59 assert(Sym->isFunction());
60 OS << "\t.functype\t" << Sym->getName() << " ";
61 OS << WebAssembly::signatureToString(Sym->getSignature());
62 OS << "\n";
63}
64
66 assert(Sym->isGlobal());
67 OS << "\t.globaltype\t" << Sym->getName() << ", "
69 static_cast<wasm::ValType>(Sym->getGlobalType().Type));
70 if (!Sym->getGlobalType().Mutable)
71 OS << ", immutable";
72 OS << '\n';
73}
74
76 assert(Sym->isTable());
77 const wasm::WasmTableType &Type = Sym->getTableType();
78 OS << "\t.tabletype\t" << Sym->getName() << ", "
79 << WebAssembly::typeToString(static_cast<wasm::ValType>(Type.ElemType));
80 bool HasMaximum = Type.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX;
81 if (Type.Limits.Minimum != 0 || HasMaximum) {
82 OS << ", " << Type.Limits.Minimum;
83 if (HasMaximum)
84 OS << ", " << Type.Limits.Maximum;
85 }
86 OS << '\n';
87}
88
90 assert(Sym->isTag());
91 OS << "\t.tagtype\t" << Sym->getName() << " ";
92 OS << WebAssembly::typeListToString(Sym->getSignature()->Params);
93 OS << "\n";
94}
95
97 StringRef ImportModule) {
98 OS << "\t.import_module\t" << Sym->getName() << ", "
99 << ImportModule << '\n';
100}
101
103 StringRef ImportName) {
104 OS << "\t.import_name\t" << Sym->getName() << ", "
105 << ImportName << '\n';
106}
107
109 StringRef ExportName) {
110 OS << "\t.export_name\t" << Sym->getName() << ", "
111 << ExportName << '\n';
112}
113
115 OS << "\t.indidx \t" << *Value << '\n';
116}
117
120 for (auto Type : Types) {
121 if (Grouped.empty() || Grouped.back().first != Type)
122 Grouped.push_back(std::make_pair(Type, 1));
123 else
124 ++Grouped.back().second;
125 }
126
128 for (auto Pair : Grouped) {
129 Streamer.emitULEB128IntValue(Pair.second);
130 emitValueType(Pair.first);
131 }
132}
133
135 llvm_unreachable(".indidx encoding not yet implemented");
136}
Symbol * Sym
Definition: ELF_riscv.cpp:479
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
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
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:213
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:133
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:161
Target specific streamer interface.
Definition: MCStreamer.h:94
MCStreamer & Streamer
Definition: MCStreamer.h:96
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
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:74
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:157
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.