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