blob: 610507cf7f0b1fe9492e281c6f89124cb665aef1 [file] [log] [blame]
Derek Schuffd3d84fd2017-03-30 19:44:09 +00001//===- WasmYAML.cpp - Wasm YAMLIO implementation --------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines classes for handling the YAML representation of wasm.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ObjectYAML/WasmYAML.h"
Eugene Zelenko28082ab2017-07-01 01:35:55 +000015#include "llvm/ADT/StringRef.h"
Derek Schuffd3d84fd2017-03-30 19:44:09 +000016#include "llvm/Support/Casting.h"
Eugene Zelenko28082ab2017-07-01 01:35:55 +000017#include "llvm/Support/ErrorHandling.h"
18#include "llvm/Support/YAMLTraits.h"
Derek Schuffd3d84fd2017-03-30 19:44:09 +000019
20namespace llvm {
Derek Schuffc5b472f2017-03-31 22:14:14 +000021
22namespace WasmYAML {
23
24// Declared here rather than in the header to comply with:
25// http://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers
Eugene Zelenko28082ab2017-07-01 01:35:55 +000026Section::~Section() = default;
Derek Schuffc5b472f2017-03-31 22:14:14 +000027
28} // end namespace WasmYAML
29
Derek Schuffd3d84fd2017-03-30 19:44:09 +000030namespace yaml {
31
32void MappingTraits<WasmYAML::FileHeader>::mapping(
33 IO &IO, WasmYAML::FileHeader &FileHdr) {
34 IO.mapRequired("Version", FileHdr.Version);
35}
36
37void MappingTraits<WasmYAML::Object>::mapping(IO &IO,
38 WasmYAML::Object &Object) {
39 IO.setContext(&Object);
40 IO.mapTag("!WASM", true);
41 IO.mapRequired("FileHeader", Object.Header);
42 IO.mapOptional("Sections", Object.Sections);
43 IO.setContext(nullptr);
44}
45
46static void commonSectionMapping(IO &IO, WasmYAML::Section &Section) {
47 IO.mapRequired("Type", Section.Type);
48 IO.mapOptional("Relocations", Section.Relocations);
49}
50
Sam Cleggb7787fd2017-06-20 04:04:59 +000051static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) {
52 commonSectionMapping(IO, Section);
53 IO.mapRequired("Name", Section.Name);
54 IO.mapOptional("FunctionNames", Section.FunctionNames);
55}
56
57static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) {
58 commonSectionMapping(IO, Section);
59 IO.mapRequired("Name", Section.Name);
Sam Clegg6bb5a412018-04-26 18:15:32 +000060 IO.mapRequired("Version", Section.Version);
Sam Clegg6c899ba2018-02-23 05:08:34 +000061 IO.mapOptional("SymbolTable", Section.SymbolTable);
Sam Clegg63ebb812017-09-29 16:50:08 +000062 IO.mapOptional("SegmentInfo", Section.SegmentInfos);
Sam Clegg42739982017-12-14 21:10:03 +000063 IO.mapOptional("InitFunctions", Section.InitFunctions);
Sam Cleggea7cace2018-01-09 23:43:14 +000064 IO.mapOptional("Comdats", Section.Comdats);
Sam Cleggb7787fd2017-06-20 04:04:59 +000065}
66
Derek Schuffd3d84fd2017-03-30 19:44:09 +000067static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) {
68 commonSectionMapping(IO, Section);
69 IO.mapRequired("Name", Section.Name);
Sam Cleggb7787fd2017-06-20 04:04:59 +000070 IO.mapRequired("Payload", Section.Payload);
Derek Schuffd3d84fd2017-03-30 19:44:09 +000071}
72
73static void sectionMapping(IO &IO, WasmYAML::TypeSection &Section) {
74 commonSectionMapping(IO, Section);
75 IO.mapOptional("Signatures", Section.Signatures);
76}
77
78static void sectionMapping(IO &IO, WasmYAML::ImportSection &Section) {
79 commonSectionMapping(IO, Section);
80 IO.mapOptional("Imports", Section.Imports);
81}
82
83static void sectionMapping(IO &IO, WasmYAML::FunctionSection &Section) {
84 commonSectionMapping(IO, Section);
85 IO.mapOptional("FunctionTypes", Section.FunctionTypes);
86}
87
88static void sectionMapping(IO &IO, WasmYAML::TableSection &Section) {
89 commonSectionMapping(IO, Section);
90 IO.mapOptional("Tables", Section.Tables);
91}
92
93static void sectionMapping(IO &IO, WasmYAML::MemorySection &Section) {
94 commonSectionMapping(IO, Section);
95 IO.mapOptional("Memories", Section.Memories);
96}
97
98static void sectionMapping(IO &IO, WasmYAML::GlobalSection &Section) {
99 commonSectionMapping(IO, Section);
100 IO.mapOptional("Globals", Section.Globals);
101}
102
Heejin Ahnda419bd2018-11-14 02:46:21 +0000103static void sectionMapping(IO &IO, WasmYAML::EventSection &Section) {
104 commonSectionMapping(IO, Section);
105 IO.mapOptional("Events", Section.Events);
106}
107
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000108static void sectionMapping(IO &IO, WasmYAML::ExportSection &Section) {
109 commonSectionMapping(IO, Section);
110 IO.mapOptional("Exports", Section.Exports);
111}
112
113static void sectionMapping(IO &IO, WasmYAML::StartSection &Section) {
114 commonSectionMapping(IO, Section);
115 IO.mapOptional("StartFunction", Section.StartFunction);
116}
117
118static void sectionMapping(IO &IO, WasmYAML::ElemSection &Section) {
119 commonSectionMapping(IO, Section);
120 IO.mapOptional("Segments", Section.Segments);
121}
122
123static void sectionMapping(IO &IO, WasmYAML::CodeSection &Section) {
124 commonSectionMapping(IO, Section);
125 IO.mapRequired("Functions", Section.Functions);
126}
127
128static void sectionMapping(IO &IO, WasmYAML::DataSection &Section) {
129 commonSectionMapping(IO, Section);
130 IO.mapRequired("Segments", Section.Segments);
131}
132
133void MappingTraits<std::unique_ptr<WasmYAML::Section>>::mapping(
134 IO &IO, std::unique_ptr<WasmYAML::Section> &Section) {
135 WasmYAML::SectionType SectionType;
136 if (IO.outputting())
137 SectionType = Section->Type;
138 else
139 IO.mapRequired("Type", SectionType);
140
141 switch (SectionType) {
Sam Cleggb7787fd2017-06-20 04:04:59 +0000142 case wasm::WASM_SEC_CUSTOM: {
143 StringRef SectionName;
144 if (IO.outputting()) {
145 auto CustomSection = cast<WasmYAML::CustomSection>(Section.get());
146 SectionName = CustomSection->Name;
147 } else {
148 IO.mapRequired("Name", SectionName);
149 }
150 if (SectionName == "linking") {
151 if (!IO.outputting())
152 Section.reset(new WasmYAML::LinkingSection());
153 sectionMapping(IO, *cast<WasmYAML::LinkingSection>(Section.get()));
154 } else if (SectionName == "name") {
155 if (!IO.outputting())
156 Section.reset(new WasmYAML::NameSection());
157 sectionMapping(IO, *cast<WasmYAML::NameSection>(Section.get()));
158 } else {
159 if (!IO.outputting())
160 Section.reset(new WasmYAML::CustomSection(SectionName));
161 sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get()));
162 }
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000163 break;
Sam Cleggb7787fd2017-06-20 04:04:59 +0000164 }
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000165 case wasm::WASM_SEC_TYPE:
166 if (!IO.outputting())
167 Section.reset(new WasmYAML::TypeSection());
168 sectionMapping(IO, *cast<WasmYAML::TypeSection>(Section.get()));
169 break;
170 case wasm::WASM_SEC_IMPORT:
171 if (!IO.outputting())
172 Section.reset(new WasmYAML::ImportSection());
173 sectionMapping(IO, *cast<WasmYAML::ImportSection>(Section.get()));
174 break;
175 case wasm::WASM_SEC_FUNCTION:
176 if (!IO.outputting())
177 Section.reset(new WasmYAML::FunctionSection());
178 sectionMapping(IO, *cast<WasmYAML::FunctionSection>(Section.get()));
179 break;
180 case wasm::WASM_SEC_TABLE:
181 if (!IO.outputting())
182 Section.reset(new WasmYAML::TableSection());
183 sectionMapping(IO, *cast<WasmYAML::TableSection>(Section.get()));
184 break;
185 case wasm::WASM_SEC_MEMORY:
186 if (!IO.outputting())
187 Section.reset(new WasmYAML::MemorySection());
188 sectionMapping(IO, *cast<WasmYAML::MemorySection>(Section.get()));
189 break;
190 case wasm::WASM_SEC_GLOBAL:
191 if (!IO.outputting())
192 Section.reset(new WasmYAML::GlobalSection());
193 sectionMapping(IO, *cast<WasmYAML::GlobalSection>(Section.get()));
194 break;
Heejin Ahnda419bd2018-11-14 02:46:21 +0000195 case wasm::WASM_SEC_EVENT:
196 if (!IO.outputting())
197 Section.reset(new WasmYAML::EventSection());
198 sectionMapping(IO, *cast<WasmYAML::EventSection>(Section.get()));
199 break;
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000200 case wasm::WASM_SEC_EXPORT:
201 if (!IO.outputting())
202 Section.reset(new WasmYAML::ExportSection());
203 sectionMapping(IO, *cast<WasmYAML::ExportSection>(Section.get()));
204 break;
205 case wasm::WASM_SEC_START:
206 if (!IO.outputting())
207 Section.reset(new WasmYAML::StartSection());
208 sectionMapping(IO, *cast<WasmYAML::StartSection>(Section.get()));
209 break;
210 case wasm::WASM_SEC_ELEM:
211 if (!IO.outputting())
212 Section.reset(new WasmYAML::ElemSection());
213 sectionMapping(IO, *cast<WasmYAML::ElemSection>(Section.get()));
214 break;
215 case wasm::WASM_SEC_CODE:
216 if (!IO.outputting())
217 Section.reset(new WasmYAML::CodeSection());
218 sectionMapping(IO, *cast<WasmYAML::CodeSection>(Section.get()));
219 break;
220 case wasm::WASM_SEC_DATA:
221 if (!IO.outputting())
222 Section.reset(new WasmYAML::DataSection());
223 sectionMapping(IO, *cast<WasmYAML::DataSection>(Section.get()));
224 break;
225 default:
226 llvm_unreachable("Unknown section type");
227 }
228}
229
230void ScalarEnumerationTraits<WasmYAML::SectionType>::enumeration(
231 IO &IO, WasmYAML::SectionType &Type) {
232#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_SEC_##X);
233 ECase(CUSTOM);
234 ECase(TYPE);
235 ECase(IMPORT);
236 ECase(FUNCTION);
237 ECase(TABLE);
238 ECase(MEMORY);
239 ECase(GLOBAL);
Heejin Ahnda419bd2018-11-14 02:46:21 +0000240 ECase(EVENT);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000241 ECase(EXPORT);
242 ECase(START);
243 ECase(ELEM);
244 ECase(CODE);
245 ECase(DATA);
246#undef ECase
247}
248
249void MappingTraits<WasmYAML::Signature>::mapping(
250 IO &IO, WasmYAML::Signature &Signature) {
Sam Clegge53af7f2018-01-09 21:38:53 +0000251 IO.mapRequired("Index", Signature.Index);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000252 IO.mapRequired("ReturnType", Signature.ReturnType);
253 IO.mapRequired("ParamTypes", Signature.ParamTypes);
254}
255
256void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) {
257 IO.mapRequired("ElemType", Table.ElemType);
258 IO.mapRequired("Limits", Table.TableLimits);
259}
260
261void MappingTraits<WasmYAML::Function>::mapping(IO &IO,
262 WasmYAML::Function &Function) {
Sam Clegge53af7f2018-01-09 21:38:53 +0000263 IO.mapRequired("Index", Function.Index);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000264 IO.mapRequired("Locals", Function.Locals);
265 IO.mapRequired("Body", Function.Body);
266}
267
268void MappingTraits<WasmYAML::Relocation>::mapping(
269 IO &IO, WasmYAML::Relocation &Relocation) {
270 IO.mapRequired("Type", Relocation.Type);
271 IO.mapRequired("Index", Relocation.Index);
272 IO.mapRequired("Offset", Relocation.Offset);
Sam Cleggcc182aa2017-04-26 00:02:31 +0000273 IO.mapOptional("Addend", Relocation.Addend, 0);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000274}
275
Sam Clegg03cdd122017-05-05 18:12:34 +0000276void MappingTraits<WasmYAML::NameEntry>::mapping(
277 IO &IO, WasmYAML::NameEntry &NameEntry) {
278 IO.mapRequired("Index", NameEntry.Index);
279 IO.mapRequired("Name", NameEntry.Name);
280}
281
Sam Clegg63ebb812017-09-29 16:50:08 +0000282void MappingTraits<WasmYAML::SegmentInfo>::mapping(
283 IO &IO, WasmYAML::SegmentInfo &SegmentInfo) {
284 IO.mapRequired("Index", SegmentInfo.Index);
285 IO.mapRequired("Name", SegmentInfo.Name);
286 IO.mapRequired("Alignment", SegmentInfo.Alignment);
287 IO.mapRequired("Flags", SegmentInfo.Flags);
288}
289
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000290void MappingTraits<WasmYAML::LocalDecl>::mapping(
291 IO &IO, WasmYAML::LocalDecl &LocalDecl) {
292 IO.mapRequired("Type", LocalDecl.Type);
293 IO.mapRequired("Count", LocalDecl.Count);
294}
295
296void MappingTraits<WasmYAML::Limits>::mapping(IO &IO,
297 WasmYAML::Limits &Limits) {
298 if (!IO.outputting() || Limits.Flags)
299 IO.mapOptional("Flags", Limits.Flags);
300 IO.mapRequired("Initial", Limits.Initial);
301 if (!IO.outputting() || Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
302 IO.mapOptional("Maximum", Limits.Maximum);
303}
304
305void MappingTraits<WasmYAML::ElemSegment>::mapping(
306 IO &IO, WasmYAML::ElemSegment &Segment) {
307 IO.mapRequired("Offset", Segment.Offset);
308 IO.mapRequired("Functions", Segment.Functions);
309}
310
311void MappingTraits<WasmYAML::Import>::mapping(IO &IO,
312 WasmYAML::Import &Import) {
313 IO.mapRequired("Module", Import.Module);
314 IO.mapRequired("Field", Import.Field);
315 IO.mapRequired("Kind", Import.Kind);
316 if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION) {
317 IO.mapRequired("SigIndex", Import.SigIndex);
318 } else if (Import.Kind == wasm::WASM_EXTERNAL_GLOBAL) {
Sam Clegg41db5192017-05-10 00:14:04 +0000319 IO.mapRequired("GlobalType", Import.GlobalImport.Type);
320 IO.mapRequired("GlobalMutable", Import.GlobalImport.Mutable);
Heejin Ahnda419bd2018-11-14 02:46:21 +0000321 } else if (Import.Kind == wasm::WASM_EXTERNAL_EVENT) {
322 IO.mapRequired("EventAttribute", Import.EventImport.Attribute);
323 IO.mapRequired("EventSigIndex", Import.EventImport.SigIndex);
Sam Clegg2ffff5a2017-05-09 23:48:41 +0000324 } else if (Import.Kind == wasm::WASM_EXTERNAL_TABLE) {
Sam Clegg41db5192017-05-10 00:14:04 +0000325 IO.mapRequired("Table", Import.TableImport);
Heejin Ahnf208f632018-09-05 01:27:38 +0000326 } else if (Import.Kind == wasm::WASM_EXTERNAL_MEMORY) {
Sam Clegg2ffff5a2017-05-09 23:48:41 +0000327 IO.mapRequired("Memory", Import.Memory);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000328 } else {
329 llvm_unreachable("unhandled import type");
330 }
331}
332
333void MappingTraits<WasmYAML::Export>::mapping(IO &IO,
334 WasmYAML::Export &Export) {
335 IO.mapRequired("Name", Export.Name);
336 IO.mapRequired("Kind", Export.Kind);
337 IO.mapRequired("Index", Export.Index);
338}
339
340void MappingTraits<WasmYAML::Global>::mapping(IO &IO,
341 WasmYAML::Global &Global) {
Sam Clegge53af7f2018-01-09 21:38:53 +0000342 IO.mapRequired("Index", Global.Index);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000343 IO.mapRequired("Type", Global.Type);
344 IO.mapRequired("Mutable", Global.Mutable);
345 IO.mapRequired("InitExpr", Global.InitExpr);
346}
347
348void MappingTraits<wasm::WasmInitExpr>::mapping(IO &IO,
349 wasm::WasmInitExpr &Expr) {
350 WasmYAML::Opcode Op = Expr.Opcode;
351 IO.mapRequired("Opcode", Op);
352 Expr.Opcode = Op;
353 switch (Expr.Opcode) {
354 case wasm::WASM_OPCODE_I32_CONST:
355 IO.mapRequired("Value", Expr.Value.Int32);
356 break;
357 case wasm::WASM_OPCODE_I64_CONST:
358 IO.mapRequired("Value", Expr.Value.Int64);
359 break;
360 case wasm::WASM_OPCODE_F32_CONST:
361 IO.mapRequired("Value", Expr.Value.Float32);
362 break;
363 case wasm::WASM_OPCODE_F64_CONST:
364 IO.mapRequired("Value", Expr.Value.Float64);
365 break;
Sam Clegg7fb391f2017-04-25 17:11:56 +0000366 case wasm::WASM_OPCODE_GET_GLOBAL:
367 IO.mapRequired("Index", Expr.Value.Global);
368 break;
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000369 }
370}
371
372void MappingTraits<WasmYAML::DataSegment>::mapping(
373 IO &IO, WasmYAML::DataSegment &Segment) {
Sam Clegg9c07f942017-07-12 00:24:54 +0000374 IO.mapOptional("SectionOffset", Segment.SectionOffset);
375 IO.mapRequired("MemoryIndex", Segment.MemoryIndex);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000376 IO.mapRequired("Offset", Segment.Offset);
377 IO.mapRequired("Content", Segment.Content);
378}
379
Sam Clegg42739982017-12-14 21:10:03 +0000380void MappingTraits<WasmYAML::InitFunction>::mapping(
381 IO &IO, WasmYAML::InitFunction &Init) {
382 IO.mapRequired("Priority", Init.Priority);
Sam Clegg6c899ba2018-02-23 05:08:34 +0000383 IO.mapRequired("Symbol", Init.Symbol);
Sam Clegg42739982017-12-14 21:10:03 +0000384}
385
Sam Cleggea7cace2018-01-09 23:43:14 +0000386void ScalarEnumerationTraits<WasmYAML::ComdatKind>::enumeration(
387 IO &IO, WasmYAML::ComdatKind &Kind) {
388#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_COMDAT_##X);
389 ECase(FUNCTION);
390 ECase(DATA);
391#undef ECase
392}
393
394void MappingTraits<WasmYAML::ComdatEntry>::mapping(
395 IO &IO, WasmYAML::ComdatEntry &ComdatEntry) {
396 IO.mapRequired("Kind", ComdatEntry.Kind);
397 IO.mapRequired("Index", ComdatEntry.Index);
398}
399
Heejin Ahnf208f632018-09-05 01:27:38 +0000400void MappingTraits<WasmYAML::Comdat>::mapping(IO &IO,
401 WasmYAML::Comdat &Comdat) {
Sam Cleggea7cace2018-01-09 23:43:14 +0000402 IO.mapRequired("Name", Comdat.Name);
403 IO.mapRequired("Entries", Comdat.Entries);
404}
405
Sam Cleggb7787fd2017-06-20 04:04:59 +0000406void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,
407 WasmYAML::SymbolInfo &Info) {
Sam Clegg6c899ba2018-02-23 05:08:34 +0000408 IO.mapRequired("Index", Info.Index);
409 IO.mapRequired("Kind", Info.Kind);
Sam Cleggb7787fd2017-06-20 04:04:59 +0000410 IO.mapRequired("Name", Info.Name);
411 IO.mapRequired("Flags", Info.Flags);
Sam Clegg6c899ba2018-02-23 05:08:34 +0000412 if (Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION) {
413 IO.mapRequired("Function", Info.ElementIndex);
414 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL) {
415 IO.mapRequired("Global", Info.ElementIndex);
Heejin Ahnda419bd2018-11-14 02:46:21 +0000416 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_EVENT) {
417 IO.mapRequired("Event", Info.ElementIndex);
Sam Clegg6c899ba2018-02-23 05:08:34 +0000418 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA) {
419 if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) {
420 IO.mapRequired("Segment", Info.DataRef.Segment);
421 IO.mapOptional("Offset", Info.DataRef.Offset, 0u);
422 IO.mapRequired("Size", Info.DataRef.Size);
423 }
Sam Clegg6a31a0d2018-04-26 19:27:28 +0000424 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION) {
425 IO.mapRequired("Section", Info.ElementIndex);
Sam Clegg6c899ba2018-02-23 05:08:34 +0000426 } else {
427 llvm_unreachable("unsupported symbol kind");
428 }
Sam Cleggb7787fd2017-06-20 04:04:59 +0000429}
430
Heejin Ahnda419bd2018-11-14 02:46:21 +0000431void MappingTraits<WasmYAML::Event>::mapping(IO &IO, WasmYAML::Event &Event) {
432 IO.mapRequired("Index", Event.Index);
433 IO.mapRequired("Attribute", Event.Attribute);
434 IO.mapRequired("SigIndex", Event.SigIndex);
435}
436
Sam Clegg0fc55992017-12-13 22:02:25 +0000437void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset(
438 IO &IO, WasmYAML::LimitFlags &Value) {
439#define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X)
440 BCase(HAS_MAX);
Derek Schuff68818062018-11-06 17:27:25 +0000441 BCase(IS_SHARED);
Sam Clegg0fc55992017-12-13 22:02:25 +0000442#undef BCase
443}
444
445void ScalarBitSetTraits<WasmYAML::SegmentFlags>::bitset(
Heejin Ahnf208f632018-09-05 01:27:38 +0000446 IO &IO, WasmYAML::SegmentFlags &Value) {}
Sam Clegg0fc55992017-12-13 22:02:25 +0000447
448void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset(
449 IO &IO, WasmYAML::SymbolFlags &Value) {
Heejin Ahnf208f632018-09-05 01:27:38 +0000450#define BCaseMask(M, X) \
451 IO.maskedBitSetCase(Value, #X, wasm::WASM_SYMBOL_##X, wasm::WASM_SYMBOL_##M)
452 // BCaseMask(BINDING_MASK, BINDING_GLOBAL);
Sam Clegg0fc55992017-12-13 22:02:25 +0000453 BCaseMask(BINDING_MASK, BINDING_WEAK);
454 BCaseMask(BINDING_MASK, BINDING_LOCAL);
Heejin Ahnf208f632018-09-05 01:27:38 +0000455 // BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT);
Sam Clegg0fc55992017-12-13 22:02:25 +0000456 BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN);
Sam Clegg6c899ba2018-02-23 05:08:34 +0000457 BCaseMask(UNDEFINED, UNDEFINED);
Sam Clegg0fc55992017-12-13 22:02:25 +0000458#undef BCaseMask
459}
460
Sam Clegg6c899ba2018-02-23 05:08:34 +0000461void ScalarEnumerationTraits<WasmYAML::SymbolKind>::enumeration(
462 IO &IO, WasmYAML::SymbolKind &Kind) {
463#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_SYMBOL_TYPE_##X);
464 ECase(FUNCTION);
465 ECase(DATA);
466 ECase(GLOBAL);
Sam Clegg6a31a0d2018-04-26 19:27:28 +0000467 ECase(SECTION);
Heejin Ahnda419bd2018-11-14 02:46:21 +0000468 ECase(EVENT);
Sam Clegg6c899ba2018-02-23 05:08:34 +0000469#undef ECase
470}
471
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000472void ScalarEnumerationTraits<WasmYAML::ValueType>::enumeration(
473 IO &IO, WasmYAML::ValueType &Type) {
474#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);
475 ECase(I32);
476 ECase(I64);
477 ECase(F32);
478 ECase(F64);
Thomas Lively6f21a132018-09-20 22:04:44 +0000479 ECase(V128);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000480 ECase(ANYFUNC);
481 ECase(FUNC);
482 ECase(NORESULT);
483#undef ECase
484}
485
486void ScalarEnumerationTraits<WasmYAML::ExportKind>::enumeration(
487 IO &IO, WasmYAML::ExportKind &Kind) {
488#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_EXTERNAL_##X);
489 ECase(FUNCTION);
490 ECase(TABLE);
491 ECase(MEMORY);
492 ECase(GLOBAL);
Heejin Ahnda419bd2018-11-14 02:46:21 +0000493 ECase(EVENT);
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000494#undef ECase
495}
496
497void ScalarEnumerationTraits<WasmYAML::Opcode>::enumeration(
498 IO &IO, WasmYAML::Opcode &Code) {
499#define ECase(X) IO.enumCase(Code, #X, wasm::WASM_OPCODE_##X);
500 ECase(END);
501 ECase(I32_CONST);
502 ECase(I64_CONST);
503 ECase(F64_CONST);
504 ECase(F32_CONST);
505 ECase(GET_GLOBAL);
506#undef ECase
507}
508
509void ScalarEnumerationTraits<WasmYAML::TableType>::enumeration(
510 IO &IO, WasmYAML::TableType &Type) {
511#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);
512 ECase(ANYFUNC);
513#undef ECase
514}
515
516void ScalarEnumerationTraits<WasmYAML::RelocType>::enumeration(
517 IO &IO, WasmYAML::RelocType &Type) {
518#define WASM_RELOC(name, value) IO.enumCase(Type, #name, wasm::name);
Sam Cleggc5d8bc82017-12-21 03:16:34 +0000519#include "llvm/BinaryFormat/WasmRelocs.def"
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000520#undef WASM_RELOC
521}
522
523} // end namespace yaml
Eugene Zelenko28082ab2017-07-01 01:35:55 +0000524
Derek Schuffd3d84fd2017-03-30 19:44:09 +0000525} // end namespace llvm