[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / ObjectYAML / WasmYAML.cpp
blob752654ddbbaf14fe049694ea6d8b76240f0c7062
1 //===- WasmYAML.cpp - Wasm YAMLIO implementation --------------------------===//
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 // This file defines classes for handling the YAML representation of wasm.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ObjectYAML/WasmYAML.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Casting.h"
16 #include "llvm/Support/ErrorHandling.h"
17 #include "llvm/Support/YAMLTraits.h"
19 namespace llvm {
21 namespace WasmYAML {
23 // Declared here rather than in the header to comply with:
24 // http://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers
25 Section::~Section() = default;
27 } // end namespace WasmYAML
29 namespace yaml {
31 void MappingTraits<WasmYAML::FileHeader>::mapping(
32 IO &IO, WasmYAML::FileHeader &FileHdr) {
33 IO.mapRequired("Version", FileHdr.Version);
36 void MappingTraits<WasmYAML::Object>::mapping(IO &IO,
37 WasmYAML::Object &Object) {
38 IO.setContext(&Object);
39 IO.mapTag("!WASM", true);
40 IO.mapRequired("FileHeader", Object.Header);
41 IO.mapOptional("Sections", Object.Sections);
42 IO.setContext(nullptr);
45 static void commonSectionMapping(IO &IO, WasmYAML::Section &Section) {
46 IO.mapRequired("Type", Section.Type);
47 IO.mapOptional("Relocations", Section.Relocations);
50 static void sectionMapping(IO &IO, WasmYAML::DylinkSection &Section) {
51 commonSectionMapping(IO, Section);
52 IO.mapRequired("Name", Section.Name);
53 IO.mapRequired("MemorySize", Section.MemorySize);
54 IO.mapRequired("MemoryAlignment", Section.MemoryAlignment);
55 IO.mapRequired("TableSize", Section.TableSize);
56 IO.mapRequired("TableAlignment", Section.TableAlignment);
57 IO.mapRequired("Needed", Section.Needed);
60 static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) {
61 commonSectionMapping(IO, Section);
62 IO.mapRequired("Name", Section.Name);
63 IO.mapOptional("FunctionNames", Section.FunctionNames);
64 IO.mapOptional("GlobalNames", Section.GlobalNames);
65 IO.mapOptional("DataSegmentNames", Section.DataSegmentNames);
68 static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) {
69 commonSectionMapping(IO, Section);
70 IO.mapRequired("Name", Section.Name);
71 IO.mapRequired("Version", Section.Version);
72 IO.mapOptional("SymbolTable", Section.SymbolTable);
73 IO.mapOptional("SegmentInfo", Section.SegmentInfos);
74 IO.mapOptional("InitFunctions", Section.InitFunctions);
75 IO.mapOptional("Comdats", Section.Comdats);
78 static void sectionMapping(IO &IO, WasmYAML::ProducersSection &Section) {
79 commonSectionMapping(IO, Section);
80 IO.mapRequired("Name", Section.Name);
81 IO.mapOptional("Languages", Section.Languages);
82 IO.mapOptional("Tools", Section.Tools);
83 IO.mapOptional("SDKs", Section.SDKs);
86 static void sectionMapping(IO &IO, WasmYAML::TargetFeaturesSection &Section) {
87 commonSectionMapping(IO, Section);
88 IO.mapRequired("Name", Section.Name);
89 IO.mapRequired("Features", Section.Features);
92 static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) {
93 commonSectionMapping(IO, Section);
94 IO.mapRequired("Name", Section.Name);
95 IO.mapRequired("Payload", Section.Payload);
98 static void sectionMapping(IO &IO, WasmYAML::TypeSection &Section) {
99 commonSectionMapping(IO, Section);
100 IO.mapOptional("Signatures", Section.Signatures);
103 static void sectionMapping(IO &IO, WasmYAML::ImportSection &Section) {
104 commonSectionMapping(IO, Section);
105 IO.mapOptional("Imports", Section.Imports);
108 static void sectionMapping(IO &IO, WasmYAML::FunctionSection &Section) {
109 commonSectionMapping(IO, Section);
110 IO.mapOptional("FunctionTypes", Section.FunctionTypes);
113 static void sectionMapping(IO &IO, WasmYAML::TableSection &Section) {
114 commonSectionMapping(IO, Section);
115 IO.mapOptional("Tables", Section.Tables);
118 static void sectionMapping(IO &IO, WasmYAML::MemorySection &Section) {
119 commonSectionMapping(IO, Section);
120 IO.mapOptional("Memories", Section.Memories);
123 static void sectionMapping(IO &IO, WasmYAML::TagSection &Section) {
124 commonSectionMapping(IO, Section);
125 IO.mapOptional("Tags", Section.Tags);
128 static void sectionMapping(IO &IO, WasmYAML::GlobalSection &Section) {
129 commonSectionMapping(IO, Section);
130 IO.mapOptional("Globals", Section.Globals);
133 static void sectionMapping(IO &IO, WasmYAML::ExportSection &Section) {
134 commonSectionMapping(IO, Section);
135 IO.mapOptional("Exports", Section.Exports);
138 static void sectionMapping(IO &IO, WasmYAML::StartSection &Section) {
139 commonSectionMapping(IO, Section);
140 IO.mapOptional("StartFunction", Section.StartFunction);
143 static void sectionMapping(IO &IO, WasmYAML::ElemSection &Section) {
144 commonSectionMapping(IO, Section);
145 IO.mapOptional("Segments", Section.Segments);
148 static void sectionMapping(IO &IO, WasmYAML::CodeSection &Section) {
149 commonSectionMapping(IO, Section);
150 IO.mapRequired("Functions", Section.Functions);
153 static void sectionMapping(IO &IO, WasmYAML::DataSection &Section) {
154 commonSectionMapping(IO, Section);
155 IO.mapRequired("Segments", Section.Segments);
158 static void sectionMapping(IO &IO, WasmYAML::DataCountSection &Section) {
159 commonSectionMapping(IO, Section);
160 IO.mapRequired("Count", Section.Count);
163 void MappingTraits<std::unique_ptr<WasmYAML::Section>>::mapping(
164 IO &IO, std::unique_ptr<WasmYAML::Section> &Section) {
165 WasmYAML::SectionType SectionType;
166 if (IO.outputting())
167 SectionType = Section->Type;
168 else
169 IO.mapRequired("Type", SectionType);
171 switch (SectionType) {
172 case wasm::WASM_SEC_CUSTOM: {
173 StringRef SectionName;
174 if (IO.outputting()) {
175 auto CustomSection = cast<WasmYAML::CustomSection>(Section.get());
176 SectionName = CustomSection->Name;
177 } else {
178 IO.mapRequired("Name", SectionName);
180 if (SectionName == "dylink") {
181 if (!IO.outputting())
182 Section.reset(new WasmYAML::DylinkSection());
183 sectionMapping(IO, *cast<WasmYAML::DylinkSection>(Section.get()));
184 } else if (SectionName == "linking") {
185 if (!IO.outputting())
186 Section.reset(new WasmYAML::LinkingSection());
187 sectionMapping(IO, *cast<WasmYAML::LinkingSection>(Section.get()));
188 } else if (SectionName == "name") {
189 if (!IO.outputting())
190 Section.reset(new WasmYAML::NameSection());
191 sectionMapping(IO, *cast<WasmYAML::NameSection>(Section.get()));
192 } else if (SectionName == "producers") {
193 if (!IO.outputting())
194 Section.reset(new WasmYAML::ProducersSection());
195 sectionMapping(IO, *cast<WasmYAML::ProducersSection>(Section.get()));
196 } else if (SectionName == "target_features") {
197 if (!IO.outputting())
198 Section.reset(new WasmYAML::TargetFeaturesSection());
199 sectionMapping(IO, *cast<WasmYAML::TargetFeaturesSection>(Section.get()));
200 } else {
201 if (!IO.outputting())
202 Section.reset(new WasmYAML::CustomSection(SectionName));
203 sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get()));
205 break;
207 case wasm::WASM_SEC_TYPE:
208 if (!IO.outputting())
209 Section.reset(new WasmYAML::TypeSection());
210 sectionMapping(IO, *cast<WasmYAML::TypeSection>(Section.get()));
211 break;
212 case wasm::WASM_SEC_IMPORT:
213 if (!IO.outputting())
214 Section.reset(new WasmYAML::ImportSection());
215 sectionMapping(IO, *cast<WasmYAML::ImportSection>(Section.get()));
216 break;
217 case wasm::WASM_SEC_FUNCTION:
218 if (!IO.outputting())
219 Section.reset(new WasmYAML::FunctionSection());
220 sectionMapping(IO, *cast<WasmYAML::FunctionSection>(Section.get()));
221 break;
222 case wasm::WASM_SEC_TABLE:
223 if (!IO.outputting())
224 Section.reset(new WasmYAML::TableSection());
225 sectionMapping(IO, *cast<WasmYAML::TableSection>(Section.get()));
226 break;
227 case wasm::WASM_SEC_MEMORY:
228 if (!IO.outputting())
229 Section.reset(new WasmYAML::MemorySection());
230 sectionMapping(IO, *cast<WasmYAML::MemorySection>(Section.get()));
231 break;
232 case wasm::WASM_SEC_TAG:
233 if (!IO.outputting())
234 Section.reset(new WasmYAML::TagSection());
235 sectionMapping(IO, *cast<WasmYAML::TagSection>(Section.get()));
236 break;
237 case wasm::WASM_SEC_GLOBAL:
238 if (!IO.outputting())
239 Section.reset(new WasmYAML::GlobalSection());
240 sectionMapping(IO, *cast<WasmYAML::GlobalSection>(Section.get()));
241 break;
242 case wasm::WASM_SEC_EXPORT:
243 if (!IO.outputting())
244 Section.reset(new WasmYAML::ExportSection());
245 sectionMapping(IO, *cast<WasmYAML::ExportSection>(Section.get()));
246 break;
247 case wasm::WASM_SEC_START:
248 if (!IO.outputting())
249 Section.reset(new WasmYAML::StartSection());
250 sectionMapping(IO, *cast<WasmYAML::StartSection>(Section.get()));
251 break;
252 case wasm::WASM_SEC_ELEM:
253 if (!IO.outputting())
254 Section.reset(new WasmYAML::ElemSection());
255 sectionMapping(IO, *cast<WasmYAML::ElemSection>(Section.get()));
256 break;
257 case wasm::WASM_SEC_CODE:
258 if (!IO.outputting())
259 Section.reset(new WasmYAML::CodeSection());
260 sectionMapping(IO, *cast<WasmYAML::CodeSection>(Section.get()));
261 break;
262 case wasm::WASM_SEC_DATA:
263 if (!IO.outputting())
264 Section.reset(new WasmYAML::DataSection());
265 sectionMapping(IO, *cast<WasmYAML::DataSection>(Section.get()));
266 break;
267 case wasm::WASM_SEC_DATACOUNT:
268 if (!IO.outputting())
269 Section.reset(new WasmYAML::DataCountSection());
270 sectionMapping(IO, *cast<WasmYAML::DataCountSection>(Section.get()));
271 break;
272 default:
273 llvm_unreachable("Unknown section type");
277 void ScalarEnumerationTraits<WasmYAML::SectionType>::enumeration(
278 IO &IO, WasmYAML::SectionType &Type) {
279 #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_SEC_##X);
280 ECase(CUSTOM);
281 ECase(TYPE);
282 ECase(IMPORT);
283 ECase(FUNCTION);
284 ECase(TABLE);
285 ECase(MEMORY);
286 ECase(GLOBAL);
287 ECase(TAG);
288 ECase(EXPORT);
289 ECase(START);
290 ECase(ELEM);
291 ECase(CODE);
292 ECase(DATA);
293 ECase(DATACOUNT);
294 #undef ECase
297 void MappingTraits<WasmYAML::Signature>::mapping(
298 IO &IO, WasmYAML::Signature &Signature) {
299 IO.mapRequired("Index", Signature.Index);
300 IO.mapRequired("ParamTypes", Signature.ParamTypes);
301 IO.mapRequired("ReturnTypes", Signature.ReturnTypes);
304 void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) {
305 IO.mapRequired("Index", Table.Index);
306 IO.mapRequired("ElemType", Table.ElemType);
307 IO.mapRequired("Limits", Table.TableLimits);
310 void MappingTraits<WasmYAML::Function>::mapping(IO &IO,
311 WasmYAML::Function &Function) {
312 IO.mapRequired("Index", Function.Index);
313 IO.mapRequired("Locals", Function.Locals);
314 IO.mapRequired("Body", Function.Body);
317 void MappingTraits<WasmYAML::Relocation>::mapping(
318 IO &IO, WasmYAML::Relocation &Relocation) {
319 IO.mapRequired("Type", Relocation.Type);
320 IO.mapRequired("Index", Relocation.Index);
321 IO.mapRequired("Offset", Relocation.Offset);
322 IO.mapOptional("Addend", Relocation.Addend, 0);
325 void MappingTraits<WasmYAML::NameEntry>::mapping(
326 IO &IO, WasmYAML::NameEntry &NameEntry) {
327 IO.mapRequired("Index", NameEntry.Index);
328 IO.mapRequired("Name", NameEntry.Name);
331 void MappingTraits<WasmYAML::ProducerEntry>::mapping(
332 IO &IO, WasmYAML::ProducerEntry &ProducerEntry) {
333 IO.mapRequired("Name", ProducerEntry.Name);
334 IO.mapRequired("Version", ProducerEntry.Version);
337 void ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix>::enumeration(
338 IO &IO, WasmYAML::FeaturePolicyPrefix &Kind) {
339 #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_FEATURE_PREFIX_##X);
340 ECase(USED);
341 ECase(REQUIRED);
342 ECase(DISALLOWED);
343 #undef ECase
346 void MappingTraits<WasmYAML::FeatureEntry>::mapping(
347 IO &IO, WasmYAML::FeatureEntry &FeatureEntry) {
348 IO.mapRequired("Prefix", FeatureEntry.Prefix);
349 IO.mapRequired("Name", FeatureEntry.Name);
352 void MappingTraits<WasmYAML::SegmentInfo>::mapping(
353 IO &IO, WasmYAML::SegmentInfo &SegmentInfo) {
354 IO.mapRequired("Index", SegmentInfo.Index);
355 IO.mapRequired("Name", SegmentInfo.Name);
356 IO.mapRequired("Alignment", SegmentInfo.Alignment);
357 IO.mapRequired("Flags", SegmentInfo.Flags);
360 void MappingTraits<WasmYAML::LocalDecl>::mapping(
361 IO &IO, WasmYAML::LocalDecl &LocalDecl) {
362 IO.mapRequired("Type", LocalDecl.Type);
363 IO.mapRequired("Count", LocalDecl.Count);
366 void MappingTraits<WasmYAML::Limits>::mapping(IO &IO,
367 WasmYAML::Limits &Limits) {
368 if (!IO.outputting() || Limits.Flags)
369 IO.mapOptional("Flags", Limits.Flags);
370 IO.mapRequired("Minimum", Limits.Minimum);
371 if (!IO.outputting() || Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
372 IO.mapOptional("Maximum", Limits.Maximum);
375 void MappingTraits<WasmYAML::ElemSegment>::mapping(
376 IO &IO, WasmYAML::ElemSegment &Segment) {
377 if (!IO.outputting() || Segment.Flags)
378 IO.mapOptional("Flags", Segment.Flags);
379 if (!IO.outputting() ||
380 Segment.Flags & wasm::WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER)
381 IO.mapOptional("TableNumber", Segment.TableNumber);
382 if (!IO.outputting() ||
383 Segment.Flags & wasm::WASM_ELEM_SEGMENT_MASK_HAS_ELEM_KIND)
384 IO.mapOptional("ElemKind", Segment.ElemKind);
385 IO.mapRequired("Offset", Segment.Offset);
386 IO.mapRequired("Functions", Segment.Functions);
389 void MappingTraits<WasmYAML::Import>::mapping(IO &IO,
390 WasmYAML::Import &Import) {
391 IO.mapRequired("Module", Import.Module);
392 IO.mapRequired("Field", Import.Field);
393 IO.mapRequired("Kind", Import.Kind);
394 if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION) {
395 IO.mapRequired("SigIndex", Import.SigIndex);
396 } else if (Import.Kind == wasm::WASM_EXTERNAL_GLOBAL) {
397 IO.mapRequired("GlobalType", Import.GlobalImport.Type);
398 IO.mapRequired("GlobalMutable", Import.GlobalImport.Mutable);
399 } else if (Import.Kind == wasm::WASM_EXTERNAL_TAG) {
400 IO.mapRequired("TagAttribute", Import.TagImport.Attribute);
401 IO.mapRequired("TagSigIndex", Import.TagImport.SigIndex);
402 } else if (Import.Kind == wasm::WASM_EXTERNAL_TABLE) {
403 IO.mapRequired("Table", Import.TableImport);
404 } else if (Import.Kind == wasm::WASM_EXTERNAL_MEMORY) {
405 IO.mapRequired("Memory", Import.Memory);
406 } else {
407 llvm_unreachable("unhandled import type");
411 void MappingTraits<WasmYAML::Export>::mapping(IO &IO,
412 WasmYAML::Export &Export) {
413 IO.mapRequired("Name", Export.Name);
414 IO.mapRequired("Kind", Export.Kind);
415 IO.mapRequired("Index", Export.Index);
418 void MappingTraits<WasmYAML::Global>::mapping(IO &IO,
419 WasmYAML::Global &Global) {
420 IO.mapRequired("Index", Global.Index);
421 IO.mapRequired("Type", Global.Type);
422 IO.mapRequired("Mutable", Global.Mutable);
423 IO.mapRequired("InitExpr", Global.InitExpr);
426 void MappingTraits<wasm::WasmInitExpr>::mapping(IO &IO,
427 wasm::WasmInitExpr &Expr) {
428 WasmYAML::Opcode Op = Expr.Opcode;
429 IO.mapRequired("Opcode", Op);
430 Expr.Opcode = Op;
431 switch (Expr.Opcode) {
432 case wasm::WASM_OPCODE_I32_CONST:
433 IO.mapRequired("Value", Expr.Value.Int32);
434 break;
435 case wasm::WASM_OPCODE_I64_CONST:
436 IO.mapRequired("Value", Expr.Value.Int64);
437 break;
438 case wasm::WASM_OPCODE_F32_CONST:
439 IO.mapRequired("Value", Expr.Value.Float32);
440 break;
441 case wasm::WASM_OPCODE_F64_CONST:
442 IO.mapRequired("Value", Expr.Value.Float64);
443 break;
444 case wasm::WASM_OPCODE_GLOBAL_GET:
445 IO.mapRequired("Index", Expr.Value.Global);
446 break;
447 case wasm::WASM_OPCODE_REF_NULL: {
448 WasmYAML::ValueType Ty = wasm::WASM_TYPE_EXTERNREF;
449 IO.mapRequired("Type", Ty);
450 break;
455 void MappingTraits<WasmYAML::DataSegment>::mapping(
456 IO &IO, WasmYAML::DataSegment &Segment) {
457 IO.mapOptional("SectionOffset", Segment.SectionOffset);
458 IO.mapRequired("InitFlags", Segment.InitFlags);
459 if (Segment.InitFlags & wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX) {
460 IO.mapRequired("MemoryIndex", Segment.MemoryIndex);
461 } else {
462 Segment.MemoryIndex = 0;
464 if ((Segment.InitFlags & wasm::WASM_DATA_SEGMENT_IS_PASSIVE) == 0) {
465 IO.mapRequired("Offset", Segment.Offset);
466 } else {
467 Segment.Offset.Opcode = wasm::WASM_OPCODE_I32_CONST;
468 Segment.Offset.Value.Int32 = 0;
470 IO.mapRequired("Content", Segment.Content);
473 void MappingTraits<WasmYAML::InitFunction>::mapping(
474 IO &IO, WasmYAML::InitFunction &Init) {
475 IO.mapRequired("Priority", Init.Priority);
476 IO.mapRequired("Symbol", Init.Symbol);
479 void ScalarEnumerationTraits<WasmYAML::ComdatKind>::enumeration(
480 IO &IO, WasmYAML::ComdatKind &Kind) {
481 #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_COMDAT_##X);
482 ECase(FUNCTION);
483 ECase(DATA);
484 ECase(SECTION);
485 #undef ECase
488 void MappingTraits<WasmYAML::ComdatEntry>::mapping(
489 IO &IO, WasmYAML::ComdatEntry &ComdatEntry) {
490 IO.mapRequired("Kind", ComdatEntry.Kind);
491 IO.mapRequired("Index", ComdatEntry.Index);
494 void MappingTraits<WasmYAML::Comdat>::mapping(IO &IO,
495 WasmYAML::Comdat &Comdat) {
496 IO.mapRequired("Name", Comdat.Name);
497 IO.mapRequired("Entries", Comdat.Entries);
500 void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,
501 WasmYAML::SymbolInfo &Info) {
502 IO.mapRequired("Index", Info.Index);
503 IO.mapRequired("Kind", Info.Kind);
504 if (Info.Kind != wasm::WASM_SYMBOL_TYPE_SECTION)
505 IO.mapRequired("Name", Info.Name);
506 IO.mapRequired("Flags", Info.Flags);
507 if (Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION) {
508 IO.mapRequired("Function", Info.ElementIndex);
509 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL) {
510 IO.mapRequired("Global", Info.ElementIndex);
511 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_TABLE) {
512 IO.mapRequired("Table", Info.ElementIndex);
513 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_TAG) {
514 IO.mapRequired("Tag", Info.ElementIndex);
515 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA) {
516 if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) {
517 IO.mapRequired("Segment", Info.DataRef.Segment);
518 IO.mapOptional("Offset", Info.DataRef.Offset, 0u);
519 IO.mapRequired("Size", Info.DataRef.Size);
521 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION) {
522 IO.mapRequired("Section", Info.ElementIndex);
523 } else {
524 llvm_unreachable("unsupported symbol kind");
528 void MappingTraits<WasmYAML::Tag>::mapping(IO &IO, WasmYAML::Tag &Tag) {
529 IO.mapRequired("Index", Tag.Index);
530 IO.mapRequired("Attribute", Tag.Attribute);
531 IO.mapRequired("SigIndex", Tag.SigIndex);
534 void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset(
535 IO &IO, WasmYAML::LimitFlags &Value) {
536 #define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X)
537 BCase(HAS_MAX);
538 BCase(IS_SHARED);
539 BCase(IS_64);
540 #undef BCase
543 void ScalarBitSetTraits<WasmYAML::SegmentFlags>::bitset(
544 IO &IO, WasmYAML::SegmentFlags &Value) {
545 #define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_SEG_FLAG_##X)
546 BCase(STRINGS);
547 BCase(TLS);
548 #undef BCase
551 void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset(
552 IO &IO, WasmYAML::SymbolFlags &Value) {
553 #define BCaseMask(M, X) \
554 IO.maskedBitSetCase(Value, #X, wasm::WASM_SYMBOL_##X, wasm::WASM_SYMBOL_##M)
555 // BCaseMask(BINDING_MASK, BINDING_GLOBAL);
556 BCaseMask(BINDING_MASK, BINDING_WEAK);
557 BCaseMask(BINDING_MASK, BINDING_LOCAL);
558 // BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT);
559 BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN);
560 BCaseMask(UNDEFINED, UNDEFINED);
561 BCaseMask(EXPORTED, EXPORTED);
562 BCaseMask(EXPLICIT_NAME, EXPLICIT_NAME);
563 BCaseMask(NO_STRIP, NO_STRIP);
564 #undef BCaseMask
567 void ScalarEnumerationTraits<WasmYAML::SymbolKind>::enumeration(
568 IO &IO, WasmYAML::SymbolKind &Kind) {
569 #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_SYMBOL_TYPE_##X);
570 ECase(FUNCTION);
571 ECase(DATA);
572 ECase(GLOBAL);
573 ECase(TABLE);
574 ECase(SECTION);
575 ECase(TAG);
576 #undef ECase
579 void ScalarEnumerationTraits<WasmYAML::ValueType>::enumeration(
580 IO &IO, WasmYAML::ValueType &Type) {
581 #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);
582 ECase(I32);
583 ECase(I64);
584 ECase(F32);
585 ECase(F64);
586 ECase(V128);
587 ECase(FUNCREF);
588 ECase(EXTERNREF);
589 ECase(FUNC);
590 #undef ECase
593 void ScalarEnumerationTraits<WasmYAML::ExportKind>::enumeration(
594 IO &IO, WasmYAML::ExportKind &Kind) {
595 #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_EXTERNAL_##X);
596 ECase(FUNCTION);
597 ECase(TABLE);
598 ECase(MEMORY);
599 ECase(GLOBAL);
600 ECase(TAG);
601 #undef ECase
604 void ScalarEnumerationTraits<WasmYAML::Opcode>::enumeration(
605 IO &IO, WasmYAML::Opcode &Code) {
606 #define ECase(X) IO.enumCase(Code, #X, wasm::WASM_OPCODE_##X);
607 ECase(END);
608 ECase(I32_CONST);
609 ECase(I64_CONST);
610 ECase(F64_CONST);
611 ECase(F32_CONST);
612 ECase(GLOBAL_GET);
613 ECase(REF_NULL);
614 #undef ECase
617 void ScalarEnumerationTraits<WasmYAML::TableType>::enumeration(
618 IO &IO, WasmYAML::TableType &Type) {
619 #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);
620 ECase(FUNCREF);
621 ECase(EXTERNREF);
622 #undef ECase
625 void ScalarEnumerationTraits<WasmYAML::RelocType>::enumeration(
626 IO &IO, WasmYAML::RelocType &Type) {
627 #define WASM_RELOC(name, value) IO.enumCase(Type, #name, wasm::name);
628 #include "llvm/BinaryFormat/WasmRelocs.def"
629 #undef WASM_RELOC
630 IO.enumFallback<Hex32>(Type);
633 } // end namespace yaml
635 } // end namespace llvm