annotate llvm/lib/ObjectYAML/WasmYAML.cpp @ 220:42394fc6a535

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