Path: blob/main/contrib/llvm-project/llvm/lib/ObjectYAML/WasmYAML.cpp
35233 views
//===- WasmYAML.cpp - Wasm YAMLIO implementation --------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines classes for handling the YAML representation of wasm.9//10//===----------------------------------------------------------------------===//1112#include "llvm/ObjectYAML/WasmYAML.h"13#include "llvm/ADT/StringRef.h"14#include "llvm/BinaryFormat/Wasm.h"15#include "llvm/Support/Casting.h"16#include "llvm/Support/ErrorHandling.h"17#include "llvm/Support/YAMLTraits.h"1819namespace llvm {2021namespace WasmYAML {2223// 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-headers25Section::~Section() = default;2627} // end namespace WasmYAML2829namespace yaml {3031void MappingTraits<WasmYAML::FileHeader>::mapping(32IO &IO, WasmYAML::FileHeader &FileHdr) {33IO.mapRequired("Version", FileHdr.Version);34}3536void MappingTraits<WasmYAML::Object>::mapping(IO &IO,37WasmYAML::Object &Object) {38IO.setContext(&Object);39IO.mapTag("!WASM", true);40IO.mapRequired("FileHeader", Object.Header);41IO.mapOptional("Sections", Object.Sections);42IO.setContext(nullptr);43}4445static void commonSectionMapping(IO &IO, WasmYAML::Section &Section) {46IO.mapRequired("Type", Section.Type);47IO.mapOptional("Relocations", Section.Relocations);48IO.mapOptional("HeaderSecSizeEncodingLen", Section.HeaderSecSizeEncodingLen);49}5051static void sectionMapping(IO &IO, WasmYAML::DylinkSection &Section) {52commonSectionMapping(IO, Section);53IO.mapRequired("Name", Section.Name);54IO.mapRequired("MemorySize", Section.MemorySize);55IO.mapRequired("MemoryAlignment", Section.MemoryAlignment);56IO.mapRequired("TableSize", Section.TableSize);57IO.mapRequired("TableAlignment", Section.TableAlignment);58IO.mapRequired("Needed", Section.Needed);59IO.mapOptional("ImportInfo", Section.ImportInfo);60IO.mapOptional("ExportInfo", Section.ExportInfo);61}6263static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) {64commonSectionMapping(IO, Section);65IO.mapRequired("Name", Section.Name);66IO.mapOptional("FunctionNames", Section.FunctionNames);67IO.mapOptional("GlobalNames", Section.GlobalNames);68IO.mapOptional("DataSegmentNames", Section.DataSegmentNames);69}7071static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) {72commonSectionMapping(IO, Section);73IO.mapRequired("Name", Section.Name);74IO.mapRequired("Version", Section.Version);75IO.mapOptional("SymbolTable", Section.SymbolTable);76IO.mapOptional("SegmentInfo", Section.SegmentInfos);77IO.mapOptional("InitFunctions", Section.InitFunctions);78IO.mapOptional("Comdats", Section.Comdats);79}8081static void sectionMapping(IO &IO, WasmYAML::ProducersSection &Section) {82commonSectionMapping(IO, Section);83IO.mapRequired("Name", Section.Name);84IO.mapOptional("Languages", Section.Languages);85IO.mapOptional("Tools", Section.Tools);86IO.mapOptional("SDKs", Section.SDKs);87}8889static void sectionMapping(IO &IO, WasmYAML::TargetFeaturesSection &Section) {90commonSectionMapping(IO, Section);91IO.mapRequired("Name", Section.Name);92IO.mapRequired("Features", Section.Features);93}9495static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) {96commonSectionMapping(IO, Section);97IO.mapRequired("Name", Section.Name);98IO.mapRequired("Payload", Section.Payload);99}100101static void sectionMapping(IO &IO, WasmYAML::TypeSection &Section) {102commonSectionMapping(IO, Section);103IO.mapOptional("Signatures", Section.Signatures);104}105106static void sectionMapping(IO &IO, WasmYAML::ImportSection &Section) {107commonSectionMapping(IO, Section);108IO.mapOptional("Imports", Section.Imports);109}110111static void sectionMapping(IO &IO, WasmYAML::FunctionSection &Section) {112commonSectionMapping(IO, Section);113IO.mapOptional("FunctionTypes", Section.FunctionTypes);114}115116static void sectionMapping(IO &IO, WasmYAML::TableSection &Section) {117commonSectionMapping(IO, Section);118IO.mapOptional("Tables", Section.Tables);119}120121static void sectionMapping(IO &IO, WasmYAML::MemorySection &Section) {122commonSectionMapping(IO, Section);123IO.mapOptional("Memories", Section.Memories);124}125126static void sectionMapping(IO &IO, WasmYAML::TagSection &Section) {127commonSectionMapping(IO, Section);128IO.mapOptional("TagTypes", Section.TagTypes);129}130131static void sectionMapping(IO &IO, WasmYAML::GlobalSection &Section) {132commonSectionMapping(IO, Section);133IO.mapOptional("Globals", Section.Globals);134}135136static void sectionMapping(IO &IO, WasmYAML::ExportSection &Section) {137commonSectionMapping(IO, Section);138IO.mapOptional("Exports", Section.Exports);139}140141static void sectionMapping(IO &IO, WasmYAML::StartSection &Section) {142commonSectionMapping(IO, Section);143IO.mapOptional("StartFunction", Section.StartFunction);144}145146static void sectionMapping(IO &IO, WasmYAML::ElemSection &Section) {147commonSectionMapping(IO, Section);148IO.mapOptional("Segments", Section.Segments);149}150151static void sectionMapping(IO &IO, WasmYAML::CodeSection &Section) {152commonSectionMapping(IO, Section);153IO.mapRequired("Functions", Section.Functions);154}155156static void sectionMapping(IO &IO, WasmYAML::DataSection &Section) {157commonSectionMapping(IO, Section);158IO.mapRequired("Segments", Section.Segments);159}160161static void sectionMapping(IO &IO, WasmYAML::DataCountSection &Section) {162commonSectionMapping(IO, Section);163IO.mapRequired("Count", Section.Count);164}165166void MappingTraits<std::unique_ptr<WasmYAML::Section>>::mapping(167IO &IO, std::unique_ptr<WasmYAML::Section> &Section) {168WasmYAML::SectionType SectionType;169if (IO.outputting())170SectionType = Section->Type;171else172IO.mapRequired("Type", SectionType);173174switch (SectionType) {175case wasm::WASM_SEC_CUSTOM: {176StringRef SectionName;177if (IO.outputting()) {178auto CustomSection = cast<WasmYAML::CustomSection>(Section.get());179SectionName = CustomSection->Name;180} else {181IO.mapRequired("Name", SectionName);182}183if (SectionName == "dylink" || SectionName == "dylink.0") {184if (!IO.outputting())185Section.reset(new WasmYAML::DylinkSection());186sectionMapping(IO, *cast<WasmYAML::DylinkSection>(Section.get()));187} else if (SectionName == "linking") {188if (!IO.outputting())189Section.reset(new WasmYAML::LinkingSection());190sectionMapping(IO, *cast<WasmYAML::LinkingSection>(Section.get()));191} else if (SectionName == "name") {192if (!IO.outputting())193Section.reset(new WasmYAML::NameSection());194sectionMapping(IO, *cast<WasmYAML::NameSection>(Section.get()));195} else if (SectionName == "producers") {196if (!IO.outputting())197Section.reset(new WasmYAML::ProducersSection());198sectionMapping(IO, *cast<WasmYAML::ProducersSection>(Section.get()));199} else if (SectionName == "target_features") {200if (!IO.outputting())201Section.reset(new WasmYAML::TargetFeaturesSection());202sectionMapping(IO, *cast<WasmYAML::TargetFeaturesSection>(Section.get()));203} else {204if (!IO.outputting())205Section.reset(new WasmYAML::CustomSection(SectionName));206sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get()));207}208break;209}210case wasm::WASM_SEC_TYPE:211if (!IO.outputting())212Section.reset(new WasmYAML::TypeSection());213sectionMapping(IO, *cast<WasmYAML::TypeSection>(Section.get()));214break;215case wasm::WASM_SEC_IMPORT:216if (!IO.outputting())217Section.reset(new WasmYAML::ImportSection());218sectionMapping(IO, *cast<WasmYAML::ImportSection>(Section.get()));219break;220case wasm::WASM_SEC_FUNCTION:221if (!IO.outputting())222Section.reset(new WasmYAML::FunctionSection());223sectionMapping(IO, *cast<WasmYAML::FunctionSection>(Section.get()));224break;225case wasm::WASM_SEC_TABLE:226if (!IO.outputting())227Section.reset(new WasmYAML::TableSection());228sectionMapping(IO, *cast<WasmYAML::TableSection>(Section.get()));229break;230case wasm::WASM_SEC_MEMORY:231if (!IO.outputting())232Section.reset(new WasmYAML::MemorySection());233sectionMapping(IO, *cast<WasmYAML::MemorySection>(Section.get()));234break;235case wasm::WASM_SEC_TAG:236if (!IO.outputting())237Section.reset(new WasmYAML::TagSection());238sectionMapping(IO, *cast<WasmYAML::TagSection>(Section.get()));239break;240case wasm::WASM_SEC_GLOBAL:241if (!IO.outputting())242Section.reset(new WasmYAML::GlobalSection());243sectionMapping(IO, *cast<WasmYAML::GlobalSection>(Section.get()));244break;245case wasm::WASM_SEC_EXPORT:246if (!IO.outputting())247Section.reset(new WasmYAML::ExportSection());248sectionMapping(IO, *cast<WasmYAML::ExportSection>(Section.get()));249break;250case wasm::WASM_SEC_START:251if (!IO.outputting())252Section.reset(new WasmYAML::StartSection());253sectionMapping(IO, *cast<WasmYAML::StartSection>(Section.get()));254break;255case wasm::WASM_SEC_ELEM:256if (!IO.outputting())257Section.reset(new WasmYAML::ElemSection());258sectionMapping(IO, *cast<WasmYAML::ElemSection>(Section.get()));259break;260case wasm::WASM_SEC_CODE:261if (!IO.outputting())262Section.reset(new WasmYAML::CodeSection());263sectionMapping(IO, *cast<WasmYAML::CodeSection>(Section.get()));264break;265case wasm::WASM_SEC_DATA:266if (!IO.outputting())267Section.reset(new WasmYAML::DataSection());268sectionMapping(IO, *cast<WasmYAML::DataSection>(Section.get()));269break;270case wasm::WASM_SEC_DATACOUNT:271if (!IO.outputting())272Section.reset(new WasmYAML::DataCountSection());273sectionMapping(IO, *cast<WasmYAML::DataCountSection>(Section.get()));274break;275default:276llvm_unreachable("Unknown section type");277}278}279280void ScalarEnumerationTraits<WasmYAML::SectionType>::enumeration(281IO &IO, WasmYAML::SectionType &Type) {282#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_SEC_##X);283ECase(CUSTOM);284ECase(TYPE);285ECase(IMPORT);286ECase(FUNCTION);287ECase(TABLE);288ECase(MEMORY);289ECase(GLOBAL);290ECase(TAG);291ECase(EXPORT);292ECase(START);293ECase(ELEM);294ECase(CODE);295ECase(DATA);296ECase(DATACOUNT);297#undef ECase298}299300void MappingTraits<WasmYAML::Signature>::mapping(301IO &IO, WasmYAML::Signature &Signature) {302IO.mapRequired("Index", Signature.Index);303IO.mapRequired("ParamTypes", Signature.ParamTypes);304IO.mapRequired("ReturnTypes", Signature.ReturnTypes);305}306307void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) {308IO.mapRequired("Index", Table.Index);309IO.mapRequired("ElemType", Table.ElemType);310IO.mapRequired("Limits", Table.TableLimits);311}312313void MappingTraits<WasmYAML::Function>::mapping(IO &IO,314WasmYAML::Function &Function) {315IO.mapRequired("Index", Function.Index);316IO.mapRequired("Locals", Function.Locals);317IO.mapRequired("Body", Function.Body);318}319320void MappingTraits<WasmYAML::Relocation>::mapping(321IO &IO, WasmYAML::Relocation &Relocation) {322IO.mapRequired("Type", Relocation.Type);323IO.mapRequired("Index", Relocation.Index);324IO.mapRequired("Offset", Relocation.Offset);325IO.mapOptional("Addend", Relocation.Addend, 0);326}327328void MappingTraits<WasmYAML::NameEntry>::mapping(329IO &IO, WasmYAML::NameEntry &NameEntry) {330IO.mapRequired("Index", NameEntry.Index);331IO.mapRequired("Name", NameEntry.Name);332}333334void MappingTraits<WasmYAML::ProducerEntry>::mapping(335IO &IO, WasmYAML::ProducerEntry &ProducerEntry) {336IO.mapRequired("Name", ProducerEntry.Name);337IO.mapRequired("Version", ProducerEntry.Version);338}339340void ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix>::enumeration(341IO &IO, WasmYAML::FeaturePolicyPrefix &Kind) {342#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_FEATURE_PREFIX_##X);343ECase(USED);344ECase(REQUIRED);345ECase(DISALLOWED);346#undef ECase347}348349void MappingTraits<WasmYAML::FeatureEntry>::mapping(350IO &IO, WasmYAML::FeatureEntry &FeatureEntry) {351IO.mapRequired("Prefix", FeatureEntry.Prefix);352IO.mapRequired("Name", FeatureEntry.Name);353}354355void MappingTraits<WasmYAML::SegmentInfo>::mapping(356IO &IO, WasmYAML::SegmentInfo &SegmentInfo) {357IO.mapRequired("Index", SegmentInfo.Index);358IO.mapRequired("Name", SegmentInfo.Name);359IO.mapRequired("Alignment", SegmentInfo.Alignment);360IO.mapRequired("Flags", SegmentInfo.Flags);361}362363void MappingTraits<WasmYAML::LocalDecl>::mapping(364IO &IO, WasmYAML::LocalDecl &LocalDecl) {365IO.mapRequired("Type", LocalDecl.Type);366IO.mapRequired("Count", LocalDecl.Count);367}368369void MappingTraits<WasmYAML::Limits>::mapping(IO &IO,370WasmYAML::Limits &Limits) {371IO.mapOptional("Flags", Limits.Flags, 0);372IO.mapRequired("Minimum", Limits.Minimum);373if (!IO.outputting() || Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)374IO.mapOptional("Maximum", Limits.Maximum);375}376377void MappingTraits<WasmYAML::ElemSegment>::mapping(378IO &IO, WasmYAML::ElemSegment &Segment) {379IO.mapOptional("Flags", Segment.Flags, 0);380if (!IO.outputting() ||381Segment.Flags & wasm::WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER)382IO.mapOptional("TableNumber", Segment.TableNumber);383if (!IO.outputting() ||384Segment.Flags & wasm::WASM_ELEM_SEGMENT_MASK_HAS_ELEM_KIND)385IO.mapOptional("ElemKind", Segment.ElemKind);386// TODO: Omit "offset" for passive segments? It's neither meaningful nor387// encoded.388IO.mapRequired("Offset", Segment.Offset);389IO.mapRequired("Functions", Segment.Functions);390}391392void MappingTraits<WasmYAML::Import>::mapping(IO &IO,393WasmYAML::Import &Import) {394IO.mapRequired("Module", Import.Module);395IO.mapRequired("Field", Import.Field);396IO.mapRequired("Kind", Import.Kind);397if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION ||398Import.Kind == wasm::WASM_EXTERNAL_TAG) {399IO.mapRequired("SigIndex", Import.SigIndex);400} else if (Import.Kind == wasm::WASM_EXTERNAL_GLOBAL) {401IO.mapRequired("GlobalType", Import.GlobalImport.Type);402IO.mapRequired("GlobalMutable", Import.GlobalImport.Mutable);403} else if (Import.Kind == wasm::WASM_EXTERNAL_TABLE) {404IO.mapRequired("Table", Import.TableImport);405} else if (Import.Kind == wasm::WASM_EXTERNAL_MEMORY) {406IO.mapRequired("Memory", Import.Memory);407} else {408llvm_unreachable("unhandled import type");409}410}411412void MappingTraits<WasmYAML::Export>::mapping(IO &IO,413WasmYAML::Export &Export) {414IO.mapRequired("Name", Export.Name);415IO.mapRequired("Kind", Export.Kind);416IO.mapRequired("Index", Export.Index);417}418419void MappingTraits<WasmYAML::Global>::mapping(IO &IO,420WasmYAML::Global &Global) {421IO.mapRequired("Index", Global.Index);422IO.mapRequired("Type", Global.Type);423IO.mapRequired("Mutable", Global.Mutable);424IO.mapRequired("InitExpr", Global.Init);425}426427void MappingTraits<WasmYAML::InitExpr>::mapping(IO &IO,428WasmYAML::InitExpr &Expr) {429IO.mapOptional("Extended", Expr.Extended, false);430if (Expr.Extended) {431IO.mapRequired("Body", Expr.Body);432} else {433WasmYAML::Opcode Op = Expr.Inst.Opcode;434IO.mapRequired("Opcode", Op);435Expr.Inst.Opcode = Op;436switch (Expr.Inst.Opcode) {437case wasm::WASM_OPCODE_I32_CONST:438IO.mapRequired("Value", Expr.Inst.Value.Int32);439break;440case wasm::WASM_OPCODE_I64_CONST:441IO.mapRequired("Value", Expr.Inst.Value.Int64);442break;443case wasm::WASM_OPCODE_F32_CONST:444IO.mapRequired("Value", Expr.Inst.Value.Float32);445break;446case wasm::WASM_OPCODE_F64_CONST:447IO.mapRequired("Value", Expr.Inst.Value.Float64);448break;449case wasm::WASM_OPCODE_GLOBAL_GET:450IO.mapRequired("Index", Expr.Inst.Value.Global);451break;452case wasm::WASM_OPCODE_REF_NULL: {453WasmYAML::ValueType Ty = wasm::WASM_TYPE_EXTERNREF;454IO.mapRequired("Type", Ty);455break;456}457}458}459}460461void MappingTraits<WasmYAML::DataSegment>::mapping(462IO &IO, WasmYAML::DataSegment &Segment) {463IO.mapOptional("SectionOffset", Segment.SectionOffset);464IO.mapRequired("InitFlags", Segment.InitFlags);465if (Segment.InitFlags & wasm::WASM_DATA_SEGMENT_HAS_MEMINDEX) {466IO.mapRequired("MemoryIndex", Segment.MemoryIndex);467} else {468Segment.MemoryIndex = 0;469}470if ((Segment.InitFlags & wasm::WASM_DATA_SEGMENT_IS_PASSIVE) == 0) {471IO.mapRequired("Offset", Segment.Offset);472} else {473Segment.Offset.Inst.Opcode = wasm::WASM_OPCODE_I32_CONST;474Segment.Offset.Inst.Value.Int32 = 0;475}476IO.mapRequired("Content", Segment.Content);477}478479void MappingTraits<WasmYAML::InitFunction>::mapping(480IO &IO, WasmYAML::InitFunction &Init) {481IO.mapRequired("Priority", Init.Priority);482IO.mapRequired("Symbol", Init.Symbol);483}484485void ScalarEnumerationTraits<WasmYAML::ComdatKind>::enumeration(486IO &IO, WasmYAML::ComdatKind &Kind) {487#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_COMDAT_##X);488ECase(FUNCTION);489ECase(DATA);490ECase(SECTION);491#undef ECase492}493494void MappingTraits<WasmYAML::ComdatEntry>::mapping(495IO &IO, WasmYAML::ComdatEntry &ComdatEntry) {496IO.mapRequired("Kind", ComdatEntry.Kind);497IO.mapRequired("Index", ComdatEntry.Index);498}499500void MappingTraits<WasmYAML::Comdat>::mapping(IO &IO,501WasmYAML::Comdat &Comdat) {502IO.mapRequired("Name", Comdat.Name);503IO.mapRequired("Entries", Comdat.Entries);504}505506void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,507WasmYAML::SymbolInfo &Info) {508IO.mapRequired("Index", Info.Index);509IO.mapRequired("Kind", Info.Kind);510if (Info.Kind != wasm::WASM_SYMBOL_TYPE_SECTION)511IO.mapRequired("Name", Info.Name);512IO.mapRequired("Flags", Info.Flags);513if (Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION) {514IO.mapRequired("Function", Info.ElementIndex);515} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_GLOBAL) {516IO.mapRequired("Global", Info.ElementIndex);517} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_TABLE) {518IO.mapRequired("Table", Info.ElementIndex);519} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_TAG) {520IO.mapRequired("Tag", Info.ElementIndex);521} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_DATA) {522if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) {523if ((Info.Flags & wasm::WASM_SYMBOL_ABSOLUTE) == 0) {524IO.mapRequired("Segment", Info.DataRef.Segment);525}526IO.mapOptional("Offset", Info.DataRef.Offset, 0u);527IO.mapRequired("Size", Info.DataRef.Size);528}529} else if (Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION) {530IO.mapRequired("Section", Info.ElementIndex);531} else {532llvm_unreachable("unsupported symbol kind");533}534}535536void MappingTraits<WasmYAML::DylinkImportInfo>::mapping(537IO &IO, WasmYAML::DylinkImportInfo &Info) {538IO.mapRequired("Module", Info.Module);539IO.mapRequired("Field", Info.Field);540IO.mapRequired("Flags", Info.Flags);541}542543void MappingTraits<WasmYAML::DylinkExportInfo>::mapping(544IO &IO, WasmYAML::DylinkExportInfo &Info) {545IO.mapRequired("Name", Info.Name);546IO.mapRequired("Flags", Info.Flags);547}548549void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset(550IO &IO, WasmYAML::LimitFlags &Value) {551#define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X)552BCase(HAS_MAX);553BCase(IS_SHARED);554BCase(IS_64);555#undef BCase556}557558void ScalarBitSetTraits<WasmYAML::SegmentFlags>::bitset(559IO &IO, WasmYAML::SegmentFlags &Value) {560#define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_SEG_FLAG_##X)561BCase(STRINGS);562BCase(TLS);563BCase(RETAIN);564#undef BCase565}566567void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset(568IO &IO, WasmYAML::SymbolFlags &Value) {569#define BCaseMask(M, X) \570IO.maskedBitSetCase(Value, #X, wasm::WASM_SYMBOL_##X, wasm::WASM_SYMBOL_##M)571// BCaseMask(BINDING_MASK, BINDING_GLOBAL);572BCaseMask(BINDING_MASK, BINDING_WEAK);573BCaseMask(BINDING_MASK, BINDING_LOCAL);574// BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT);575BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN);576BCaseMask(UNDEFINED, UNDEFINED);577BCaseMask(EXPORTED, EXPORTED);578BCaseMask(EXPLICIT_NAME, EXPLICIT_NAME);579BCaseMask(NO_STRIP, NO_STRIP);580BCaseMask(TLS, TLS);581BCaseMask(ABSOLUTE, ABSOLUTE);582#undef BCaseMask583}584585void ScalarEnumerationTraits<WasmYAML::SymbolKind>::enumeration(586IO &IO, WasmYAML::SymbolKind &Kind) {587#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_SYMBOL_TYPE_##X);588ECase(FUNCTION);589ECase(DATA);590ECase(GLOBAL);591ECase(TABLE);592ECase(SECTION);593ECase(TAG);594#undef ECase595}596597void ScalarEnumerationTraits<WasmYAML::ValueType>::enumeration(598IO &IO, WasmYAML::ValueType &Type) {599#define CONCAT(X) (uint32_t) wasm::ValType::X600#define ECase(X) IO.enumCase(Type, #X, CONCAT(X));601ECase(I32);602ECase(I64);603ECase(F32);604ECase(F64);605ECase(V128);606ECase(FUNCREF);607ECase(EXTERNREF);608ECase(EXNREF);609ECase(OTHERREF);610#undef ECase611}612613void ScalarEnumerationTraits<WasmYAML::ExportKind>::enumeration(614IO &IO, WasmYAML::ExportKind &Kind) {615#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_EXTERNAL_##X);616ECase(FUNCTION);617ECase(TABLE);618ECase(MEMORY);619ECase(GLOBAL);620ECase(TAG);621#undef ECase622}623624void ScalarEnumerationTraits<WasmYAML::Opcode>::enumeration(625IO &IO, WasmYAML::Opcode &Code) {626#define ECase(X) IO.enumCase(Code, #X, wasm::WASM_OPCODE_##X);627ECase(END);628ECase(I32_CONST);629ECase(I64_CONST);630ECase(F64_CONST);631ECase(F32_CONST);632ECase(GLOBAL_GET);633ECase(REF_NULL);634#undef ECase635}636637void ScalarEnumerationTraits<WasmYAML::TableType>::enumeration(638IO &IO, WasmYAML::TableType &Type) {639#define CONCAT(X) (uint32_t) wasm::ValType::X640#define ECase(X) IO.enumCase(Type, #X, CONCAT(X));641ECase(FUNCREF);642ECase(EXTERNREF);643ECase(EXNREF);644ECase(OTHERREF);645#undef ECase646}647648void ScalarEnumerationTraits<WasmYAML::RelocType>::enumeration(649IO &IO, WasmYAML::RelocType &Type) {650#define WASM_RELOC(name, value) IO.enumCase(Type, #name, wasm::name);651#include "llvm/BinaryFormat/WasmRelocs.def"652#undef WASM_RELOC653IO.enumFallback<Hex32>(Type);654}655656} // end namespace yaml657658} // end namespace llvm659660661