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