/src/llvm-project/llvm/lib/ObjectYAML/WasmYAML.cpp
Line | Count | Source (jump to first uncovered line) |
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. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
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" |
18 | | |
19 | | namespace llvm { |
20 | | |
21 | | namespace WasmYAML { |
22 | | |
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 | 0 | Section::~Section() = default; |
26 | | |
27 | | } // end namespace WasmYAML |
28 | | |
29 | | namespace yaml { |
30 | | |
31 | | void MappingTraits<WasmYAML::FileHeader>::mapping( |
32 | 0 | IO &IO, WasmYAML::FileHeader &FileHdr) { |
33 | 0 | IO.mapRequired("Version", FileHdr.Version); |
34 | 0 | } |
35 | | |
36 | | void MappingTraits<WasmYAML::Object>::mapping(IO &IO, |
37 | 0 | WasmYAML::Object &Object) { |
38 | 0 | IO.setContext(&Object); |
39 | 0 | IO.mapTag("!WASM", true); |
40 | 0 | IO.mapRequired("FileHeader", Object.Header); |
41 | 0 | IO.mapOptional("Sections", Object.Sections); |
42 | 0 | IO.setContext(nullptr); |
43 | 0 | } |
44 | | |
45 | 0 | static void commonSectionMapping(IO &IO, WasmYAML::Section &Section) { |
46 | 0 | IO.mapRequired("Type", Section.Type); |
47 | 0 | IO.mapOptional("Relocations", Section.Relocations); |
48 | 0 | IO.mapOptional("HeaderSecSizeEncodingLen", Section.HeaderSecSizeEncodingLen); |
49 | 0 | } |
50 | | |
51 | 0 | static void sectionMapping(IO &IO, WasmYAML::DylinkSection &Section) { |
52 | 0 | commonSectionMapping(IO, Section); |
53 | 0 | IO.mapRequired("Name", Section.Name); |
54 | 0 | IO.mapRequired("MemorySize", Section.MemorySize); |
55 | 0 | IO.mapRequired("MemoryAlignment", Section.MemoryAlignment); |
56 | 0 | IO.mapRequired("TableSize", Section.TableSize); |
57 | 0 | IO.mapRequired("TableAlignment", Section.TableAlignment); |
58 | 0 | IO.mapRequired("Needed", Section.Needed); |
59 | 0 | IO.mapOptional("ImportInfo", Section.ImportInfo); |
60 | 0 | IO.mapOptional("ExportInfo", Section.ExportInfo); |
61 | 0 | } |
62 | | |
63 | 0 | static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) { |
64 | 0 | commonSectionMapping(IO, Section); |
65 | 0 | IO.mapRequired("Name", Section.Name); |
66 | 0 | IO.mapOptional("FunctionNames", Section.FunctionNames); |
67 | 0 | IO.mapOptional("GlobalNames", Section.GlobalNames); |
68 | 0 | IO.mapOptional("DataSegmentNames", Section.DataSegmentNames); |
69 | 0 | } |
70 | | |
71 | 0 | static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) { |
72 | 0 | commonSectionMapping(IO, Section); |
73 | 0 | IO.mapRequired("Name", Section.Name); |
74 | 0 | IO.mapRequired("Version", Section.Version); |
75 | 0 | IO.mapOptional("SymbolTable", Section.SymbolTable); |
76 | 0 | IO.mapOptional("SegmentInfo", Section.SegmentInfos); |
77 | 0 | IO.mapOptional("InitFunctions", Section.InitFunctions); |
78 | 0 | IO.mapOptional("Comdats", Section.Comdats); |
79 | 0 | } |
80 | | |
81 | 0 | static void sectionMapping(IO &IO, WasmYAML::ProducersSection &Section) { |
82 | 0 | commonSectionMapping(IO, Section); |
83 | 0 | IO.mapRequired("Name", Section.Name); |
84 | 0 | IO.mapOptional("Languages", Section.Languages); |
85 | 0 | IO.mapOptional("Tools", Section.Tools); |
86 | 0 | IO.mapOptional("SDKs", Section.SDKs); |
87 | 0 | } |
88 | | |
89 | 0 | static void sectionMapping(IO &IO, WasmYAML::TargetFeaturesSection &Section) { |
90 | 0 | commonSectionMapping(IO, Section); |
91 | 0 | IO.mapRequired("Name", Section.Name); |
92 | 0 | IO.mapRequired("Features", Section.Features); |
93 | 0 | } |
94 | | |
95 | 0 | static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) { |
96 | 0 | commonSectionMapping(IO, Section); |
97 | 0 | IO.mapRequired("Name", Section.Name); |
98 | 0 | IO.mapRequired("Payload", Section.Payload); |
99 | 0 | } |
100 | | |
101 | 0 | static void sectionMapping(IO &IO, WasmYAML::TypeSection &Section) { |
102 | 0 | commonSectionMapping(IO, Section); |
103 | 0 | IO.mapOptional("Signatures", Section.Signatures); |
104 | 0 | } |
105 | | |
106 | 0 | static void sectionMapping(IO &IO, WasmYAML::ImportSection &Section) { |
107 | 0 | commonSectionMapping(IO, Section); |
108 | 0 | IO.mapOptional("Imports", Section.Imports); |
109 | 0 | } |
110 | | |
111 | 0 | static void sectionMapping(IO &IO, WasmYAML::FunctionSection &Section) { |
112 | 0 | commonSectionMapping(IO, Section); |
113 | 0 | IO.mapOptional("FunctionTypes", Section.FunctionTypes); |
114 | 0 | } |
115 | | |
116 | 0 | static void sectionMapping(IO &IO, WasmYAML::TableSection &Section) { |
117 | 0 | commonSectionMapping(IO, Section); |
118 | 0 | IO.mapOptional("Tables", Section.Tables); |
119 | 0 | } |
120 | | |
121 | 0 | static void sectionMapping(IO &IO, WasmYAML::MemorySection &Section) { |
122 | 0 | commonSectionMapping(IO, Section); |
123 | 0 | IO.mapOptional("Memories", Section.Memories); |
124 | 0 | } |
125 | | |
126 | 0 | static void sectionMapping(IO &IO, WasmYAML::TagSection &Section) { |
127 | 0 | commonSectionMapping(IO, Section); |
128 | 0 | IO.mapOptional("TagTypes", Section.TagTypes); |
129 | 0 | } |
130 | | |
131 | 0 | static void sectionMapping(IO &IO, WasmYAML::GlobalSection &Section) { |
132 | 0 | commonSectionMapping(IO, Section); |
133 | 0 | IO.mapOptional("Globals", Section.Globals); |
134 | 0 | } |
135 | | |
136 | 0 | static void sectionMapping(IO &IO, WasmYAML::ExportSection &Section) { |
137 | 0 | commonSectionMapping(IO, Section); |
138 | 0 | IO.mapOptional("Exports", Section.Exports); |
139 | 0 | } |
140 | | |
141 | 0 | static void sectionMapping(IO &IO, WasmYAML::StartSection &Section) { |
142 | 0 | commonSectionMapping(IO, Section); |
143 | 0 | IO.mapOptional("StartFunction", Section.StartFunction); |
144 | 0 | } |
145 | | |
146 | 0 | static void sectionMapping(IO &IO, WasmYAML::ElemSection &Section) { |
147 | 0 | commonSectionMapping(IO, Section); |
148 | 0 | IO.mapOptional("Segments", Section.Segments); |
149 | 0 | } |
150 | | |
151 | 0 | static void sectionMapping(IO &IO, WasmYAML::CodeSection &Section) { |
152 | 0 | commonSectionMapping(IO, Section); |
153 | 0 | IO.mapRequired("Functions", Section.Functions); |
154 | 0 | } |
155 | | |
156 | 0 | static void sectionMapping(IO &IO, WasmYAML::DataSection &Section) { |
157 | 0 | commonSectionMapping(IO, Section); |
158 | 0 | IO.mapRequired("Segments", Section.Segments); |
159 | 0 | } |
160 | | |
161 | 0 | static void sectionMapping(IO &IO, WasmYAML::DataCountSection &Section) { |
162 | 0 | commonSectionMapping(IO, Section); |
163 | 0 | IO.mapRequired("Count", Section.Count); |
164 | 0 | } |
165 | | |
166 | | void MappingTraits<std::unique_ptr<WasmYAML::Section>>::mapping( |
167 | 0 | IO &IO, std::unique_ptr<WasmYAML::Section> &Section) { |
168 | 0 | WasmYAML::SectionType SectionType; |
169 | 0 | if (IO.outputting()) |
170 | 0 | SectionType = Section->Type; |
171 | 0 | else |
172 | 0 | IO.mapRequired("Type", SectionType); |
173 | |
|
174 | 0 | switch (SectionType) { |
175 | 0 | case wasm::WASM_SEC_CUSTOM: { |
176 | 0 | StringRef SectionName; |
177 | 0 | if (IO.outputting()) { |
178 | 0 | auto CustomSection = cast<WasmYAML::CustomSection>(Section.get()); |
179 | 0 | SectionName = CustomSection->Name; |
180 | 0 | } else { |
181 | 0 | IO.mapRequired("Name", SectionName); |
182 | 0 | } |
183 | 0 | if (SectionName == "dylink" || SectionName == "dylink.0") { |
184 | 0 | if (!IO.outputting()) |
185 | 0 | Section.reset(new WasmYAML::DylinkSection()); |
186 | 0 | sectionMapping(IO, *cast<WasmYAML::DylinkSection>(Section.get())); |
187 | 0 | } else if (SectionName == "linking") { |
188 | 0 | if (!IO.outputting()) |
189 | 0 | Section.reset(new WasmYAML::LinkingSection()); |
190 | 0 | sectionMapping(IO, *cast<WasmYAML::LinkingSection>(Section.get())); |
191 | 0 | } else if (SectionName == "name") { |
192 | 0 | if (!IO.outputting()) |
193 | 0 | Section.reset(new WasmYAML::NameSection()); |
194 | 0 | sectionMapping(IO, *cast<WasmYAML::NameSection>(Section.get())); |
195 | 0 | } else if (SectionName == "producers") { |
196 | 0 | if (!IO.outputting()) |
197 | 0 | Section.reset(new WasmYAML::ProducersSection()); |
198 | 0 | sectionMapping(IO, *cast<WasmYAML::ProducersSection>(Section.get())); |
199 | 0 | } else if (SectionName == "target_features") { |
200 | 0 | if (!IO.outputting()) |
201 | 0 | Section.reset(new WasmYAML::TargetFeaturesSection()); |
202 | 0 | sectionMapping(IO, *cast<WasmYAML::TargetFeaturesSection>(Section.get())); |
203 | 0 | } else { |
204 | 0 | if (!IO.outputting()) |
205 | 0 | Section.reset(new WasmYAML::CustomSection(SectionName)); |
206 | 0 | sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get())); |
207 | 0 | } |
208 | 0 | break; |
209 | 0 | } |
210 | 0 | case wasm::WASM_SEC_TYPE: |
211 | 0 | if (!IO.outputting()) |
212 | 0 | Section.reset(new WasmYAML::TypeSection()); |
213 | 0 | sectionMapping(IO, *cast<WasmYAML::TypeSection>(Section.get())); |
214 | 0 | break; |
215 | 0 | case wasm::WASM_SEC_IMPORT: |
216 | 0 | if (!IO.outputting()) |
217 | 0 | Section.reset(new WasmYAML::ImportSection()); |
218 | 0 | sectionMapping(IO, *cast<WasmYAML::ImportSection>(Section.get())); |
219 | 0 | break; |
220 | 0 | case wasm::WASM_SEC_FUNCTION: |
221 | 0 | if (!IO.outputting()) |
222 | 0 | Section.reset(new WasmYAML::FunctionSection()); |
223 | 0 | sectionMapping(IO, *cast<WasmYAML::FunctionSection>(Section.get())); |
224 | 0 | break; |
225 | 0 | case wasm::WASM_SEC_TABLE: |
226 | 0 | if (!IO.outputting()) |
227 | 0 | Section.reset(new WasmYAML::TableSection()); |
228 | 0 | sectionMapping(IO, *cast<WasmYAML::TableSection>(Section.get())); |
229 | 0 | break; |
230 | 0 | case wasm::WASM_SEC_MEMORY: |
231 | 0 | if (!IO.outputting()) |
232 | 0 | Section.reset(new WasmYAML::MemorySection()); |
233 | 0 | sectionMapping(IO, *cast<WasmYAML::MemorySection>(Section.get())); |
234 | 0 | break; |
235 | 0 | case wasm::WASM_SEC_TAG: |
236 | 0 | if (!IO.outputting()) |
237 | 0 | Section.reset(new WasmYAML::TagSection()); |
238 | 0 | sectionMapping(IO, *cast<WasmYAML::TagSection>(Section.get())); |
239 | 0 | break; |
240 | 0 | case wasm::WASM_SEC_GLOBAL: |
241 | 0 | if (!IO.outputting()) |
242 | 0 | Section.reset(new WasmYAML::GlobalSection()); |
243 | 0 | sectionMapping(IO, *cast<WasmYAML::GlobalSection>(Section.get())); |
244 | 0 | break; |
245 | 0 | case wasm::WASM_SEC_EXPORT: |
246 | 0 | if (!IO.outputting()) |
247 | 0 | Section.reset(new WasmYAML::ExportSection()); |
248 | 0 | sectionMapping(IO, *cast<WasmYAML::ExportSection>(Section.get())); |
249 | 0 | break; |
250 | 0 | case wasm::WASM_SEC_START: |
251 | 0 | if (!IO.outputting()) |
252 | 0 | Section.reset(new WasmYAML::StartSection()); |
253 | 0 | sectionMapping(IO, *cast<WasmYAML::StartSection>(Section.get())); |
254 | 0 | break; |
255 | 0 | case wasm::WASM_SEC_ELEM: |
256 | 0 | if (!IO.outputting()) |
257 | 0 | Section.reset(new WasmYAML::ElemSection()); |
258 | 0 | sectionMapping(IO, *cast<WasmYAML::ElemSection>(Section.get())); |
259 | 0 | break; |
260 | 0 | case wasm::WASM_SEC_CODE: |
261 | 0 | if (!IO.outputting()) |
262 | 0 | Section.reset(new WasmYAML::CodeSection()); |
263 | 0 | sectionMapping(IO, *cast<WasmYAML::CodeSection>(Section.get())); |
264 | 0 | break; |
265 | 0 | case wasm::WASM_SEC_DATA: |
266 | 0 | if (!IO.outputting()) |
267 | 0 | Section.reset(new WasmYAML::DataSection()); |
268 | 0 | sectionMapping(IO, *cast<WasmYAML::DataSection>(Section.get())); |
269 | 0 | break; |
270 | 0 | case wasm::WASM_SEC_DATACOUNT: |
271 | 0 | if (!IO.outputting()) |
272 | 0 | Section.reset(new WasmYAML::DataCountSection()); |
273 | 0 | sectionMapping(IO, *cast<WasmYAML::DataCountSection>(Section.get())); |
274 | 0 | break; |
275 | 0 | default: |
276 | 0 | llvm_unreachable("Unknown section type"); |
277 | 0 | } |
278 | 0 | } |
279 | | |
280 | | void ScalarEnumerationTraits<WasmYAML::SectionType>::enumeration( |
281 | 0 | IO &IO, WasmYAML::SectionType &Type) { |
282 | 0 | #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_SEC_##X); |
283 | 0 | ECase(CUSTOM); |
284 | 0 | ECase(TYPE); |
285 | 0 | ECase(IMPORT); |
286 | 0 | ECase(FUNCTION); |
287 | 0 | ECase(TABLE); |
288 | 0 | ECase(MEMORY); |
289 | 0 | ECase(GLOBAL); |
290 | 0 | ECase(TAG); |
291 | 0 | ECase(EXPORT); |
292 | 0 | ECase(START); |
293 | 0 | ECase(ELEM); |
294 | 0 | ECase(CODE); |
295 | 0 | ECase(DATA); |
296 | 0 | ECase(DATACOUNT); |
297 | 0 | #undef ECase |
298 | 0 | } |
299 | | |
300 | | void MappingTraits<WasmYAML::Signature>::mapping( |
301 | 0 | IO &IO, WasmYAML::Signature &Signature) { |
302 | 0 | IO.mapRequired("Index", Signature.Index); |
303 | 0 | IO.mapRequired("ParamTypes", Signature.ParamTypes); |
304 | 0 | IO.mapRequired("ReturnTypes", Signature.ReturnTypes); |
305 | 0 | } |
306 | | |
307 | 0 | void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) { |
308 | 0 | IO.mapRequired("Index", Table.Index); |
309 | 0 | IO.mapRequired("ElemType", Table.ElemType); |
310 | 0 | IO.mapRequired("Limits", Table.TableLimits); |
311 | 0 | } |
312 | | |
313 | | void MappingTraits<WasmYAML::Function>::mapping(IO &IO, |
314 | 0 | WasmYAML::Function &Function) { |
315 | 0 | IO.mapRequired("Index", Function.Index); |
316 | 0 | IO.mapRequired("Locals", Function.Locals); |
317 | 0 | IO.mapRequired("Body", Function.Body); |
318 | 0 | } |
319 | | |
320 | | void MappingTraits<WasmYAML::Relocation>::mapping( |
321 | 0 | IO &IO, WasmYAML::Relocation &Relocation) { |
322 | 0 | IO.mapRequired("Type", Relocation.Type); |
323 | 0 | IO.mapRequired("Index", Relocation.Index); |
324 | 0 | IO.mapRequired("Offset", Relocation.Offset); |
325 | 0 | IO.mapOptional("Addend", Relocation.Addend, 0); |
326 | 0 | } |
327 | | |
328 | | void MappingTraits<WasmYAML::NameEntry>::mapping( |
329 | 0 | IO &IO, WasmYAML::NameEntry &NameEntry) { |
330 | 0 | IO.mapRequired("Index", NameEntry.Index); |
331 | 0 | IO.mapRequired("Name", NameEntry.Name); |
332 | 0 | } |
333 | | |
334 | | void MappingTraits<WasmYAML::ProducerEntry>::mapping( |
335 | 0 | IO &IO, WasmYAML::ProducerEntry &ProducerEntry) { |
336 | 0 | IO.mapRequired("Name", ProducerEntry.Name); |
337 | 0 | IO.mapRequired("Version", ProducerEntry.Version); |
338 | 0 | } |
339 | | |
340 | | void ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix>::enumeration( |
341 | 0 | IO &IO, WasmYAML::FeaturePolicyPrefix &Kind) { |
342 | 0 | #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_FEATURE_PREFIX_##X); |
343 | 0 | ECase(USED); |
344 | 0 | ECase(REQUIRED); |
345 | 0 | ECase(DISALLOWED); |
346 | 0 | #undef ECase |
347 | 0 | } |
348 | | |
349 | | void MappingTraits<WasmYAML::FeatureEntry>::mapping( |
350 | 0 | IO &IO, WasmYAML::FeatureEntry &FeatureEntry) { |
351 | 0 | IO.mapRequired("Prefix", FeatureEntry.Prefix); |
352 | 0 | IO.mapRequired("Name", FeatureEntry.Name); |
353 | 0 | } |
354 | | |
355 | | void MappingTraits<WasmYAML::SegmentInfo>::mapping( |
356 | 0 | IO &IO, WasmYAML::SegmentInfo &SegmentInfo) { |
357 | 0 | IO.mapRequired("Index", SegmentInfo.Index); |
358 | 0 | IO.mapRequired("Name", SegmentInfo.Name); |
359 | 0 | IO.mapRequired("Alignment", SegmentInfo.Alignment); |
360 | 0 | IO.mapRequired("Flags", SegmentInfo.Flags); |
361 | 0 | } |
362 | | |
363 | | void MappingTraits<WasmYAML::LocalDecl>::mapping( |
364 | 0 | IO &IO, WasmYAML::LocalDecl &LocalDecl) { |
365 | 0 | IO.mapRequired("Type", LocalDecl.Type); |
366 | 0 | IO.mapRequired("Count", LocalDecl.Count); |
367 | 0 | } |
368 | | |
369 | | void MappingTraits<WasmYAML::Limits>::mapping(IO &IO, |
370 | 0 | WasmYAML::Limits &Limits) { |
371 | 0 | IO.mapOptional("Flags", Limits.Flags, 0); |
372 | 0 | IO.mapRequired("Minimum", Limits.Minimum); |
373 | 0 | if (!IO.outputting() || Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) |
374 | 0 | IO.mapOptional("Maximum", Limits.Maximum); |
375 | 0 | } |
376 | | |
377 | | void MappingTraits<WasmYAML::ElemSegment>::mapping( |
378 | 0 | IO &IO, WasmYAML::ElemSegment &Segment) { |
379 | 0 | IO.mapOptional("Flags", Segment.Flags, 0); |
380 | 0 | if (!IO.outputting() || |
381 | 0 | Segment.Flags & wasm::WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER) |
382 | 0 | IO.mapOptional("TableNumber", Segment.TableNumber); |
383 | 0 | if (!IO.outputting() || |
384 | 0 | Segment.Flags & wasm::WASM_ELEM_SEGMENT_MASK_HAS_ELEM_KIND) |
385 | 0 | IO.mapOptional("ElemKind", Segment.ElemKind); |
386 | 0 | IO.mapRequired("Offset", Segment.Offset); |
387 | 0 | IO.mapRequired("Functions", Segment.Functions); |
388 | 0 | } |
389 | | |
390 | | void MappingTraits<WasmYAML::Import>::mapping(IO &IO, |
391 | 0 | WasmYAML::Import &Import) { |
392 | 0 | IO.mapRequired("Module", Import.Module); |
393 | 0 | IO.mapRequired("Field", Import.Field); |
394 | 0 | IO.mapRequired("Kind", Import.Kind); |
395 | 0 | if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION || |
396 | 0 | Import.Kind == wasm::WASM_EXTERNAL_TAG) { |
397 | 0 | IO.mapRequired("SigIndex", Import.SigIndex); |
398 | 0 | } else if (Import.Kind == wasm::WASM_EXTERNAL_GLOBAL) { |
399 | 0 | IO.mapRequired("GlobalType", Import.GlobalImport.Type); |
400 | 0 | IO.mapRequired("GlobalMutable", Import.GlobalImport.Mutable); |
401 | 0 | } else if (Import.Kind == wasm::WASM_EXTERNAL_TABLE) { |
402 | 0 | IO.mapRequired("Table", Import.TableImport); |
403 | 0 | } else if (Import.Kind == wasm::WASM_EXTERNAL_MEMORY) { |
404 | 0 | IO.mapRequired("Memory", Import.Memory); |
405 | 0 | } else { |
406 | 0 | llvm_unreachable("unhandled import type"); |
407 | 0 | } |
408 | 0 | } |
409 | | |
410 | | void MappingTraits<WasmYAML::Export>::mapping(IO &IO, |
411 | 0 | WasmYAML::Export &Export) { |
412 | 0 | IO.mapRequired("Name", Export.Name); |
413 | 0 | IO.mapRequired("Kind", Export.Kind); |
414 | 0 | IO.mapRequired("Index", Export.Index); |
415 | 0 | } |
416 | | |
417 | | void MappingTraits<WasmYAML::Global>::mapping(IO &IO, |
418 | 0 | WasmYAML::Global &Global) { |
419 | 0 | IO.mapRequired("Index", Global.Index); |
420 | 0 | IO.mapRequired("Type", Global.Type); |
421 | 0 | IO.mapRequired("Mutable", Global.Mutable); |
422 | 0 | IO.mapRequired("InitExpr", Global.Init); |
423 | 0 | } |
424 | | |
425 | | void MappingTraits<WasmYAML::InitExpr>::mapping(IO &IO, |
426 | 0 | WasmYAML::InitExpr &Expr) { |
427 | 0 | IO.mapOptional("Extended", Expr.Extended, false); |
428 | 0 | if (Expr.Extended) { |
429 | 0 | IO.mapRequired("Body", Expr.Body); |
430 | 0 | } else { |
431 | 0 | WasmYAML::Opcode Op = Expr.Inst.Opcode; |
432 | 0 | IO.mapRequired("Opcode", Op); |
433 | 0 | Expr.Inst.Opcode = Op; |
434 | 0 | switch (Expr.Inst.Opcode) { |
435 | 0 | case wasm::WASM_OPCODE_I32_CONST: |
436 | 0 | IO.mapRequired("Value", Expr.Inst.Value.Int32); |
437 | 0 | break; |
438 | 0 | case wasm::WASM_OPCODE_I64_CONST: |
439 | 0 | IO.mapRequired("Value", Expr.Inst.Value.Int64); |
440 | 0 | break; |
441 | 0 | case wasm::WASM_OPCODE_F32_CONST: |
442 | 0 | IO.mapRequired("Value", Expr.Inst.Value.Float32); |
443 | 0 | break; |
444 | 0 | case wasm::WASM_OPCODE_F64_CONST: |
445 | 0 | IO.mapRequired("Value", Expr.Inst.Value.Float64); |
446 | 0 | break; |
447 | 0 | case wasm::WASM_OPCODE_GLOBAL_GET: |
448 | 0 | IO.mapRequired("Index", Expr.Inst.Value.Global); |
449 | 0 | break; |
450 | 0 | case wasm::WASM_OPCODE_REF_NULL: { |
451 | 0 | WasmYAML::ValueType Ty = wasm::WASM_TYPE_EXTERNREF; |
452 | 0 | IO.mapRequired("Type", Ty); |
453 | 0 | break; |
454 | 0 | } |
455 | 0 | } |
456 | 0 | } |
457 | 0 | } |
458 | | |
459 | | void MappingTraits<WasmYAML::DataSegment>::mapping( |
460 | 0 | IO &IO, WasmYAML::DataSegment &Segment) { |
461 | 0 | IO.mapOptional("SectionOffset", Segment.SectionOffset); |
462 | 0 | IO.mapRequired("InitFlags", Segment.InitFlags); |
463 | 0 | if (Segment.InitFlags & wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX) { |
464 | 0 | IO.mapRequired("MemoryIndex", Segment.MemoryIndex); |
465 | 0 | } else { |
466 | 0 | Segment.MemoryIndex = 0; |
467 | 0 | } |
468 | 0 | if ((Segment.InitFlags & wasm::WASM_DATA_SEGMENT_IS_PASSIVE) == 0) { |
469 | 0 | IO.mapRequired("Offset", Segment.Offset); |
470 | 0 | } else { |
471 | 0 | Segment.Offset.Inst.Opcode = wasm::WASM_OPCODE_I32_CONST; |
472 | 0 | Segment.Offset.Inst.Value.Int32 = 0; |
473 | 0 | } |
474 | 0 | IO.mapRequired("Content", Segment.Content); |
475 | 0 | } |
476 | | |
477 | | void MappingTraits<WasmYAML::InitFunction>::mapping( |
478 | 0 | IO &IO, WasmYAML::InitFunction &Init) { |
479 | 0 | IO.mapRequired("Priority", Init.Priority); |
480 | 0 | IO.mapRequired("Symbol", Init.Symbol); |
481 | 0 | } |
482 | | |
483 | | void ScalarEnumerationTraits<WasmYAML::ComdatKind>::enumeration( |
484 | 0 | IO &IO, WasmYAML::ComdatKind &Kind) { |
485 | 0 | #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_COMDAT_##X); |
486 | 0 | ECase(FUNCTION); |
487 | 0 | ECase(DATA); |
488 | 0 | ECase(SECTION); |
489 | 0 | #undef ECase |
490 | 0 | } |
491 | | |
492 | | void MappingTraits<WasmYAML::ComdatEntry>::mapping( |
493 | 0 | IO &IO, WasmYAML::ComdatEntry &ComdatEntry) { |
494 | 0 | IO.mapRequired("Kind", ComdatEntry.Kind); |
495 | 0 | IO.mapRequired("Index", ComdatEntry.Index); |
496 | 0 | } |
497 | | |
498 | | void MappingTraits<WasmYAML::Comdat>::mapping(IO &IO, |
499 | 0 | WasmYAML::Comdat &Comdat) { |
500 | 0 | IO.mapRequired("Name", Comdat.Name); |
501 | 0 | IO.mapRequired("Entries", Comdat.Entries); |
502 | 0 | } |
503 | | |
504 | | void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO, |
505 | 0 | WasmYAML::SymbolInfo &Info) { |
506 | 0 | IO.mapRequired("Index", Info.Index); |
507 | 0 | IO.mapRequired("Kind", Info.Kind); |
508 | 0 | if (Info.Kind != wasm::WASM_SYMBOL_TYPE_SECTION) |
509 | 0 | IO.mapRequired("Name", Info.Name); |
510 | 0 | IO.mapRequired("Flags", Info.Flags); |
511 | 0 | if (Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION) { |
512 | 0 | IO.mapRequired("Function", Info.ElementIndex); |
513 | 0 | } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL) { |
514 | 0 | IO.mapRequired("Global", Info.ElementIndex); |
515 | 0 | } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_TABLE) { |
516 | 0 | IO.mapRequired("Table", Info.ElementIndex); |
517 | 0 | } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_TAG) { |
518 | 0 | IO.mapRequired("Tag", Info.ElementIndex); |
519 | 0 | } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA) { |
520 | 0 | if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) { |
521 | 0 | if ((Info.Flags & wasm::WASM_SYMBOL_ABSOLUTE) == 0) { |
522 | 0 | IO.mapRequired("Segment", Info.DataRef.Segment); |
523 | 0 | } |
524 | 0 | IO.mapOptional("Offset", Info.DataRef.Offset, 0u); |
525 | 0 | IO.mapRequired("Size", Info.DataRef.Size); |
526 | 0 | } |
527 | 0 | } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION) { |
528 | 0 | IO.mapRequired("Section", Info.ElementIndex); |
529 | 0 | } else { |
530 | 0 | llvm_unreachable("unsupported symbol kind"); |
531 | 0 | } |
532 | 0 | } |
533 | | |
534 | | void MappingTraits<WasmYAML::DylinkImportInfo>::mapping( |
535 | 0 | IO &IO, WasmYAML::DylinkImportInfo &Info) { |
536 | 0 | IO.mapRequired("Module", Info.Module); |
537 | 0 | IO.mapRequired("Field", Info.Field); |
538 | 0 | IO.mapRequired("Flags", Info.Flags); |
539 | 0 | } |
540 | | |
541 | | void MappingTraits<WasmYAML::DylinkExportInfo>::mapping( |
542 | 0 | IO &IO, WasmYAML::DylinkExportInfo &Info) { |
543 | 0 | IO.mapRequired("Name", Info.Name); |
544 | 0 | IO.mapRequired("Flags", Info.Flags); |
545 | 0 | } |
546 | | |
547 | | void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset( |
548 | 0 | IO &IO, WasmYAML::LimitFlags &Value) { |
549 | 0 | #define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X) |
550 | 0 | BCase(HAS_MAX); |
551 | 0 | BCase(IS_SHARED); |
552 | 0 | BCase(IS_64); |
553 | 0 | #undef BCase |
554 | 0 | } |
555 | | |
556 | | void ScalarBitSetTraits<WasmYAML::SegmentFlags>::bitset( |
557 | 0 | IO &IO, WasmYAML::SegmentFlags &Value) { |
558 | 0 | #define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_SEG_FLAG_##X) |
559 | 0 | BCase(STRINGS); |
560 | 0 | BCase(TLS); |
561 | 0 | #undef BCase |
562 | 0 | } |
563 | | |
564 | | void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset( |
565 | 0 | IO &IO, WasmYAML::SymbolFlags &Value) { |
566 | 0 | #define BCaseMask(M, X) \ |
567 | 0 | IO.maskedBitSetCase(Value, #X, wasm::WASM_SYMBOL_##X, wasm::WASM_SYMBOL_##M) |
568 | | // BCaseMask(BINDING_MASK, BINDING_GLOBAL); |
569 | 0 | BCaseMask(BINDING_MASK, BINDING_WEAK); |
570 | 0 | BCaseMask(BINDING_MASK, BINDING_LOCAL); |
571 | | // BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT); |
572 | 0 | BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN); |
573 | 0 | BCaseMask(UNDEFINED, UNDEFINED); |
574 | 0 | BCaseMask(EXPORTED, EXPORTED); |
575 | 0 | BCaseMask(EXPLICIT_NAME, EXPLICIT_NAME); |
576 | 0 | BCaseMask(NO_STRIP, NO_STRIP); |
577 | 0 | BCaseMask(TLS, TLS); |
578 | 0 | BCaseMask(ABSOLUTE, ABSOLUTE); |
579 | 0 | #undef BCaseMask |
580 | 0 | } |
581 | | |
582 | | void ScalarEnumerationTraits<WasmYAML::SymbolKind>::enumeration( |
583 | 0 | IO &IO, WasmYAML::SymbolKind &Kind) { |
584 | 0 | #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_SYMBOL_TYPE_##X); |
585 | 0 | ECase(FUNCTION); |
586 | 0 | ECase(DATA); |
587 | 0 | ECase(GLOBAL); |
588 | 0 | ECase(TABLE); |
589 | 0 | ECase(SECTION); |
590 | 0 | ECase(TAG); |
591 | 0 | #undef ECase |
592 | 0 | } |
593 | | |
594 | | void ScalarEnumerationTraits<WasmYAML::ValueType>::enumeration( |
595 | 0 | IO &IO, WasmYAML::ValueType &Type) { |
596 | 0 | #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X); |
597 | 0 | ECase(I32); |
598 | 0 | ECase(I64); |
599 | 0 | ECase(F32); |
600 | 0 | ECase(F64); |
601 | 0 | ECase(V128); |
602 | 0 | ECase(FUNCREF); |
603 | 0 | ECase(EXTERNREF); |
604 | 0 | ECase(FUNC); |
605 | 0 | #undef ECase |
606 | 0 | } |
607 | | |
608 | | void ScalarEnumerationTraits<WasmYAML::ExportKind>::enumeration( |
609 | 0 | IO &IO, WasmYAML::ExportKind &Kind) { |
610 | 0 | #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_EXTERNAL_##X); |
611 | 0 | ECase(FUNCTION); |
612 | 0 | ECase(TABLE); |
613 | 0 | ECase(MEMORY); |
614 | 0 | ECase(GLOBAL); |
615 | 0 | ECase(TAG); |
616 | 0 | #undef ECase |
617 | 0 | } |
618 | | |
619 | | void ScalarEnumerationTraits<WasmYAML::Opcode>::enumeration( |
620 | 0 | IO &IO, WasmYAML::Opcode &Code) { |
621 | 0 | #define ECase(X) IO.enumCase(Code, #X, wasm::WASM_OPCODE_##X); |
622 | 0 | ECase(END); |
623 | 0 | ECase(I32_CONST); |
624 | 0 | ECase(I64_CONST); |
625 | 0 | ECase(F64_CONST); |
626 | 0 | ECase(F32_CONST); |
627 | 0 | ECase(GLOBAL_GET); |
628 | 0 | ECase(REF_NULL); |
629 | 0 | #undef ECase |
630 | 0 | } |
631 | | |
632 | | void ScalarEnumerationTraits<WasmYAML::TableType>::enumeration( |
633 | 0 | IO &IO, WasmYAML::TableType &Type) { |
634 | 0 | #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X); |
635 | 0 | ECase(FUNCREF); |
636 | 0 | ECase(EXTERNREF); |
637 | 0 | #undef ECase |
638 | 0 | } |
639 | | |
640 | | void ScalarEnumerationTraits<WasmYAML::RelocType>::enumeration( |
641 | 0 | IO &IO, WasmYAML::RelocType &Type) { |
642 | 0 | #define WASM_RELOC(name, value) IO.enumCase(Type, #name, wasm::name); |
643 | 0 | #include "llvm/BinaryFormat/WasmRelocs.def" |
644 | 0 | #undef WASM_RELOC |
645 | 0 | IO.enumFallback<Hex32>(Type); |
646 | 0 | } |
647 | | |
648 | | } // end namespace yaml |
649 | | |
650 | | } // end namespace llvm |