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 Section::~Section() = default; 26 27 } // end namespace WasmYAML 28 29 namespace yaml { 30 31 void MappingTraits<WasmYAML::FileHeader>::mapping( 32 IO &IO, WasmYAML::FileHeader &FileHdr) { 33 IO.mapRequired("Version", FileHdr.Version); 34 } 35 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); 43 } 44 45 static void commonSectionMapping(IO &IO, WasmYAML::Section &Section) { 46 IO.mapRequired("Type", Section.Type); 47 IO.mapOptional("Relocations", Section.Relocations); 48 } 49 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); 58 } 59 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 } 65 66 static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) { 67 commonSectionMapping(IO, Section); 68 IO.mapRequired("Name", Section.Name); 69 IO.mapRequired("Version", Section.Version); 70 IO.mapOptional("SymbolTable", Section.SymbolTable); 71 IO.mapOptional("SegmentInfo", Section.SegmentInfos); 72 IO.mapOptional("InitFunctions", Section.InitFunctions); 73 IO.mapOptional("Comdats", Section.Comdats); 74 } 75 76 static void sectionMapping(IO &IO, WasmYAML::ProducersSection &Section) { 77 commonSectionMapping(IO, Section); 78 IO.mapRequired("Name", Section.Name); 79 IO.mapOptional("Languages", Section.Languages); 80 IO.mapOptional("Tools", Section.Tools); 81 IO.mapOptional("SDKs", Section.SDKs); 82 } 83 84 static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) { 85 commonSectionMapping(IO, Section); 86 IO.mapRequired("Name", Section.Name); 87 IO.mapRequired("Payload", Section.Payload); 88 } 89 90 static void sectionMapping(IO &IO, WasmYAML::TypeSection &Section) { 91 commonSectionMapping(IO, Section); 92 IO.mapOptional("Signatures", Section.Signatures); 93 } 94 95 static void sectionMapping(IO &IO, WasmYAML::ImportSection &Section) { 96 commonSectionMapping(IO, Section); 97 IO.mapOptional("Imports", Section.Imports); 98 } 99 100 static void sectionMapping(IO &IO, WasmYAML::FunctionSection &Section) { 101 commonSectionMapping(IO, Section); 102 IO.mapOptional("FunctionTypes", Section.FunctionTypes); 103 } 104 105 static void sectionMapping(IO &IO, WasmYAML::TableSection &Section) { 106 commonSectionMapping(IO, Section); 107 IO.mapOptional("Tables", Section.Tables); 108 } 109 110 static void sectionMapping(IO &IO, WasmYAML::MemorySection &Section) { 111 commonSectionMapping(IO, Section); 112 IO.mapOptional("Memories", Section.Memories); 113 } 114 115 static void sectionMapping(IO &IO, WasmYAML::GlobalSection &Section) { 116 commonSectionMapping(IO, Section); 117 IO.mapOptional("Globals", Section.Globals); 118 } 119 120 static void sectionMapping(IO &IO, WasmYAML::EventSection &Section) { 121 commonSectionMapping(IO, Section); 122 IO.mapOptional("Events", Section.Events); 123 } 124 125 static void sectionMapping(IO &IO, WasmYAML::ExportSection &Section) { 126 commonSectionMapping(IO, Section); 127 IO.mapOptional("Exports", Section.Exports); 128 } 129 130 static void sectionMapping(IO &IO, WasmYAML::StartSection &Section) { 131 commonSectionMapping(IO, Section); 132 IO.mapOptional("StartFunction", Section.StartFunction); 133 } 134 135 static void sectionMapping(IO &IO, WasmYAML::ElemSection &Section) { 136 commonSectionMapping(IO, Section); 137 IO.mapOptional("Segments", Section.Segments); 138 } 139 140 static void sectionMapping(IO &IO, WasmYAML::CodeSection &Section) { 141 commonSectionMapping(IO, Section); 142 IO.mapRequired("Functions", Section.Functions); 143 } 144 145 static void sectionMapping(IO &IO, WasmYAML::DataSection &Section) { 146 commonSectionMapping(IO, Section); 147 IO.mapRequired("Segments", Section.Segments); 148 } 149 150 void MappingTraits<std::unique_ptr<WasmYAML::Section>>::mapping( 151 IO &IO, std::unique_ptr<WasmYAML::Section> &Section) { 152 WasmYAML::SectionType SectionType; 153 if (IO.outputting()) 154 SectionType = Section->Type; 155 else 156 IO.mapRequired("Type", SectionType); 157 158 switch (SectionType) { 159 case wasm::WASM_SEC_CUSTOM: { 160 StringRef SectionName; 161 if (IO.outputting()) { 162 auto CustomSection = cast<WasmYAML::CustomSection>(Section.get()); 163 SectionName = CustomSection->Name; 164 } else { 165 IO.mapRequired("Name", SectionName); 166 } 167 if (SectionName == "dylink") { 168 if (!IO.outputting()) 169 Section.reset(new WasmYAML::DylinkSection()); 170 sectionMapping(IO, *cast<WasmYAML::DylinkSection>(Section.get())); 171 } else if (SectionName == "linking") { 172 if (!IO.outputting()) 173 Section.reset(new WasmYAML::LinkingSection()); 174 sectionMapping(IO, *cast<WasmYAML::LinkingSection>(Section.get())); 175 } else if (SectionName == "name") { 176 if (!IO.outputting()) 177 Section.reset(new WasmYAML::NameSection()); 178 sectionMapping(IO, *cast<WasmYAML::NameSection>(Section.get())); 179 } else if (SectionName == "producers") { 180 if (!IO.outputting()) 181 Section.reset(new WasmYAML::ProducersSection()); 182 sectionMapping(IO, *cast<WasmYAML::ProducersSection>(Section.get())); 183 } else { 184 if (!IO.outputting()) 185 Section.reset(new WasmYAML::CustomSection(SectionName)); 186 sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get())); 187 } 188 break; 189 } 190 case wasm::WASM_SEC_TYPE: 191 if (!IO.outputting()) 192 Section.reset(new WasmYAML::TypeSection()); 193 sectionMapping(IO, *cast<WasmYAML::TypeSection>(Section.get())); 194 break; 195 case wasm::WASM_SEC_IMPORT: 196 if (!IO.outputting()) 197 Section.reset(new WasmYAML::ImportSection()); 198 sectionMapping(IO, *cast<WasmYAML::ImportSection>(Section.get())); 199 break; 200 case wasm::WASM_SEC_FUNCTION: 201 if (!IO.outputting()) 202 Section.reset(new WasmYAML::FunctionSection()); 203 sectionMapping(IO, *cast<WasmYAML::FunctionSection>(Section.get())); 204 break; 205 case wasm::WASM_SEC_TABLE: 206 if (!IO.outputting()) 207 Section.reset(new WasmYAML::TableSection()); 208 sectionMapping(IO, *cast<WasmYAML::TableSection>(Section.get())); 209 break; 210 case wasm::WASM_SEC_MEMORY: 211 if (!IO.outputting()) 212 Section.reset(new WasmYAML::MemorySection()); 213 sectionMapping(IO, *cast<WasmYAML::MemorySection>(Section.get())); 214 break; 215 case wasm::WASM_SEC_GLOBAL: 216 if (!IO.outputting()) 217 Section.reset(new WasmYAML::GlobalSection()); 218 sectionMapping(IO, *cast<WasmYAML::GlobalSection>(Section.get())); 219 break; 220 case wasm::WASM_SEC_EVENT: 221 if (!IO.outputting()) 222 Section.reset(new WasmYAML::EventSection()); 223 sectionMapping(IO, *cast<WasmYAML::EventSection>(Section.get())); 224 break; 225 case wasm::WASM_SEC_EXPORT: 226 if (!IO.outputting()) 227 Section.reset(new WasmYAML::ExportSection()); 228 sectionMapping(IO, *cast<WasmYAML::ExportSection>(Section.get())); 229 break; 230 case wasm::WASM_SEC_START: 231 if (!IO.outputting()) 232 Section.reset(new WasmYAML::StartSection()); 233 sectionMapping(IO, *cast<WasmYAML::StartSection>(Section.get())); 234 break; 235 case wasm::WASM_SEC_ELEM: 236 if (!IO.outputting()) 237 Section.reset(new WasmYAML::ElemSection()); 238 sectionMapping(IO, *cast<WasmYAML::ElemSection>(Section.get())); 239 break; 240 case wasm::WASM_SEC_CODE: 241 if (!IO.outputting()) 242 Section.reset(new WasmYAML::CodeSection()); 243 sectionMapping(IO, *cast<WasmYAML::CodeSection>(Section.get())); 244 break; 245 case wasm::WASM_SEC_DATA: 246 if (!IO.outputting()) 247 Section.reset(new WasmYAML::DataSection()); 248 sectionMapping(IO, *cast<WasmYAML::DataSection>(Section.get())); 249 break; 250 default: 251 llvm_unreachable("Unknown section type"); 252 } 253 } 254 255 void ScalarEnumerationTraits<WasmYAML::SectionType>::enumeration( 256 IO &IO, WasmYAML::SectionType &Type) { 257 #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_SEC_##X); 258 ECase(CUSTOM); 259 ECase(TYPE); 260 ECase(IMPORT); 261 ECase(FUNCTION); 262 ECase(TABLE); 263 ECase(MEMORY); 264 ECase(GLOBAL); 265 ECase(EVENT); 266 ECase(EXPORT); 267 ECase(START); 268 ECase(ELEM); 269 ECase(CODE); 270 ECase(DATA); 271 #undef ECase 272 } 273 274 void MappingTraits<WasmYAML::Signature>::mapping( 275 IO &IO, WasmYAML::Signature &Signature) { 276 IO.mapRequired("Index", Signature.Index); 277 IO.mapRequired("ReturnType", Signature.ReturnType); 278 IO.mapRequired("ParamTypes", Signature.ParamTypes); 279 } 280 281 void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) { 282 IO.mapRequired("ElemType", Table.ElemType); 283 IO.mapRequired("Limits", Table.TableLimits); 284 } 285 286 void MappingTraits<WasmYAML::Function>::mapping(IO &IO, 287 WasmYAML::Function &Function) { 288 IO.mapRequired("Index", Function.Index); 289 IO.mapRequired("Locals", Function.Locals); 290 IO.mapRequired("Body", Function.Body); 291 } 292 293 void MappingTraits<WasmYAML::Relocation>::mapping( 294 IO &IO, WasmYAML::Relocation &Relocation) { 295 IO.mapRequired("Type", Relocation.Type); 296 IO.mapRequired("Index", Relocation.Index); 297 IO.mapRequired("Offset", Relocation.Offset); 298 IO.mapOptional("Addend", Relocation.Addend, 0); 299 } 300 301 void MappingTraits<WasmYAML::NameEntry>::mapping( 302 IO &IO, WasmYAML::NameEntry &NameEntry) { 303 IO.mapRequired("Index", NameEntry.Index); 304 IO.mapRequired("Name", NameEntry.Name); 305 } 306 307 void MappingTraits<WasmYAML::ProducerEntry>::mapping( 308 IO &IO, WasmYAML::ProducerEntry &ProducerEntry) { 309 IO.mapRequired("Name", ProducerEntry.Name); 310 IO.mapRequired("Version", ProducerEntry.Version); 311 } 312 313 void MappingTraits<WasmYAML::SegmentInfo>::mapping( 314 IO &IO, WasmYAML::SegmentInfo &SegmentInfo) { 315 IO.mapRequired("Index", SegmentInfo.Index); 316 IO.mapRequired("Name", SegmentInfo.Name); 317 IO.mapRequired("Alignment", SegmentInfo.Alignment); 318 IO.mapRequired("Flags", SegmentInfo.Flags); 319 } 320 321 void MappingTraits<WasmYAML::LocalDecl>::mapping( 322 IO &IO, WasmYAML::LocalDecl &LocalDecl) { 323 IO.mapRequired("Type", LocalDecl.Type); 324 IO.mapRequired("Count", LocalDecl.Count); 325 } 326 327 void MappingTraits<WasmYAML::Limits>::mapping(IO &IO, 328 WasmYAML::Limits &Limits) { 329 if (!IO.outputting() || Limits.Flags) 330 IO.mapOptional("Flags", Limits.Flags); 331 IO.mapRequired("Initial", Limits.Initial); 332 if (!IO.outputting() || Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) 333 IO.mapOptional("Maximum", Limits.Maximum); 334 } 335 336 void MappingTraits<WasmYAML::ElemSegment>::mapping( 337 IO &IO, WasmYAML::ElemSegment &Segment) { 338 IO.mapRequired("Offset", Segment.Offset); 339 IO.mapRequired("Functions", Segment.Functions); 340 } 341 342 void MappingTraits<WasmYAML::Import>::mapping(IO &IO, 343 WasmYAML::Import &Import) { 344 IO.mapRequired("Module", Import.Module); 345 IO.mapRequired("Field", Import.Field); 346 IO.mapRequired("Kind", Import.Kind); 347 if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION) { 348 IO.mapRequired("SigIndex", Import.SigIndex); 349 } else if (Import.Kind == wasm::WASM_EXTERNAL_GLOBAL) { 350 IO.mapRequired("GlobalType", Import.GlobalImport.Type); 351 IO.mapRequired("GlobalMutable", Import.GlobalImport.Mutable); 352 } else if (Import.Kind == wasm::WASM_EXTERNAL_EVENT) { 353 IO.mapRequired("EventAttribute", Import.EventImport.Attribute); 354 IO.mapRequired("EventSigIndex", Import.EventImport.SigIndex); 355 } else if (Import.Kind == wasm::WASM_EXTERNAL_TABLE) { 356 IO.mapRequired("Table", Import.TableImport); 357 } else if (Import.Kind == wasm::WASM_EXTERNAL_MEMORY) { 358 IO.mapRequired("Memory", Import.Memory); 359 } else { 360 llvm_unreachable("unhandled import type"); 361 } 362 } 363 364 void MappingTraits<WasmYAML::Export>::mapping(IO &IO, 365 WasmYAML::Export &Export) { 366 IO.mapRequired("Name", Export.Name); 367 IO.mapRequired("Kind", Export.Kind); 368 IO.mapRequired("Index", Export.Index); 369 } 370 371 void MappingTraits<WasmYAML::Global>::mapping(IO &IO, 372 WasmYAML::Global &Global) { 373 IO.mapRequired("Index", Global.Index); 374 IO.mapRequired("Type", Global.Type); 375 IO.mapRequired("Mutable", Global.Mutable); 376 IO.mapRequired("InitExpr", Global.InitExpr); 377 } 378 379 void MappingTraits<wasm::WasmInitExpr>::mapping(IO &IO, 380 wasm::WasmInitExpr &Expr) { 381 WasmYAML::Opcode Op = Expr.Opcode; 382 IO.mapRequired("Opcode", Op); 383 Expr.Opcode = Op; 384 switch (Expr.Opcode) { 385 case wasm::WASM_OPCODE_I32_CONST: 386 IO.mapRequired("Value", Expr.Value.Int32); 387 break; 388 case wasm::WASM_OPCODE_I64_CONST: 389 IO.mapRequired("Value", Expr.Value.Int64); 390 break; 391 case wasm::WASM_OPCODE_F32_CONST: 392 IO.mapRequired("Value", Expr.Value.Float32); 393 break; 394 case wasm::WASM_OPCODE_F64_CONST: 395 IO.mapRequired("Value", Expr.Value.Float64); 396 break; 397 case wasm::WASM_OPCODE_GLOBAL_GET: 398 IO.mapRequired("Index", Expr.Value.Global); 399 break; 400 } 401 } 402 403 void MappingTraits<WasmYAML::DataSegment>::mapping( 404 IO &IO, WasmYAML::DataSegment &Segment) { 405 IO.mapOptional("SectionOffset", Segment.SectionOffset); 406 IO.mapRequired("InitFlags", Segment.InitFlags); 407 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX) { 408 IO.mapRequired("MemoryIndex", Segment.MemoryIndex); 409 } else { 410 Segment.MemoryIndex = 0; 411 } 412 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) { 413 IO.mapRequired("Offset", Segment.Offset); 414 } else { 415 Segment.Offset.Opcode = wasm::WASM_OPCODE_I32_CONST; 416 Segment.Offset.Value.Int32 = 0; 417 } 418 IO.mapRequired("Content", Segment.Content); 419 } 420 421 void MappingTraits<WasmYAML::InitFunction>::mapping( 422 IO &IO, WasmYAML::InitFunction &Init) { 423 IO.mapRequired("Priority", Init.Priority); 424 IO.mapRequired("Symbol", Init.Symbol); 425 } 426 427 void ScalarEnumerationTraits<WasmYAML::ComdatKind>::enumeration( 428 IO &IO, WasmYAML::ComdatKind &Kind) { 429 #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_COMDAT_##X); 430 ECase(FUNCTION); 431 ECase(DATA); 432 #undef ECase 433 } 434 435 void MappingTraits<WasmYAML::ComdatEntry>::mapping( 436 IO &IO, WasmYAML::ComdatEntry &ComdatEntry) { 437 IO.mapRequired("Kind", ComdatEntry.Kind); 438 IO.mapRequired("Index", ComdatEntry.Index); 439 } 440 441 void MappingTraits<WasmYAML::Comdat>::mapping(IO &IO, 442 WasmYAML::Comdat &Comdat) { 443 IO.mapRequired("Name", Comdat.Name); 444 IO.mapRequired("Entries", Comdat.Entries); 445 } 446 447 void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO, 448 WasmYAML::SymbolInfo &Info) { 449 IO.mapRequired("Index", Info.Index); 450 IO.mapRequired("Kind", Info.Kind); 451 IO.mapRequired("Name", Info.Name); 452 IO.mapRequired("Flags", Info.Flags); 453 if (Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION) { 454 IO.mapRequired("Function", Info.ElementIndex); 455 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL) { 456 IO.mapRequired("Global", Info.ElementIndex); 457 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_EVENT) { 458 IO.mapRequired("Event", Info.ElementIndex); 459 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA) { 460 if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) { 461 IO.mapRequired("Segment", Info.DataRef.Segment); 462 IO.mapOptional("Offset", Info.DataRef.Offset, 0u); 463 IO.mapRequired("Size", Info.DataRef.Size); 464 } 465 } else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION) { 466 IO.mapRequired("Section", Info.ElementIndex); 467 } else { 468 llvm_unreachable("unsupported symbol kind"); 469 } 470 } 471 472 void MappingTraits<WasmYAML::Event>::mapping(IO &IO, WasmYAML::Event &Event) { 473 IO.mapRequired("Index", Event.Index); 474 IO.mapRequired("Attribute", Event.Attribute); 475 IO.mapRequired("SigIndex", Event.SigIndex); 476 } 477 478 void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset( 479 IO &IO, WasmYAML::LimitFlags &Value) { 480 #define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X) 481 BCase(HAS_MAX); 482 BCase(IS_SHARED); 483 #undef BCase 484 } 485 486 void ScalarBitSetTraits<WasmYAML::SegmentFlags>::bitset( 487 IO &IO, WasmYAML::SegmentFlags &Value) {} 488 489 void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset( 490 IO &IO, WasmYAML::SymbolFlags &Value) { 491 #define BCaseMask(M, X) \ 492 IO.maskedBitSetCase(Value, #X, wasm::WASM_SYMBOL_##X, wasm::WASM_SYMBOL_##M) 493 // BCaseMask(BINDING_MASK, BINDING_GLOBAL); 494 BCaseMask(BINDING_MASK, BINDING_WEAK); 495 BCaseMask(BINDING_MASK, BINDING_LOCAL); 496 // BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT); 497 BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN); 498 BCaseMask(UNDEFINED, UNDEFINED); 499 BCaseMask(EXPORTED, EXPORTED); 500 #undef BCaseMask 501 } 502 503 void ScalarEnumerationTraits<WasmYAML::SymbolKind>::enumeration( 504 IO &IO, WasmYAML::SymbolKind &Kind) { 505 #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_SYMBOL_TYPE_##X); 506 ECase(FUNCTION); 507 ECase(DATA); 508 ECase(GLOBAL); 509 ECase(SECTION); 510 ECase(EVENT); 511 #undef ECase 512 } 513 514 void ScalarEnumerationTraits<WasmYAML::ValueType>::enumeration( 515 IO &IO, WasmYAML::ValueType &Type) { 516 #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X); 517 ECase(I32); 518 ECase(I64); 519 ECase(F32); 520 ECase(F64); 521 ECase(V128); 522 ECase(FUNCREF); 523 ECase(FUNC); 524 ECase(NORESULT); 525 #undef ECase 526 } 527 528 void ScalarEnumerationTraits<WasmYAML::ExportKind>::enumeration( 529 IO &IO, WasmYAML::ExportKind &Kind) { 530 #define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_EXTERNAL_##X); 531 ECase(FUNCTION); 532 ECase(TABLE); 533 ECase(MEMORY); 534 ECase(GLOBAL); 535 ECase(EVENT); 536 #undef ECase 537 } 538 539 void ScalarEnumerationTraits<WasmYAML::Opcode>::enumeration( 540 IO &IO, WasmYAML::Opcode &Code) { 541 #define ECase(X) IO.enumCase(Code, #X, wasm::WASM_OPCODE_##X); 542 ECase(END); 543 ECase(I32_CONST); 544 ECase(I64_CONST); 545 ECase(F64_CONST); 546 ECase(F32_CONST); 547 ECase(GLOBAL_GET); 548 #undef ECase 549 } 550 551 void ScalarEnumerationTraits<WasmYAML::TableType>::enumeration( 552 IO &IO, WasmYAML::TableType &Type) { 553 #define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X); 554 ECase(FUNCREF); 555 #undef ECase 556 } 557 558 void ScalarEnumerationTraits<WasmYAML::RelocType>::enumeration( 559 IO &IO, WasmYAML::RelocType &Type) { 560 #define WASM_RELOC(name, value) IO.enumCase(Type, #name, wasm::name); 561 #include "llvm/BinaryFormat/WasmRelocs.def" 562 #undef WASM_RELOC 563 } 564 565 } // end namespace yaml 566 567 } // end namespace llvm 568