xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ObjectYAML/WasmYAML.h (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
10b57cec5SDimitry Andric //===- WasmYAML.h - Wasm YAMLIO implementation ------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric ///
90b57cec5SDimitry Andric /// \file
100b57cec5SDimitry Andric /// This file declares classes for handling the YAML representation
110b57cec5SDimitry Andric /// of wasm binaries.
120b57cec5SDimitry Andric ///
130b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #ifndef LLVM_OBJECTYAML_WASMYAML_H
160b57cec5SDimitry Andric #define LLVM_OBJECTYAML_WASMYAML_H
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
190b57cec5SDimitry Andric #include "llvm/BinaryFormat/Wasm.h"
200b57cec5SDimitry Andric #include "llvm/ObjectYAML/YAML.h"
210b57cec5SDimitry Andric #include "llvm/Support/Casting.h"
220b57cec5SDimitry Andric #include <cstdint>
230b57cec5SDimitry Andric #include <memory>
240b57cec5SDimitry Andric #include <vector>
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric namespace llvm {
270b57cec5SDimitry Andric namespace WasmYAML {
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionType)
300b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, ValueType)
310b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, TableType)
320b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, SignatureForm)
330b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind)
340b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode)
350b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType)
360b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolFlags)
370b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolKind)
380b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, SegmentFlags)
390b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, LimitFlags)
400b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, ComdatKind)
410b57cec5SDimitry Andric LLVM_YAML_STRONG_TYPEDEF(uint32_t, FeaturePolicyPrefix)
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric struct FileHeader {
440b57cec5SDimitry Andric   yaml::Hex32 Version;
450b57cec5SDimitry Andric };
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric struct Limits {
480b57cec5SDimitry Andric   LimitFlags Flags;
49fe6060f1SDimitry Andric   yaml::Hex32 Minimum;
500b57cec5SDimitry Andric   yaml::Hex32 Maximum;
510b57cec5SDimitry Andric };
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric struct Table {
540b57cec5SDimitry Andric   TableType ElemType;
550b57cec5SDimitry Andric   Limits TableLimits;
56e8d8bef9SDimitry Andric   uint32_t Index;
570b57cec5SDimitry Andric };
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric struct Export {
600b57cec5SDimitry Andric   StringRef Name;
610b57cec5SDimitry Andric   ExportKind Kind;
620b57cec5SDimitry Andric   uint32_t Index;
630b57cec5SDimitry Andric };
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric struct ElemSegment {
66fe6060f1SDimitry Andric   uint32_t Flags;
67fe6060f1SDimitry Andric   uint32_t TableNumber;
68fe6060f1SDimitry Andric   ValueType ElemKind;
690b57cec5SDimitry Andric   wasm::WasmInitExpr Offset;
700b57cec5SDimitry Andric   std::vector<uint32_t> Functions;
710b57cec5SDimitry Andric };
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric struct Global {
740b57cec5SDimitry Andric   uint32_t Index;
750b57cec5SDimitry Andric   ValueType Type;
760b57cec5SDimitry Andric   bool Mutable;
770b57cec5SDimitry Andric   wasm::WasmInitExpr InitExpr;
780b57cec5SDimitry Andric };
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric struct Import {
810b57cec5SDimitry Andric   StringRef Module;
820b57cec5SDimitry Andric   StringRef Field;
830b57cec5SDimitry Andric   ExportKind Kind;
840b57cec5SDimitry Andric   union {
850b57cec5SDimitry Andric     uint32_t SigIndex;
860b57cec5SDimitry Andric     Global GlobalImport;
870b57cec5SDimitry Andric     Table TableImport;
880b57cec5SDimitry Andric     Limits Memory;
89*349cc55cSDimitry Andric     uint32_t TagIndex;
900b57cec5SDimitry Andric   };
910b57cec5SDimitry Andric };
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric struct LocalDecl {
940b57cec5SDimitry Andric   ValueType Type;
950b57cec5SDimitry Andric   uint32_t Count;
960b57cec5SDimitry Andric };
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric struct Function {
990b57cec5SDimitry Andric   uint32_t Index;
1000b57cec5SDimitry Andric   std::vector<LocalDecl> Locals;
1010b57cec5SDimitry Andric   yaml::BinaryRef Body;
1020b57cec5SDimitry Andric };
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric struct Relocation {
1050b57cec5SDimitry Andric   RelocType Type;
1060b57cec5SDimitry Andric   uint32_t Index;
1075ffd83dbSDimitry Andric   // TODO(wvo): this would strictly be better as Hex64, but that will change
1085ffd83dbSDimitry Andric   // all existing obj2yaml output.
1090b57cec5SDimitry Andric   yaml::Hex32 Offset;
1105ffd83dbSDimitry Andric   int64_t Addend;
1110b57cec5SDimitry Andric };
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric struct DataSegment {
1140b57cec5SDimitry Andric   uint32_t SectionOffset;
1150b57cec5SDimitry Andric   uint32_t InitFlags;
1160b57cec5SDimitry Andric   uint32_t MemoryIndex;
1170b57cec5SDimitry Andric   wasm::WasmInitExpr Offset;
1180b57cec5SDimitry Andric   yaml::BinaryRef Content;
1190b57cec5SDimitry Andric };
1200b57cec5SDimitry Andric 
1210b57cec5SDimitry Andric struct NameEntry {
1220b57cec5SDimitry Andric   uint32_t Index;
1230b57cec5SDimitry Andric   StringRef Name;
1240b57cec5SDimitry Andric };
1250b57cec5SDimitry Andric 
1260b57cec5SDimitry Andric struct ProducerEntry {
1270b57cec5SDimitry Andric   std::string Name;
1280b57cec5SDimitry Andric   std::string Version;
1290b57cec5SDimitry Andric };
1300b57cec5SDimitry Andric 
1310b57cec5SDimitry Andric struct FeatureEntry {
1320b57cec5SDimitry Andric   FeaturePolicyPrefix Prefix;
1330b57cec5SDimitry Andric   std::string Name;
1340b57cec5SDimitry Andric };
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric struct SegmentInfo {
1370b57cec5SDimitry Andric   uint32_t Index;
1380b57cec5SDimitry Andric   StringRef Name;
1390b57cec5SDimitry Andric   uint32_t Alignment;
1400b57cec5SDimitry Andric   SegmentFlags Flags;
1410b57cec5SDimitry Andric };
1420b57cec5SDimitry Andric 
1430b57cec5SDimitry Andric struct Signature {
1440b57cec5SDimitry Andric   uint32_t Index;
1450b57cec5SDimitry Andric   SignatureForm Form = wasm::WASM_TYPE_FUNC;
1460b57cec5SDimitry Andric   std::vector<ValueType> ParamTypes;
1478bcb0991SDimitry Andric   std::vector<ValueType> ReturnTypes;
1480b57cec5SDimitry Andric };
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric struct SymbolInfo {
1510b57cec5SDimitry Andric   uint32_t Index;
1520b57cec5SDimitry Andric   StringRef Name;
1530b57cec5SDimitry Andric   SymbolKind Kind;
1540b57cec5SDimitry Andric   SymbolFlags Flags;
1550b57cec5SDimitry Andric   union {
1560b57cec5SDimitry Andric     uint32_t ElementIndex;
1570b57cec5SDimitry Andric     wasm::WasmDataReference DataRef;
1580b57cec5SDimitry Andric   };
1590b57cec5SDimitry Andric };
1600b57cec5SDimitry Andric 
1610b57cec5SDimitry Andric struct InitFunction {
1620b57cec5SDimitry Andric   uint32_t Priority;
1630b57cec5SDimitry Andric   uint32_t Symbol;
1640b57cec5SDimitry Andric };
1650b57cec5SDimitry Andric 
1660b57cec5SDimitry Andric struct ComdatEntry {
1670b57cec5SDimitry Andric   ComdatKind Kind;
1680b57cec5SDimitry Andric   uint32_t Index;
1690b57cec5SDimitry Andric };
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric struct Comdat {
1720b57cec5SDimitry Andric   StringRef Name;
1730b57cec5SDimitry Andric   std::vector<ComdatEntry> Entries;
1740b57cec5SDimitry Andric };
1750b57cec5SDimitry Andric 
1760b57cec5SDimitry Andric struct Section {
1770b57cec5SDimitry Andric   explicit Section(SectionType SecType) : Type(SecType) {}
1780b57cec5SDimitry Andric   virtual ~Section();
1790b57cec5SDimitry Andric 
1800b57cec5SDimitry Andric   SectionType Type;
1810b57cec5SDimitry Andric   std::vector<Relocation> Relocations;
1820b57cec5SDimitry Andric };
1830b57cec5SDimitry Andric 
1840b57cec5SDimitry Andric struct CustomSection : Section {
1850b57cec5SDimitry Andric   explicit CustomSection(StringRef Name)
1860b57cec5SDimitry Andric       : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
1870b57cec5SDimitry Andric 
1880b57cec5SDimitry Andric   static bool classof(const Section *S) {
1890b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_CUSTOM;
1900b57cec5SDimitry Andric   }
1910b57cec5SDimitry Andric 
1920b57cec5SDimitry Andric   StringRef Name;
1930b57cec5SDimitry Andric   yaml::BinaryRef Payload;
1940b57cec5SDimitry Andric };
1950b57cec5SDimitry Andric 
196*349cc55cSDimitry Andric struct DylinkImportInfo {
197*349cc55cSDimitry Andric   StringRef Module;
198*349cc55cSDimitry Andric   StringRef Field;
199*349cc55cSDimitry Andric   SymbolFlags Flags;
200*349cc55cSDimitry Andric };
201*349cc55cSDimitry Andric 
202*349cc55cSDimitry Andric struct DylinkExportInfo {
203*349cc55cSDimitry Andric   StringRef Name;
204*349cc55cSDimitry Andric   SymbolFlags Flags;
205*349cc55cSDimitry Andric };
206*349cc55cSDimitry Andric 
2070b57cec5SDimitry Andric struct DylinkSection : CustomSection {
208*349cc55cSDimitry Andric   DylinkSection() : CustomSection("dylink.0") {}
2090b57cec5SDimitry Andric 
2100b57cec5SDimitry Andric   static bool classof(const Section *S) {
2110b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
212*349cc55cSDimitry Andric     return C && C->Name == "dylink.0";
2130b57cec5SDimitry Andric   }
2140b57cec5SDimitry Andric 
2150b57cec5SDimitry Andric   uint32_t MemorySize;
2160b57cec5SDimitry Andric   uint32_t MemoryAlignment;
2170b57cec5SDimitry Andric   uint32_t TableSize;
2180b57cec5SDimitry Andric   uint32_t TableAlignment;
2190b57cec5SDimitry Andric   std::vector<StringRef> Needed;
220*349cc55cSDimitry Andric   std::vector<DylinkImportInfo> ImportInfo;
221*349cc55cSDimitry Andric   std::vector<DylinkExportInfo> ExportInfo;
2220b57cec5SDimitry Andric };
2230b57cec5SDimitry Andric 
2240b57cec5SDimitry Andric struct NameSection : CustomSection {
2250b57cec5SDimitry Andric   NameSection() : CustomSection("name") {}
2260b57cec5SDimitry Andric 
2270b57cec5SDimitry Andric   static bool classof(const Section *S) {
2280b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2290b57cec5SDimitry Andric     return C && C->Name == "name";
2300b57cec5SDimitry Andric   }
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric   std::vector<NameEntry> FunctionNames;
233e8d8bef9SDimitry Andric   std::vector<NameEntry> GlobalNames;
234e8d8bef9SDimitry Andric   std::vector<NameEntry> DataSegmentNames;
2350b57cec5SDimitry Andric };
2360b57cec5SDimitry Andric 
2370b57cec5SDimitry Andric struct LinkingSection : CustomSection {
2380b57cec5SDimitry Andric   LinkingSection() : CustomSection("linking") {}
2390b57cec5SDimitry Andric 
2400b57cec5SDimitry Andric   static bool classof(const Section *S) {
2410b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2420b57cec5SDimitry Andric     return C && C->Name == "linking";
2430b57cec5SDimitry Andric   }
2440b57cec5SDimitry Andric 
2450b57cec5SDimitry Andric   uint32_t Version;
2460b57cec5SDimitry Andric   std::vector<SymbolInfo> SymbolTable;
2470b57cec5SDimitry Andric   std::vector<SegmentInfo> SegmentInfos;
2480b57cec5SDimitry Andric   std::vector<InitFunction> InitFunctions;
2490b57cec5SDimitry Andric   std::vector<Comdat> Comdats;
2500b57cec5SDimitry Andric };
2510b57cec5SDimitry Andric 
2520b57cec5SDimitry Andric struct ProducersSection : CustomSection {
2530b57cec5SDimitry Andric   ProducersSection() : CustomSection("producers") {}
2540b57cec5SDimitry Andric 
2550b57cec5SDimitry Andric   static bool classof(const Section *S) {
2560b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2570b57cec5SDimitry Andric     return C && C->Name == "producers";
2580b57cec5SDimitry Andric   }
2590b57cec5SDimitry Andric 
2600b57cec5SDimitry Andric   std::vector<ProducerEntry> Languages;
2610b57cec5SDimitry Andric   std::vector<ProducerEntry> Tools;
2620b57cec5SDimitry Andric   std::vector<ProducerEntry> SDKs;
2630b57cec5SDimitry Andric };
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric struct TargetFeaturesSection : CustomSection {
2660b57cec5SDimitry Andric   TargetFeaturesSection() : CustomSection("target_features") {}
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   static bool classof(const Section *S) {
2690b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2700b57cec5SDimitry Andric     return C && C->Name == "target_features";
2710b57cec5SDimitry Andric   }
2720b57cec5SDimitry Andric 
2730b57cec5SDimitry Andric   std::vector<FeatureEntry> Features;
2740b57cec5SDimitry Andric };
2750b57cec5SDimitry Andric 
2760b57cec5SDimitry Andric struct TypeSection : Section {
2770b57cec5SDimitry Andric   TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
2780b57cec5SDimitry Andric 
2790b57cec5SDimitry Andric   static bool classof(const Section *S) {
2800b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_TYPE;
2810b57cec5SDimitry Andric   }
2820b57cec5SDimitry Andric 
2830b57cec5SDimitry Andric   std::vector<Signature> Signatures;
2840b57cec5SDimitry Andric };
2850b57cec5SDimitry Andric 
2860b57cec5SDimitry Andric struct ImportSection : Section {
2870b57cec5SDimitry Andric   ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
2880b57cec5SDimitry Andric 
2890b57cec5SDimitry Andric   static bool classof(const Section *S) {
2900b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_IMPORT;
2910b57cec5SDimitry Andric   }
2920b57cec5SDimitry Andric 
2930b57cec5SDimitry Andric   std::vector<Import> Imports;
2940b57cec5SDimitry Andric };
2950b57cec5SDimitry Andric 
2960b57cec5SDimitry Andric struct FunctionSection : Section {
2970b57cec5SDimitry Andric   FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
2980b57cec5SDimitry Andric 
2990b57cec5SDimitry Andric   static bool classof(const Section *S) {
3000b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_FUNCTION;
3010b57cec5SDimitry Andric   }
3020b57cec5SDimitry Andric 
3030b57cec5SDimitry Andric   std::vector<uint32_t> FunctionTypes;
3040b57cec5SDimitry Andric };
3050b57cec5SDimitry Andric 
3060b57cec5SDimitry Andric struct TableSection : Section {
3070b57cec5SDimitry Andric   TableSection() : Section(wasm::WASM_SEC_TABLE) {}
3080b57cec5SDimitry Andric 
3090b57cec5SDimitry Andric   static bool classof(const Section *S) {
3100b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_TABLE;
3110b57cec5SDimitry Andric   }
3120b57cec5SDimitry Andric 
3130b57cec5SDimitry Andric   std::vector<Table> Tables;
3140b57cec5SDimitry Andric };
3150b57cec5SDimitry Andric 
3160b57cec5SDimitry Andric struct MemorySection : Section {
3170b57cec5SDimitry Andric   MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
3180b57cec5SDimitry Andric 
3190b57cec5SDimitry Andric   static bool classof(const Section *S) {
3200b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_MEMORY;
3210b57cec5SDimitry Andric   }
3220b57cec5SDimitry Andric 
3230b57cec5SDimitry Andric   std::vector<Limits> Memories;
3240b57cec5SDimitry Andric };
3250b57cec5SDimitry Andric 
326fe6060f1SDimitry Andric struct TagSection : Section {
327fe6060f1SDimitry Andric   TagSection() : Section(wasm::WASM_SEC_TAG) {}
3280b57cec5SDimitry Andric 
3290b57cec5SDimitry Andric   static bool classof(const Section *S) {
330fe6060f1SDimitry Andric     return S->Type == wasm::WASM_SEC_TAG;
3310b57cec5SDimitry Andric   }
3320b57cec5SDimitry Andric 
333*349cc55cSDimitry Andric   std::vector<uint32_t> TagTypes;
3340b57cec5SDimitry Andric };
3350b57cec5SDimitry Andric 
3365ffd83dbSDimitry Andric struct GlobalSection : Section {
3375ffd83dbSDimitry Andric   GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
3385ffd83dbSDimitry Andric 
3395ffd83dbSDimitry Andric   static bool classof(const Section *S) {
3405ffd83dbSDimitry Andric     return S->Type == wasm::WASM_SEC_GLOBAL;
3415ffd83dbSDimitry Andric   }
3425ffd83dbSDimitry Andric 
3435ffd83dbSDimitry Andric   std::vector<Global> Globals;
3445ffd83dbSDimitry Andric };
3455ffd83dbSDimitry Andric 
3460b57cec5SDimitry Andric struct ExportSection : Section {
3470b57cec5SDimitry Andric   ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
3480b57cec5SDimitry Andric 
3490b57cec5SDimitry Andric   static bool classof(const Section *S) {
3500b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_EXPORT;
3510b57cec5SDimitry Andric   }
3520b57cec5SDimitry Andric 
3530b57cec5SDimitry Andric   std::vector<Export> Exports;
3540b57cec5SDimitry Andric };
3550b57cec5SDimitry Andric 
3560b57cec5SDimitry Andric struct StartSection : Section {
3570b57cec5SDimitry Andric   StartSection() : Section(wasm::WASM_SEC_START) {}
3580b57cec5SDimitry Andric 
3590b57cec5SDimitry Andric   static bool classof(const Section *S) {
3600b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_START;
3610b57cec5SDimitry Andric   }
3620b57cec5SDimitry Andric 
3630b57cec5SDimitry Andric   uint32_t StartFunction;
3640b57cec5SDimitry Andric };
3650b57cec5SDimitry Andric 
3660b57cec5SDimitry Andric struct ElemSection : Section {
3670b57cec5SDimitry Andric   ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
3680b57cec5SDimitry Andric 
3690b57cec5SDimitry Andric   static bool classof(const Section *S) {
3700b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_ELEM;
3710b57cec5SDimitry Andric   }
3720b57cec5SDimitry Andric 
3730b57cec5SDimitry Andric   std::vector<ElemSegment> Segments;
3740b57cec5SDimitry Andric };
3750b57cec5SDimitry Andric 
3760b57cec5SDimitry Andric struct CodeSection : Section {
3770b57cec5SDimitry Andric   CodeSection() : Section(wasm::WASM_SEC_CODE) {}
3780b57cec5SDimitry Andric 
3790b57cec5SDimitry Andric   static bool classof(const Section *S) {
3800b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_CODE;
3810b57cec5SDimitry Andric   }
3820b57cec5SDimitry Andric 
3830b57cec5SDimitry Andric   std::vector<Function> Functions;
3840b57cec5SDimitry Andric };
3850b57cec5SDimitry Andric 
3860b57cec5SDimitry Andric struct DataSection : Section {
3870b57cec5SDimitry Andric   DataSection() : Section(wasm::WASM_SEC_DATA) {}
3880b57cec5SDimitry Andric 
3890b57cec5SDimitry Andric   static bool classof(const Section *S) {
3900b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_DATA;
3910b57cec5SDimitry Andric   }
3920b57cec5SDimitry Andric 
3930b57cec5SDimitry Andric   std::vector<DataSegment> Segments;
3940b57cec5SDimitry Andric };
3950b57cec5SDimitry Andric 
3960b57cec5SDimitry Andric struct DataCountSection : Section {
3970b57cec5SDimitry Andric   DataCountSection() : Section(wasm::WASM_SEC_DATACOUNT) {}
3980b57cec5SDimitry Andric 
3990b57cec5SDimitry Andric   static bool classof(const Section *S) {
4000b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_DATACOUNT;
4010b57cec5SDimitry Andric   }
4020b57cec5SDimitry Andric 
4030b57cec5SDimitry Andric   uint32_t Count;
4040b57cec5SDimitry Andric };
4050b57cec5SDimitry Andric 
4060b57cec5SDimitry Andric struct Object {
4070b57cec5SDimitry Andric   FileHeader Header;
4080b57cec5SDimitry Andric   std::vector<std::unique_ptr<Section>> Sections;
4090b57cec5SDimitry Andric };
4100b57cec5SDimitry Andric 
4110b57cec5SDimitry Andric } // end namespace WasmYAML
4120b57cec5SDimitry Andric } // end namespace llvm
4130b57cec5SDimitry Andric 
4140b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
4150b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
4160b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
4170b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
4180b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
4190b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
4200b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
4210b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
4220b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
4230b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
4240b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
4250b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
4260b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
4270b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
4280b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ProducerEntry)
4290b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::FeatureEntry)
4300b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo)
4310b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
4320b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction)
4330b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry)
4340b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat)
435*349cc55cSDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DylinkImportInfo)
436*349cc55cSDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DylinkExportInfo)
4370b57cec5SDimitry Andric 
4380b57cec5SDimitry Andric namespace llvm {
4390b57cec5SDimitry Andric namespace yaml {
4400b57cec5SDimitry Andric 
4410b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::FileHeader> {
4420b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
4430b57cec5SDimitry Andric };
4440b57cec5SDimitry Andric 
4450b57cec5SDimitry Andric template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
4460b57cec5SDimitry Andric   static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
4470b57cec5SDimitry Andric };
4480b57cec5SDimitry Andric 
4490b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Object> {
4500b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Object &Object);
4510b57cec5SDimitry Andric };
4520b57cec5SDimitry Andric 
4530b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Import> {
4540b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Import &Import);
4550b57cec5SDimitry Andric };
4560b57cec5SDimitry Andric 
4570b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Export> {
4580b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Export &Export);
4590b57cec5SDimitry Andric };
4600b57cec5SDimitry Andric 
4610b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Global> {
4620b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Global &Global);
4630b57cec5SDimitry Andric };
4640b57cec5SDimitry Andric 
4650b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
4660b57cec5SDimitry Andric   static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
4670b57cec5SDimitry Andric };
4680b57cec5SDimitry Andric 
4690b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
4700b57cec5SDimitry Andric   static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
4710b57cec5SDimitry Andric };
4720b57cec5SDimitry Andric 
4730b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> {
4740b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind);
4750b57cec5SDimitry Andric };
4760b57cec5SDimitry Andric 
4770b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
4780b57cec5SDimitry Andric   static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
4790b57cec5SDimitry Andric };
4800b57cec5SDimitry Andric 
4810b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
4820b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::SectionType &Type);
4830b57cec5SDimitry Andric };
4840b57cec5SDimitry Andric 
4850b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Signature> {
4860b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Signature &Signature);
4870b57cec5SDimitry Andric };
4880b57cec5SDimitry Andric 
4890b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Table> {
4900b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Table &Table);
4910b57cec5SDimitry Andric };
4920b57cec5SDimitry Andric 
4930b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Limits> {
4940b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Limits &Limits);
4950b57cec5SDimitry Andric };
4960b57cec5SDimitry Andric 
4970b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Function> {
4980b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Function &Function);
4990b57cec5SDimitry Andric };
5000b57cec5SDimitry Andric 
5010b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Relocation> {
5020b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
5030b57cec5SDimitry Andric };
5040b57cec5SDimitry Andric 
5050b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::NameEntry> {
5060b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
5070b57cec5SDimitry Andric };
5080b57cec5SDimitry Andric 
5090b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ProducerEntry> {
5100b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::ProducerEntry &ProducerEntry);
5110b57cec5SDimitry Andric };
5120b57cec5SDimitry Andric 
5130b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix> {
5140b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::FeaturePolicyPrefix &Prefix);
5150b57cec5SDimitry Andric };
5160b57cec5SDimitry Andric 
5170b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::FeatureEntry> {
5180b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::FeatureEntry &FeatureEntry);
5190b57cec5SDimitry Andric };
5200b57cec5SDimitry Andric 
5210b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::SegmentInfo> {
5220b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
5230b57cec5SDimitry Andric };
5240b57cec5SDimitry Andric 
5250b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::LocalDecl> {
5260b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
5270b57cec5SDimitry Andric };
5280b57cec5SDimitry Andric 
5290b57cec5SDimitry Andric template <> struct MappingTraits<wasm::WasmInitExpr> {
5300b57cec5SDimitry Andric   static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
5310b57cec5SDimitry Andric };
5320b57cec5SDimitry Andric 
5330b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::DataSegment> {
5340b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
5350b57cec5SDimitry Andric };
5360b57cec5SDimitry Andric 
5370b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ElemSegment> {
5380b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
5390b57cec5SDimitry Andric };
5400b57cec5SDimitry Andric 
5410b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::SymbolInfo> {
5420b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
5430b57cec5SDimitry Andric };
5440b57cec5SDimitry Andric 
5450b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::InitFunction> {
5460b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::InitFunction &Init);
5470b57cec5SDimitry Andric };
5480b57cec5SDimitry Andric 
5490b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> {
5500b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind);
5510b57cec5SDimitry Andric };
5520b57cec5SDimitry Andric 
5530b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ComdatEntry> {
5540b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry);
5550b57cec5SDimitry Andric };
5560b57cec5SDimitry Andric 
5570b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Comdat> {
5580b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Comdat &Comdat);
5590b57cec5SDimitry Andric };
5600b57cec5SDimitry Andric 
5610b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
5620b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::ValueType &Type);
5630b57cec5SDimitry Andric };
5640b57cec5SDimitry Andric 
5650b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
5660b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
5670b57cec5SDimitry Andric };
5680b57cec5SDimitry Andric 
5690b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
5700b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::TableType &Type);
5710b57cec5SDimitry Andric };
5720b57cec5SDimitry Andric 
5730b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
5740b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
5750b57cec5SDimitry Andric };
5760b57cec5SDimitry Andric 
5770b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
5780b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
5790b57cec5SDimitry Andric };
5800b57cec5SDimitry Andric 
581*349cc55cSDimitry Andric template <> struct MappingTraits<WasmYAML::DylinkImportInfo> {
582*349cc55cSDimitry Andric   static void mapping(IO &IO, WasmYAML::DylinkImportInfo &Info);
583*349cc55cSDimitry Andric };
584*349cc55cSDimitry Andric 
585*349cc55cSDimitry Andric template <> struct MappingTraits<WasmYAML::DylinkExportInfo> {
586*349cc55cSDimitry Andric   static void mapping(IO &IO, WasmYAML::DylinkExportInfo &Info);
5870b57cec5SDimitry Andric };
5880b57cec5SDimitry Andric 
5890b57cec5SDimitry Andric } // end namespace yaml
5900b57cec5SDimitry Andric } // end namespace llvm
5910b57cec5SDimitry Andric 
5920b57cec5SDimitry Andric #endif // LLVM_OBJECTYAML_WASMYAML_H
593