LLVM 17.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};
52
53struct Table {
54 TableType ElemType;
57};
58
59struct Export {
61 ExportKind Kind;
63};
64
65struct InitExpr {
68 union {
71 };
72};
73
79 std::vector<uint32_t> Functions;
80};
81
82struct Global {
85 bool Mutable;
87};
88
89struct Import {
90 Import() {}
93 ExportKind Kind;
94 union {
100 };
101};
102
103struct LocalDecl {
106};
107
108struct Function {
110 std::vector<LocalDecl> Locals;
112};
113
115 RelocType Type;
117 // TODO(wvo): this would strictly be better as Hex64, but that will change
118 // all existing obj2yaml output.
119 yaml::Hex32 Offset;
120 int64_t Addend;
121};
122
129};
130
131struct NameEntry {
134};
135
137 std::string Name;
138 std::string Version;
139};
140
142 FeaturePolicyPrefix Prefix;
143 std::string Name;
144};
145
150 SegmentFlags Flags;
151};
152
153struct Signature {
155 SignatureForm Form = wasm::WASM_TYPE_FUNC;
156 std::vector<ValueType> ParamTypes;
157 std::vector<ValueType> ReturnTypes;
158};
159
163 SymbolKind Kind;
164 SymbolFlags Flags;
165 union {
168 };
169};
170
174};
175
177 ComdatKind Kind;
179};
180
181struct Comdat {
183 std::vector<ComdatEntry> Entries;
184};
185
186struct Section {
187 explicit Section(SectionType SecType) : Type(SecType) {}
188 virtual ~Section();
189
190 SectionType Type;
191 std::vector<Relocation> Relocations;
192};
193
196 : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
197
198 static bool classof(const Section *S) {
199 return S->Type == wasm::WASM_SEC_CUSTOM;
200 }
201
204};
205
209 SymbolFlags Flags;
210};
211
214 SymbolFlags Flags;
215};
216
218 DylinkSection() : CustomSection("dylink.0") {}
219
220 static bool classof(const Section *S) {
221 auto C = dyn_cast<CustomSection>(S);
222 return C && C->Name == "dylink.0";
223 }
224
229 std::vector<StringRef> Needed;
230 std::vector<DylinkImportInfo> ImportInfo;
231 std::vector<DylinkExportInfo> ExportInfo;
232};
233
236
237 static bool classof(const Section *S) {
238 auto C = dyn_cast<CustomSection>(S);
239 return C && C->Name == "name";
240 }
241
242 std::vector<NameEntry> FunctionNames;
243 std::vector<NameEntry> GlobalNames;
244 std::vector<NameEntry> DataSegmentNames;
245};
246
249
250 static bool classof(const Section *S) {
251 auto C = dyn_cast<CustomSection>(S);
252 return C && C->Name == "linking";
253 }
254
256 std::vector<SymbolInfo> SymbolTable;
257 std::vector<SegmentInfo> SegmentInfos;
258 std::vector<InitFunction> InitFunctions;
259 std::vector<Comdat> Comdats;
260};
261
263 ProducersSection() : CustomSection("producers") {}
264
265 static bool classof(const Section *S) {
266 auto C = dyn_cast<CustomSection>(S);
267 return C && C->Name == "producers";
268 }
269
270 std::vector<ProducerEntry> Languages;
271 std::vector<ProducerEntry> Tools;
272 std::vector<ProducerEntry> SDKs;
273};
274
276 TargetFeaturesSection() : CustomSection("target_features") {}
277
278 static bool classof(const Section *S) {
279 auto C = dyn_cast<CustomSection>(S);
280 return C && C->Name == "target_features";
281 }
282
283 std::vector<FeatureEntry> Features;
284};
285
287 TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
288
289 static bool classof(const Section *S) {
290 return S->Type == wasm::WASM_SEC_TYPE;
291 }
292
293 std::vector<Signature> Signatures;
294};
295
297 ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
298
299 static bool classof(const Section *S) {
300 return S->Type == wasm::WASM_SEC_IMPORT;
301 }
302
303 std::vector<Import> Imports;
304};
305
307 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
308
309 static bool classof(const Section *S) {
310 return S->Type == wasm::WASM_SEC_FUNCTION;
311 }
312
313 std::vector<uint32_t> FunctionTypes;
314};
315
317 TableSection() : Section(wasm::WASM_SEC_TABLE) {}
318
319 static bool classof(const Section *S) {
320 return S->Type == wasm::WASM_SEC_TABLE;
321 }
322
323 std::vector<Table> Tables;
324};
325
327 MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
328
329 static bool classof(const Section *S) {
330 return S->Type == wasm::WASM_SEC_MEMORY;
331 }
332
333 std::vector<Limits> Memories;
334};
335
337 TagSection() : Section(wasm::WASM_SEC_TAG) {}
338
339 static bool classof(const Section *S) {
340 return S->Type == wasm::WASM_SEC_TAG;
341 }
342
343 std::vector<uint32_t> TagTypes;
344};
345
347 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
348
349 static bool classof(const Section *S) {
350 return S->Type == wasm::WASM_SEC_GLOBAL;
351 }
352
353 std::vector<Global> Globals;
354};
355
357 ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
358
359 static bool classof(const Section *S) {
360 return S->Type == wasm::WASM_SEC_EXPORT;
361 }
362
363 std::vector<Export> Exports;
364};
365
367 StartSection() : Section(wasm::WASM_SEC_START) {}
368
369 static bool classof(const Section *S) {
370 return S->Type == wasm::WASM_SEC_START;
371 }
372
374};
375
377 ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
378
379 static bool classof(const Section *S) {
380 return S->Type == wasm::WASM_SEC_ELEM;
381 }
382
383 std::vector<ElemSegment> Segments;
384};
385
387 CodeSection() : Section(wasm::WASM_SEC_CODE) {}
388
389 static bool classof(const Section *S) {
390 return S->Type == wasm::WASM_SEC_CODE;
391 }
392
393 std::vector<Function> Functions;
394};
395
397 DataSection() : Section(wasm::WASM_SEC_DATA) {}
398
399 static bool classof(const Section *S) {
400 return S->Type == wasm::WASM_SEC_DATA;
401 }
402
403 std::vector<DataSegment> Segments;
404};
405
407 DataCountSection() : Section(wasm::WASM_SEC_DATACOUNT) {}
408
409 static bool classof(const Section *S) {
410 return S->Type == wasm::WASM_SEC_DATACOUNT;
411 }
412
414};
415
416struct Object {
418 std::vector<std::unique_ptr<Section>> Sections;
419};
420
421} // end namespace WasmYAML
422} // end namespace llvm
423
424LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
426LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
447
448namespace llvm {
449namespace yaml {
450
451template <> struct MappingTraits<WasmYAML::FileHeader> {
452 static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
453};
454
455template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
456 static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
457};
458
459template <> struct MappingTraits<WasmYAML::Object> {
460 static void mapping(IO &IO, WasmYAML::Object &Object);
461};
462
463template <> struct MappingTraits<WasmYAML::Import> {
464 static void mapping(IO &IO, WasmYAML::Import &Import);
465};
466
467template <> struct MappingTraits<WasmYAML::Export> {
468 static void mapping(IO &IO, WasmYAML::Export &Export);
469};
470
471template <> struct MappingTraits<WasmYAML::Global> {
472 static void mapping(IO &IO, WasmYAML::Global &Global);
473};
474
475template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
476 static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
477};
478
479template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
480 static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
481};
482
483template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> {
484 static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind);
485};
486
487template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
488 static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
489};
490
491template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
492 static void enumeration(IO &IO, WasmYAML::SectionType &Type);
493};
494
495template <> struct MappingTraits<WasmYAML::Signature> {
496 static void mapping(IO &IO, WasmYAML::Signature &Signature);
497};
498
499template <> struct MappingTraits<WasmYAML::Table> {
500 static void mapping(IO &IO, WasmYAML::Table &Table);
501};
502
503template <> struct MappingTraits<WasmYAML::Limits> {
504 static void mapping(IO &IO, WasmYAML::Limits &Limits);
505};
506
507template <> struct MappingTraits<WasmYAML::Function> {
508 static void mapping(IO &IO, WasmYAML::Function &Function);
509};
510
511template <> struct MappingTraits<WasmYAML::Relocation> {
512 static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
513};
514
515template <> struct MappingTraits<WasmYAML::NameEntry> {
516 static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
517};
518
519template <> struct MappingTraits<WasmYAML::ProducerEntry> {
520 static void mapping(IO &IO, WasmYAML::ProducerEntry &ProducerEntry);
521};
522
523template <> struct ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix> {
524 static void enumeration(IO &IO, WasmYAML::FeaturePolicyPrefix &Prefix);
525};
526
527template <> struct MappingTraits<WasmYAML::FeatureEntry> {
528 static void mapping(IO &IO, WasmYAML::FeatureEntry &FeatureEntry);
529};
530
531template <> struct MappingTraits<WasmYAML::SegmentInfo> {
532 static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
533};
534
535template <> struct MappingTraits<WasmYAML::LocalDecl> {
536 static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
537};
538
539template <> struct MappingTraits<WasmYAML::InitExpr> {
540 static void mapping(IO &IO, WasmYAML::InitExpr &Expr);
541};
542
543template <> struct MappingTraits<WasmYAML::DataSegment> {
544 static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
545};
546
547template <> struct MappingTraits<WasmYAML::ElemSegment> {
548 static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
549};
550
551template <> struct MappingTraits<WasmYAML::SymbolInfo> {
552 static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
553};
554
555template <> struct MappingTraits<WasmYAML::InitFunction> {
556 static void mapping(IO &IO, WasmYAML::InitFunction &Init);
557};
558
559template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> {
560 static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind);
561};
562
563template <> struct MappingTraits<WasmYAML::ComdatEntry> {
564 static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry);
565};
566
567template <> struct MappingTraits<WasmYAML::Comdat> {
568 static void mapping(IO &IO, WasmYAML::Comdat &Comdat);
569};
570
571template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
572 static void enumeration(IO &IO, WasmYAML::ValueType &Type);
573};
574
575template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
576 static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
577};
578
579template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
580 static void enumeration(IO &IO, WasmYAML::TableType &Type);
581};
582
583template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
584 static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
585};
586
587template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
588 static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
589};
590
591template <> struct MappingTraits<WasmYAML::DylinkImportInfo> {
592 static void mapping(IO &IO, WasmYAML::DylinkImportInfo &Info);
593};
594
595template <> struct MappingTraits<WasmYAML::DylinkExportInfo> {
596 static void mapping(IO &IO, WasmYAML::DylinkExportInfo &Info);
597};
598
599} // end namespace yaml
600} // end namespace llvm
601
602#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: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
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ WASM_SEC_CODE
Definition: Wasm.h:252
@ WASM_SEC_MEMORY
Definition: Wasm.h:247
@ WASM_SEC_IMPORT
Definition: Wasm.h:244
@ WASM_SEC_EXPORT
Definition: Wasm.h:249
@ WASM_SEC_DATACOUNT
Definition: Wasm.h:254
@ WASM_SEC_CUSTOM
Definition: Wasm.h:242
@ WASM_SEC_FUNCTION
Definition: Wasm.h:245
@ WASM_SEC_ELEM
Definition: Wasm.h:251
@ WASM_SEC_START
Definition: Wasm.h:250
@ WASM_SEC_TABLE
Definition: Wasm.h:246
@ WASM_SEC_TYPE
Definition: Wasm.h:243
@ WASM_SEC_TAG
Definition: Wasm.h:255
@ WASM_SEC_GLOBAL
Definition: Wasm.h:248
@ WASM_SEC_DATA
Definition: Wasm.h:253
@ WASM_TYPE_FUNC
Definition: Wasm.h:268
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.
Definition: BitVector.h:858
std::vector< Function > Functions
Definition: WasmYAML.h:393
static bool classof(const Section *S)
Definition: WasmYAML.h:389
std::vector< ComdatEntry > Entries
Definition: WasmYAML.h:183
static bool classof(const Section *S)
Definition: WasmYAML.h:198
yaml::BinaryRef Payload
Definition: WasmYAML.h:203
CustomSection(StringRef Name)
Definition: WasmYAML.h:195
static bool classof(const Section *S)
Definition: WasmYAML.h:409
std::vector< DataSegment > Segments
Definition: WasmYAML.h:403
static bool classof(const Section *S)
Definition: WasmYAML.h:399
yaml::BinaryRef Content
Definition: WasmYAML.h:128
std::vector< ElemSegment > Segments
Definition: WasmYAML.h:383
static bool classof(const Section *S)
Definition: WasmYAML.h:379
std::vector< uint32_t > Functions
Definition: WasmYAML.h:79
static bool classof(const Section *S)
Definition: WasmYAML.h:359
std::vector< Export > Exports
Definition: WasmYAML.h:363
FeaturePolicyPrefix Prefix
Definition: WasmYAML.h:142
std::vector< uint32_t > FunctionTypes
Definition: WasmYAML.h:313
static bool classof(const Section *S)
Definition: WasmYAML.h:309
std::vector< LocalDecl > Locals
Definition: WasmYAML.h:110
yaml::BinaryRef Body
Definition: WasmYAML.h:111
static bool classof(const Section *S)
Definition: WasmYAML.h:349
std::vector< Global > Globals
Definition: WasmYAML.h:353
std::vector< Import > Imports
Definition: WasmYAML.h:303
static bool classof(const Section *S)
Definition: WasmYAML.h:299
wasm::WasmInitExprMVP Inst
Definition: WasmYAML.h:69
yaml::BinaryRef Body
Definition: WasmYAML.h:70
yaml::Hex32 Minimum
Definition: WasmYAML.h:49
LimitFlags Flags
Definition: WasmYAML.h:48
yaml::Hex32 Maximum
Definition: WasmYAML.h:50
std::vector< InitFunction > InitFunctions
Definition: WasmYAML.h:258
std::vector< SymbolInfo > SymbolTable
Definition: WasmYAML.h:256
std::vector< SegmentInfo > SegmentInfos
Definition: WasmYAML.h:257
static bool classof(const Section *S)
Definition: WasmYAML.h:250
std::vector< Comdat > Comdats
Definition: WasmYAML.h:259
std::vector< Limits > Memories
Definition: WasmYAML.h:333
static bool classof(const Section *S)
Definition: WasmYAML.h:329
std::vector< NameEntry > DataSegmentNames
Definition: WasmYAML.h:244
static bool classof(const Section *S)
Definition: WasmYAML.h:237
std::vector< NameEntry > FunctionNames
Definition: WasmYAML.h:242
std::vector< NameEntry > GlobalNames
Definition: WasmYAML.h:243
std::vector< std::unique_ptr< Section > > Sections
Definition: WasmYAML.h:418
static bool classof(const Section *S)
Definition: WasmYAML.h:265
std::vector< ProducerEntry > Tools
Definition: WasmYAML.h:271
std::vector< ProducerEntry > Languages
Definition: WasmYAML.h:270
std::vector< ProducerEntry > SDKs
Definition: WasmYAML.h:272
Section(SectionType SecType)
Definition: WasmYAML.h:187
std::vector< Relocation > Relocations
Definition: WasmYAML.h:191
std::vector< ValueType > ReturnTypes
Definition: WasmYAML.h:157
std::vector< ValueType > ParamTypes
Definition: WasmYAML.h:156
static bool classof(const Section *S)
Definition: WasmYAML.h:369
wasm::WasmDataReference DataRef
Definition: WasmYAML.h:167
static bool classof(const Section *S)
Definition: WasmYAML.h:319
std::vector< Table > Tables
Definition: WasmYAML.h:323
TableType ElemType
Definition: WasmYAML.h:54
std::vector< uint32_t > TagTypes
Definition: WasmYAML.h:343
static bool classof(const Section *S)
Definition: WasmYAML.h:339
std::vector< FeatureEntry > Features
Definition: WasmYAML.h:283
static bool classof(const Section *S)
Definition: WasmYAML.h:278
static bool classof(const Section *S)
Definition: WasmYAML.h:289
std::vector< Signature > Signatures
Definition: WasmYAML.h:293