LLVM 22.0.0git
WasmYAML.h
Go to the documentation of this file.
1//===- WasmYAML.h - Wasm YAMLIO implementation ------------------*- C++ -*-===//
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 declares classes for handling the YAML representation
11/// of wasm binaries.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_OBJECTYAML_WASMYAML_H
16#define LLVM_OBJECTYAML_WASMYAML_H
17
18#include "llvm/ADT/StringRef.h"
22#include <cstdint>
23#include <memory>
24#include <vector>
25
26namespace llvm {
27namespace WasmYAML {
28
41LLVM_YAML_STRONG_TYPEDEF(uint32_t, FeaturePolicyPrefix)
42
43struct FileHeader {
44 yaml::Hex32 Version;
45};
46
47struct Limits {
48 LimitFlags Flags;
49 yaml::Hex32 Minimum;
50 yaml::Hex32 Maximum;
51 yaml::Hex32 PageSize;
52};
53
54struct Table {
55 TableType ElemType;
58};
59
60struct Export {
62 ExportKind Kind;
64};
65
66struct InitExpr {
69 union {
72 };
73};
74
80 std::vector<uint32_t> Functions;
81};
82
83struct Global {
86 bool Mutable;
88};
89
90struct Import {
91 Import() {}
94 ExportKind Kind;
95 union {
101 };
102};
103
104struct LocalDecl {
107};
108
109struct Function {
111 std::vector<LocalDecl> Locals;
113};
114
116 RelocType Type;
118 // TODO(wvo): this would strictly be better as Hex64, but that will change
119 // all existing obj2yaml output.
120 yaml::Hex32 Offset;
121 int64_t Addend;
122};
123
130};
131
132struct NameEntry {
135};
136
138 std::string Name;
139 std::string Version;
140};
141
143 FeaturePolicyPrefix Prefix;
144 std::string Name;
145};
146
151 SegmentFlags Flags;
152};
153
154struct Signature {
156 SignatureForm Form = wasm::WASM_TYPE_FUNC;
157 std::vector<ValueType> ParamTypes;
158 std::vector<ValueType> ReturnTypes;
159};
160
164 SymbolKind Kind;
165 SymbolFlags Flags;
166 union {
169 };
170};
171
175};
176
178 ComdatKind Kind;
180};
181
182struct Comdat {
184 std::vector<ComdatEntry> Entries;
185};
186
187struct Section {
188 explicit Section(SectionType SecType) : Type(SecType) {}
189 virtual ~Section();
190
191 SectionType Type;
192 std::vector<Relocation> Relocations;
193 std::optional<uint8_t> HeaderSecSizeEncodingLen;
194};
195
198 : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
199
200 static bool classof(const Section *S) {
201 return S->Type == wasm::WASM_SEC_CUSTOM;
202 }
203
206};
207
211 SymbolFlags Flags;
212};
213
216 SymbolFlags Flags;
217};
218
220 DylinkSection() : CustomSection("dylink.0") {}
221
222 static bool classof(const Section *S) {
223 auto C = dyn_cast<CustomSection>(S);
224 return C && C->Name == "dylink.0";
225 }
226
231 std::vector<StringRef> Needed;
232 std::vector<DylinkImportInfo> ImportInfo;
233 std::vector<DylinkExportInfo> ExportInfo;
234 std::vector<StringRef> RuntimePath;
235};
236
239
240 static bool classof(const Section *S) {
241 auto C = dyn_cast<CustomSection>(S);
242 return C && C->Name == "name";
243 }
244
245 std::vector<NameEntry> FunctionNames;
246 std::vector<NameEntry> GlobalNames;
247 std::vector<NameEntry> DataSegmentNames;
248};
249
252
253 static bool classof(const Section *S) {
254 auto C = dyn_cast<CustomSection>(S);
255 return C && C->Name == "linking";
256 }
257
259 std::vector<SymbolInfo> SymbolTable;
260 std::vector<SegmentInfo> SegmentInfos;
261 std::vector<InitFunction> InitFunctions;
262 std::vector<Comdat> Comdats;
263};
264
266 ProducersSection() : CustomSection("producers") {}
267
268 static bool classof(const Section *S) {
269 auto C = dyn_cast<CustomSection>(S);
270 return C && C->Name == "producers";
271 }
272
273 std::vector<ProducerEntry> Languages;
274 std::vector<ProducerEntry> Tools;
275 std::vector<ProducerEntry> SDKs;
276};
277
279 TargetFeaturesSection() : CustomSection("target_features") {}
280
281 static bool classof(const Section *S) {
282 auto C = dyn_cast<CustomSection>(S);
283 return C && C->Name == "target_features";
284 }
285
286 std::vector<FeatureEntry> Features;
287};
288
290 TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
291
292 static bool classof(const Section *S) {
293 return S->Type == wasm::WASM_SEC_TYPE;
294 }
295
296 std::vector<Signature> Signatures;
297};
298
300 ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
301
302 static bool classof(const Section *S) {
303 return S->Type == wasm::WASM_SEC_IMPORT;
304 }
305
306 std::vector<Import> Imports;
307};
308
310 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
311
312 static bool classof(const Section *S) {
313 return S->Type == wasm::WASM_SEC_FUNCTION;
314 }
315
316 std::vector<uint32_t> FunctionTypes;
317};
318
320 TableSection() : Section(wasm::WASM_SEC_TABLE) {}
321
322 static bool classof(const Section *S) {
323 return S->Type == wasm::WASM_SEC_TABLE;
324 }
325
326 std::vector<Table> Tables;
327};
328
330 MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
331
332 static bool classof(const Section *S) {
333 return S->Type == wasm::WASM_SEC_MEMORY;
334 }
335
336 std::vector<Limits> Memories;
337};
338
340 TagSection() : Section(wasm::WASM_SEC_TAG) {}
341
342 static bool classof(const Section *S) {
343 return S->Type == wasm::WASM_SEC_TAG;
344 }
345
346 std::vector<uint32_t> TagTypes;
347};
348
350 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
351
352 static bool classof(const Section *S) {
353 return S->Type == wasm::WASM_SEC_GLOBAL;
354 }
355
356 std::vector<Global> Globals;
357};
358
360 ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
361
362 static bool classof(const Section *S) {
363 return S->Type == wasm::WASM_SEC_EXPORT;
364 }
365
366 std::vector<Export> Exports;
367};
368
370 StartSection() : Section(wasm::WASM_SEC_START) {}
371
372 static bool classof(const Section *S) {
373 return S->Type == wasm::WASM_SEC_START;
374 }
375
377};
378
380 ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
381
382 static bool classof(const Section *S) {
383 return S->Type == wasm::WASM_SEC_ELEM;
384 }
385
386 std::vector<ElemSegment> Segments;
387};
388
390 CodeSection() : Section(wasm::WASM_SEC_CODE) {}
391
392 static bool classof(const Section *S) {
393 return S->Type == wasm::WASM_SEC_CODE;
394 }
395
396 std::vector<Function> Functions;
397};
398
400 DataSection() : Section(wasm::WASM_SEC_DATA) {}
401
402 static bool classof(const Section *S) {
403 return S->Type == wasm::WASM_SEC_DATA;
404 }
405
406 std::vector<DataSegment> Segments;
407};
408
410 DataCountSection() : Section(wasm::WASM_SEC_DATACOUNT) {}
411
412 static bool classof(const Section *S) {
413 return S->Type == wasm::WASM_SEC_DATACOUNT;
414 }
415
417};
418
419struct Object {
421 std::vector<std::unique_ptr<Section>> Sections;
422};
423
424} // end namespace WasmYAML
425} // end namespace llvm
426
427LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
429LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
450
451namespace llvm {
452namespace yaml {
453
454template <> struct MappingTraits<WasmYAML::FileHeader> {
455 static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
456};
457
458template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
459 static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
460};
461
462template <> struct MappingTraits<WasmYAML::Object> {
463 static void mapping(IO &IO, WasmYAML::Object &Object);
464};
465
466template <> struct MappingTraits<WasmYAML::Import> {
467 static void mapping(IO &IO, WasmYAML::Import &Import);
468};
469
470template <> struct MappingTraits<WasmYAML::Export> {
471 static void mapping(IO &IO, WasmYAML::Export &Export);
472};
473
474template <> struct MappingTraits<WasmYAML::Global> {
475 static void mapping(IO &IO, WasmYAML::Global &Global);
476};
477
478template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
479 static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
480};
481
482template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
483 static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
484};
485
486template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> {
487 static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind);
488};
489
490template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
491 static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
492};
493
494template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
495 static void enumeration(IO &IO, WasmYAML::SectionType &Type);
496};
497
498template <> struct MappingTraits<WasmYAML::Signature> {
499 static void mapping(IO &IO, WasmYAML::Signature &Signature);
500};
501
502template <> struct MappingTraits<WasmYAML::Table> {
503 static void mapping(IO &IO, WasmYAML::Table &Table);
504};
505
506template <> struct MappingTraits<WasmYAML::Limits> {
507 static void mapping(IO &IO, WasmYAML::Limits &Limits);
508};
509
510template <> struct MappingTraits<WasmYAML::Function> {
511 static void mapping(IO &IO, WasmYAML::Function &Function);
512};
513
514template <> struct MappingTraits<WasmYAML::Relocation> {
515 static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
516};
517
518template <> struct MappingTraits<WasmYAML::NameEntry> {
519 static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
520};
521
522template <> struct MappingTraits<WasmYAML::ProducerEntry> {
523 static void mapping(IO &IO, WasmYAML::ProducerEntry &ProducerEntry);
524};
525
526template <> struct ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix> {
527 static void enumeration(IO &IO, WasmYAML::FeaturePolicyPrefix &Prefix);
528};
529
530template <> struct MappingTraits<WasmYAML::FeatureEntry> {
531 static void mapping(IO &IO, WasmYAML::FeatureEntry &FeatureEntry);
532};
533
534template <> struct MappingTraits<WasmYAML::SegmentInfo> {
535 static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
536};
537
538template <> struct MappingTraits<WasmYAML::LocalDecl> {
539 static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
540};
541
542template <> struct MappingTraits<WasmYAML::InitExpr> {
543 static void mapping(IO &IO, WasmYAML::InitExpr &Expr);
544};
545
546template <> struct MappingTraits<WasmYAML::DataSegment> {
547 static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
548};
549
550template <> struct MappingTraits<WasmYAML::ElemSegment> {
551 static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
552};
553
554template <> struct MappingTraits<WasmYAML::SymbolInfo> {
555 static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
556};
557
558template <> struct MappingTraits<WasmYAML::InitFunction> {
559 static void mapping(IO &IO, WasmYAML::InitFunction &Init);
560};
561
562template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> {
563 static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind);
564};
565
566template <> struct MappingTraits<WasmYAML::ComdatEntry> {
567 static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry);
568};
569
570template <> struct MappingTraits<WasmYAML::Comdat> {
571 static void mapping(IO &IO, WasmYAML::Comdat &Comdat);
572};
573
574template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
575 static void enumeration(IO &IO, WasmYAML::ValueType &Type);
576};
577
578template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
579 static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
580};
581
582template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
583 static void enumeration(IO &IO, WasmYAML::TableType &Type);
584};
585
586template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
587 static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
588};
589
590template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
591 static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
592};
593
594template <> struct MappingTraits<WasmYAML::DylinkImportInfo> {
595 static void mapping(IO &IO, WasmYAML::DylinkImportInfo &Info);
596};
597
598template <> struct MappingTraits<WasmYAML::DylinkExportInfo> {
599 static void mapping(IO &IO, WasmYAML::DylinkExportInfo &Info);
600};
601
602} // end namespace yaml
603} // end namespace llvm
604
605#endif // LLVM_OBJECTYAML_WASMYAML_H
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
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
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:64
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ WASM_TYPE_FUNC
Definition: Wasm.h:75
@ WASM_SEC_CODE
Definition: Wasm.h:47
@ WASM_SEC_MEMORY
Definition: Wasm.h:42
@ WASM_SEC_IMPORT
Definition: Wasm.h:39
@ WASM_SEC_EXPORT
Definition: Wasm.h:44
@ WASM_SEC_DATACOUNT
Definition: Wasm.h:49
@ WASM_SEC_CUSTOM
Definition: Wasm.h:37
@ WASM_SEC_FUNCTION
Definition: Wasm.h:40
@ WASM_SEC_ELEM
Definition: Wasm.h:46
@ WASM_SEC_START
Definition: Wasm.h:45
@ WASM_SEC_TABLE
Definition: Wasm.h:41
@ WASM_SEC_TYPE
Definition: Wasm.h:38
@ WASM_SEC_TAG
Definition: Wasm.h:50
@ WASM_SEC_GLOBAL
Definition: Wasm.h:43
@ WASM_SEC_DATA
Definition: Wasm.h:48
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Export
Export information to summary.
@ Import
Import information from summary.
@ Global
Append to llvm.global_dtors.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
std::vector< Function > Functions
Definition: WasmYAML.h:396
static bool classof(const Section *S)
Definition: WasmYAML.h:392
std::vector< ComdatEntry > Entries
Definition: WasmYAML.h:184
static bool classof(const Section *S)
Definition: WasmYAML.h:200
yaml::BinaryRef Payload
Definition: WasmYAML.h:205
CustomSection(StringRef Name)
Definition: WasmYAML.h:197
static bool classof(const Section *S)
Definition: WasmYAML.h:412
std::vector< DataSegment > Segments
Definition: WasmYAML.h:406
static bool classof(const Section *S)
Definition: WasmYAML.h:402
yaml::BinaryRef Content
Definition: WasmYAML.h:129
std::vector< ElemSegment > Segments
Definition: WasmYAML.h:386
static bool classof(const Section *S)
Definition: WasmYAML.h:382
std::vector< uint32_t > Functions
Definition: WasmYAML.h:80
static bool classof(const Section *S)
Definition: WasmYAML.h:362
std::vector< Export > Exports
Definition: WasmYAML.h:366
FeaturePolicyPrefix Prefix
Definition: WasmYAML.h:143
std::vector< uint32_t > FunctionTypes
Definition: WasmYAML.h:316
static bool classof(const Section *S)
Definition: WasmYAML.h:312
std::vector< LocalDecl > Locals
Definition: WasmYAML.h:111
yaml::BinaryRef Body
Definition: WasmYAML.h:112
static bool classof(const Section *S)
Definition: WasmYAML.h:352
std::vector< Global > Globals
Definition: WasmYAML.h:356
std::vector< Import > Imports
Definition: WasmYAML.h:306
static bool classof(const Section *S)
Definition: WasmYAML.h:302
wasm::WasmInitExprMVP Inst
Definition: WasmYAML.h:70
yaml::BinaryRef Body
Definition: WasmYAML.h:71
yaml::Hex32 Minimum
Definition: WasmYAML.h:49
yaml::Hex32 PageSize
Definition: WasmYAML.h:51
LimitFlags Flags
Definition: WasmYAML.h:48
yaml::Hex32 Maximum
Definition: WasmYAML.h:50
std::vector< InitFunction > InitFunctions
Definition: WasmYAML.h:261
std::vector< SymbolInfo > SymbolTable
Definition: WasmYAML.h:259
std::vector< SegmentInfo > SegmentInfos
Definition: WasmYAML.h:260
static bool classof(const Section *S)
Definition: WasmYAML.h:253
std::vector< Comdat > Comdats
Definition: WasmYAML.h:262
std::vector< Limits > Memories
Definition: WasmYAML.h:336
static bool classof(const Section *S)
Definition: WasmYAML.h:332
std::vector< NameEntry > DataSegmentNames
Definition: WasmYAML.h:247
static bool classof(const Section *S)
Definition: WasmYAML.h:240
std::vector< NameEntry > FunctionNames
Definition: WasmYAML.h:245
std::vector< NameEntry > GlobalNames
Definition: WasmYAML.h:246
std::vector< std::unique_ptr< Section > > Sections
Definition: WasmYAML.h:421
static bool classof(const Section *S)
Definition: WasmYAML.h:268
std::vector< ProducerEntry > Tools
Definition: WasmYAML.h:274
std::vector< ProducerEntry > Languages
Definition: WasmYAML.h:273
std::vector< ProducerEntry > SDKs
Definition: WasmYAML.h:275
Section(SectionType SecType)
Definition: WasmYAML.h:188
std::optional< uint8_t > HeaderSecSizeEncodingLen
Definition: WasmYAML.h:193
std::vector< Relocation > Relocations
Definition: WasmYAML.h:192
SignatureForm Form
Definition: WasmYAML.h:156
std::vector< ValueType > ReturnTypes
Definition: WasmYAML.h:158
std::vector< ValueType > ParamTypes
Definition: WasmYAML.h:157
static bool classof(const Section *S)
Definition: WasmYAML.h:372
wasm::WasmDataReference DataRef
Definition: WasmYAML.h:168
static bool classof(const Section *S)
Definition: WasmYAML.h:322
std::vector< Table > Tables
Definition: WasmYAML.h:326
TableType ElemType
Definition: WasmYAML.h:55
std::vector< uint32_t > TagTypes
Definition: WasmYAML.h:346
static bool classof(const Section *S)
Definition: WasmYAML.h:342
std::vector< FeatureEntry > Features
Definition: WasmYAML.h:286
static bool classof(const Section *S)
Definition: WasmYAML.h:281
static bool classof(const Section *S)
Definition: WasmYAML.h:292
std::vector< Signature > Signatures
Definition: WasmYAML.h:296