LLVM 19.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"
25using namespace llvm;
26
28 : MCTargetStreamer(S) {}
29
31 Streamer.emitIntValue(uint8_t(Type), 1);
32}
33
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
62 assert(Sym->isFunction());
63 OS << "\t.functype\t" << Sym->getName() << " ";
64 OS << WebAssembly::signatureToString(Sym->getSignature());
65 OS << "\n";
66}
67
69 assert(Sym->isGlobal());
70 OS << "\t.globaltype\t" << Sym->getName() << ", "
72 static_cast<wasm::ValType>(Sym->getGlobalType().Type));
73 if (!Sym->getGlobalType().Mutable)
74 OS << ", immutable";
75 OS << '\n';
76}
77
79 assert(Sym->isTable());
80 const wasm::WasmTableType &Type = Sym->getTableType();
81 OS << "\t.tabletype\t" << Sym->getName() << ", "
82 << WebAssembly::typeToString(static_cast<wasm::ValType>(Type.ElemType));
83 bool HasMaximum = Type.Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX;
84 if (Type.Limits.Minimum != 0 || HasMaximum) {
85 OS << ", " << Type.Limits.Minimum;
86 if (HasMaximum)
87 OS << ", " << Type.Limits.Maximum;
88 }
89 OS << '\n';
90}
91
93 assert(Sym->isTag());
94 OS << "\t.tagtype\t" << Sym->getName() << " ";
95 OS << WebAssembly::typeListToString(Sym->getSignature()->Params);
96 OS << "\n";
97}
98
100 StringRef ImportModule) {
101 OS << "\t.import_module\t" << Sym->getName() << ", "
102 << ImportModule << '\n';
103}
104
106 StringRef ImportName) {
107 OS << "\t.import_name\t" << Sym->getName() << ", "
108 << ImportName << '\n';
109}
110
112 StringRef ExportName) {
113 OS << "\t.export_name\t" << Sym->getName() << ", "
114 << ExportName << '\n';
115}
116
118 OS << "\t.indidx \t" << *Value << '\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}
Symbol * Sym
Definition: ELF_riscv.cpp:479
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file provides WebAssembly-specific target descriptions.
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:94
size_t size() const
Definition: SmallVector.h:91
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:149
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.