xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ObjectYAML/WasmYAML.h (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
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;
490b57cec5SDimitry Andric   yaml::Hex32 Initial;
500b57cec5SDimitry Andric   yaml::Hex32 Maximum;
510b57cec5SDimitry Andric };
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric struct Table {
540b57cec5SDimitry Andric   TableType ElemType;
550b57cec5SDimitry Andric   Limits TableLimits;
560b57cec5SDimitry Andric };
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric struct Export {
590b57cec5SDimitry Andric   StringRef Name;
600b57cec5SDimitry Andric   ExportKind Kind;
610b57cec5SDimitry Andric   uint32_t Index;
620b57cec5SDimitry Andric };
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric struct ElemSegment {
650b57cec5SDimitry Andric   uint32_t TableIndex;
660b57cec5SDimitry Andric   wasm::WasmInitExpr Offset;
670b57cec5SDimitry Andric   std::vector<uint32_t> Functions;
680b57cec5SDimitry Andric };
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric struct Global {
710b57cec5SDimitry Andric   uint32_t Index;
720b57cec5SDimitry Andric   ValueType Type;
730b57cec5SDimitry Andric   bool Mutable;
740b57cec5SDimitry Andric   wasm::WasmInitExpr InitExpr;
750b57cec5SDimitry Andric };
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric struct Event {
780b57cec5SDimitry Andric   uint32_t Index;
790b57cec5SDimitry Andric   uint32_t Attribute;
800b57cec5SDimitry Andric   uint32_t SigIndex;
810b57cec5SDimitry Andric };
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric struct Import {
840b57cec5SDimitry Andric   StringRef Module;
850b57cec5SDimitry Andric   StringRef Field;
860b57cec5SDimitry Andric   ExportKind Kind;
870b57cec5SDimitry Andric   union {
880b57cec5SDimitry Andric     uint32_t SigIndex;
890b57cec5SDimitry Andric     Global GlobalImport;
900b57cec5SDimitry Andric     Table TableImport;
910b57cec5SDimitry Andric     Limits Memory;
920b57cec5SDimitry Andric     Event EventImport;
930b57cec5SDimitry Andric   };
940b57cec5SDimitry Andric };
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric struct LocalDecl {
970b57cec5SDimitry Andric   ValueType Type;
980b57cec5SDimitry Andric   uint32_t Count;
990b57cec5SDimitry Andric };
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric struct Function {
1020b57cec5SDimitry Andric   uint32_t Index;
1030b57cec5SDimitry Andric   std::vector<LocalDecl> Locals;
1040b57cec5SDimitry Andric   yaml::BinaryRef Body;
1050b57cec5SDimitry Andric };
1060b57cec5SDimitry Andric 
1070b57cec5SDimitry Andric struct Relocation {
1080b57cec5SDimitry Andric   RelocType Type;
1090b57cec5SDimitry Andric   uint32_t Index;
110*5ffd83dbSDimitry Andric   // TODO(wvo): this would strictly be better as Hex64, but that will change
111*5ffd83dbSDimitry Andric   // all existing obj2yaml output.
1120b57cec5SDimitry Andric   yaml::Hex32 Offset;
113*5ffd83dbSDimitry Andric   int64_t Addend;
1140b57cec5SDimitry Andric };
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric struct DataSegment {
1170b57cec5SDimitry Andric   uint32_t SectionOffset;
1180b57cec5SDimitry Andric   uint32_t InitFlags;
1190b57cec5SDimitry Andric   uint32_t MemoryIndex;
1200b57cec5SDimitry Andric   wasm::WasmInitExpr Offset;
1210b57cec5SDimitry Andric   yaml::BinaryRef Content;
1220b57cec5SDimitry Andric };
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric struct NameEntry {
1250b57cec5SDimitry Andric   uint32_t Index;
1260b57cec5SDimitry Andric   StringRef Name;
1270b57cec5SDimitry Andric };
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric struct ProducerEntry {
1300b57cec5SDimitry Andric   std::string Name;
1310b57cec5SDimitry Andric   std::string Version;
1320b57cec5SDimitry Andric };
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric struct FeatureEntry {
1350b57cec5SDimitry Andric   FeaturePolicyPrefix Prefix;
1360b57cec5SDimitry Andric   std::string Name;
1370b57cec5SDimitry Andric };
1380b57cec5SDimitry Andric 
1390b57cec5SDimitry Andric struct SegmentInfo {
1400b57cec5SDimitry Andric   uint32_t Index;
1410b57cec5SDimitry Andric   StringRef Name;
1420b57cec5SDimitry Andric   uint32_t Alignment;
1430b57cec5SDimitry Andric   SegmentFlags Flags;
1440b57cec5SDimitry Andric };
1450b57cec5SDimitry Andric 
1460b57cec5SDimitry Andric struct Signature {
1470b57cec5SDimitry Andric   uint32_t Index;
1480b57cec5SDimitry Andric   SignatureForm Form = wasm::WASM_TYPE_FUNC;
1490b57cec5SDimitry Andric   std::vector<ValueType> ParamTypes;
1508bcb0991SDimitry Andric   std::vector<ValueType> ReturnTypes;
1510b57cec5SDimitry Andric };
1520b57cec5SDimitry Andric 
1530b57cec5SDimitry Andric struct SymbolInfo {
1540b57cec5SDimitry Andric   uint32_t Index;
1550b57cec5SDimitry Andric   StringRef Name;
1560b57cec5SDimitry Andric   SymbolKind Kind;
1570b57cec5SDimitry Andric   SymbolFlags Flags;
1580b57cec5SDimitry Andric   union {
1590b57cec5SDimitry Andric     uint32_t ElementIndex;
1600b57cec5SDimitry Andric     wasm::WasmDataReference DataRef;
1610b57cec5SDimitry Andric   };
1620b57cec5SDimitry Andric };
1630b57cec5SDimitry Andric 
1640b57cec5SDimitry Andric struct InitFunction {
1650b57cec5SDimitry Andric   uint32_t Priority;
1660b57cec5SDimitry Andric   uint32_t Symbol;
1670b57cec5SDimitry Andric };
1680b57cec5SDimitry Andric 
1690b57cec5SDimitry Andric struct ComdatEntry {
1700b57cec5SDimitry Andric   ComdatKind Kind;
1710b57cec5SDimitry Andric   uint32_t Index;
1720b57cec5SDimitry Andric };
1730b57cec5SDimitry Andric 
1740b57cec5SDimitry Andric struct Comdat {
1750b57cec5SDimitry Andric   StringRef Name;
1760b57cec5SDimitry Andric   std::vector<ComdatEntry> Entries;
1770b57cec5SDimitry Andric };
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric struct Section {
1800b57cec5SDimitry Andric   explicit Section(SectionType SecType) : Type(SecType) {}
1810b57cec5SDimitry Andric   virtual ~Section();
1820b57cec5SDimitry Andric 
1830b57cec5SDimitry Andric   SectionType Type;
1840b57cec5SDimitry Andric   std::vector<Relocation> Relocations;
1850b57cec5SDimitry Andric };
1860b57cec5SDimitry Andric 
1870b57cec5SDimitry Andric struct CustomSection : Section {
1880b57cec5SDimitry Andric   explicit CustomSection(StringRef Name)
1890b57cec5SDimitry Andric       : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
1900b57cec5SDimitry Andric 
1910b57cec5SDimitry Andric   static bool classof(const Section *S) {
1920b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_CUSTOM;
1930b57cec5SDimitry Andric   }
1940b57cec5SDimitry Andric 
1950b57cec5SDimitry Andric   StringRef Name;
1960b57cec5SDimitry Andric   yaml::BinaryRef Payload;
1970b57cec5SDimitry Andric };
1980b57cec5SDimitry Andric 
1990b57cec5SDimitry Andric struct DylinkSection : CustomSection {
2000b57cec5SDimitry Andric   DylinkSection() : CustomSection("dylink") {}
2010b57cec5SDimitry Andric 
2020b57cec5SDimitry Andric   static bool classof(const Section *S) {
2030b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2040b57cec5SDimitry Andric     return C && C->Name == "dylink";
2050b57cec5SDimitry Andric   }
2060b57cec5SDimitry Andric 
2070b57cec5SDimitry Andric   uint32_t MemorySize;
2080b57cec5SDimitry Andric   uint32_t MemoryAlignment;
2090b57cec5SDimitry Andric   uint32_t TableSize;
2100b57cec5SDimitry Andric   uint32_t TableAlignment;
2110b57cec5SDimitry Andric   std::vector<StringRef> Needed;
2120b57cec5SDimitry Andric };
2130b57cec5SDimitry Andric 
2140b57cec5SDimitry Andric struct NameSection : CustomSection {
2150b57cec5SDimitry Andric   NameSection() : CustomSection("name") {}
2160b57cec5SDimitry Andric 
2170b57cec5SDimitry Andric   static bool classof(const Section *S) {
2180b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2190b57cec5SDimitry Andric     return C && C->Name == "name";
2200b57cec5SDimitry Andric   }
2210b57cec5SDimitry Andric 
2220b57cec5SDimitry Andric   std::vector<NameEntry> FunctionNames;
2230b57cec5SDimitry Andric };
2240b57cec5SDimitry Andric 
2250b57cec5SDimitry Andric struct LinkingSection : CustomSection {
2260b57cec5SDimitry Andric   LinkingSection() : CustomSection("linking") {}
2270b57cec5SDimitry Andric 
2280b57cec5SDimitry Andric   static bool classof(const Section *S) {
2290b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2300b57cec5SDimitry Andric     return C && C->Name == "linking";
2310b57cec5SDimitry Andric   }
2320b57cec5SDimitry Andric 
2330b57cec5SDimitry Andric   uint32_t Version;
2340b57cec5SDimitry Andric   std::vector<SymbolInfo> SymbolTable;
2350b57cec5SDimitry Andric   std::vector<SegmentInfo> SegmentInfos;
2360b57cec5SDimitry Andric   std::vector<InitFunction> InitFunctions;
2370b57cec5SDimitry Andric   std::vector<Comdat> Comdats;
2380b57cec5SDimitry Andric };
2390b57cec5SDimitry Andric 
2400b57cec5SDimitry Andric struct ProducersSection : CustomSection {
2410b57cec5SDimitry Andric   ProducersSection() : CustomSection("producers") {}
2420b57cec5SDimitry Andric 
2430b57cec5SDimitry Andric   static bool classof(const Section *S) {
2440b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2450b57cec5SDimitry Andric     return C && C->Name == "producers";
2460b57cec5SDimitry Andric   }
2470b57cec5SDimitry Andric 
2480b57cec5SDimitry Andric   std::vector<ProducerEntry> Languages;
2490b57cec5SDimitry Andric   std::vector<ProducerEntry> Tools;
2500b57cec5SDimitry Andric   std::vector<ProducerEntry> SDKs;
2510b57cec5SDimitry Andric };
2520b57cec5SDimitry Andric 
2530b57cec5SDimitry Andric struct TargetFeaturesSection : CustomSection {
2540b57cec5SDimitry Andric   TargetFeaturesSection() : CustomSection("target_features") {}
2550b57cec5SDimitry Andric 
2560b57cec5SDimitry Andric   static bool classof(const Section *S) {
2570b57cec5SDimitry Andric     auto C = dyn_cast<CustomSection>(S);
2580b57cec5SDimitry Andric     return C && C->Name == "target_features";
2590b57cec5SDimitry Andric   }
2600b57cec5SDimitry Andric 
2610b57cec5SDimitry Andric   std::vector<FeatureEntry> Features;
2620b57cec5SDimitry Andric };
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric struct TypeSection : Section {
2650b57cec5SDimitry Andric   TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
2660b57cec5SDimitry Andric 
2670b57cec5SDimitry Andric   static bool classof(const Section *S) {
2680b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_TYPE;
2690b57cec5SDimitry Andric   }
2700b57cec5SDimitry Andric 
2710b57cec5SDimitry Andric   std::vector<Signature> Signatures;
2720b57cec5SDimitry Andric };
2730b57cec5SDimitry Andric 
2740b57cec5SDimitry Andric struct ImportSection : Section {
2750b57cec5SDimitry Andric   ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
2760b57cec5SDimitry Andric 
2770b57cec5SDimitry Andric   static bool classof(const Section *S) {
2780b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_IMPORT;
2790b57cec5SDimitry Andric   }
2800b57cec5SDimitry Andric 
2810b57cec5SDimitry Andric   std::vector<Import> Imports;
2820b57cec5SDimitry Andric };
2830b57cec5SDimitry Andric 
2840b57cec5SDimitry Andric struct FunctionSection : Section {
2850b57cec5SDimitry Andric   FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
2860b57cec5SDimitry Andric 
2870b57cec5SDimitry Andric   static bool classof(const Section *S) {
2880b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_FUNCTION;
2890b57cec5SDimitry Andric   }
2900b57cec5SDimitry Andric 
2910b57cec5SDimitry Andric   std::vector<uint32_t> FunctionTypes;
2920b57cec5SDimitry Andric };
2930b57cec5SDimitry Andric 
2940b57cec5SDimitry Andric struct TableSection : Section {
2950b57cec5SDimitry Andric   TableSection() : Section(wasm::WASM_SEC_TABLE) {}
2960b57cec5SDimitry Andric 
2970b57cec5SDimitry Andric   static bool classof(const Section *S) {
2980b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_TABLE;
2990b57cec5SDimitry Andric   }
3000b57cec5SDimitry Andric 
3010b57cec5SDimitry Andric   std::vector<Table> Tables;
3020b57cec5SDimitry Andric };
3030b57cec5SDimitry Andric 
3040b57cec5SDimitry Andric struct MemorySection : Section {
3050b57cec5SDimitry Andric   MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
3060b57cec5SDimitry Andric 
3070b57cec5SDimitry Andric   static bool classof(const Section *S) {
3080b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_MEMORY;
3090b57cec5SDimitry Andric   }
3100b57cec5SDimitry Andric 
3110b57cec5SDimitry Andric   std::vector<Limits> Memories;
3120b57cec5SDimitry Andric };
3130b57cec5SDimitry Andric 
3140b57cec5SDimitry Andric struct EventSection : Section {
3150b57cec5SDimitry Andric   EventSection() : Section(wasm::WASM_SEC_EVENT) {}
3160b57cec5SDimitry Andric 
3170b57cec5SDimitry Andric   static bool classof(const Section *S) {
3180b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_EVENT;
3190b57cec5SDimitry Andric   }
3200b57cec5SDimitry Andric 
3210b57cec5SDimitry Andric   std::vector<Event> Events;
3220b57cec5SDimitry Andric };
3230b57cec5SDimitry Andric 
324*5ffd83dbSDimitry Andric struct GlobalSection : Section {
325*5ffd83dbSDimitry Andric   GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
326*5ffd83dbSDimitry Andric 
327*5ffd83dbSDimitry Andric   static bool classof(const Section *S) {
328*5ffd83dbSDimitry Andric     return S->Type == wasm::WASM_SEC_GLOBAL;
329*5ffd83dbSDimitry Andric   }
330*5ffd83dbSDimitry Andric 
331*5ffd83dbSDimitry Andric   std::vector<Global> Globals;
332*5ffd83dbSDimitry Andric };
333*5ffd83dbSDimitry Andric 
3340b57cec5SDimitry Andric struct ExportSection : Section {
3350b57cec5SDimitry Andric   ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
3360b57cec5SDimitry Andric 
3370b57cec5SDimitry Andric   static bool classof(const Section *S) {
3380b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_EXPORT;
3390b57cec5SDimitry Andric   }
3400b57cec5SDimitry Andric 
3410b57cec5SDimitry Andric   std::vector<Export> Exports;
3420b57cec5SDimitry Andric };
3430b57cec5SDimitry Andric 
3440b57cec5SDimitry Andric struct StartSection : Section {
3450b57cec5SDimitry Andric   StartSection() : Section(wasm::WASM_SEC_START) {}
3460b57cec5SDimitry Andric 
3470b57cec5SDimitry Andric   static bool classof(const Section *S) {
3480b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_START;
3490b57cec5SDimitry Andric   }
3500b57cec5SDimitry Andric 
3510b57cec5SDimitry Andric   uint32_t StartFunction;
3520b57cec5SDimitry Andric };
3530b57cec5SDimitry Andric 
3540b57cec5SDimitry Andric struct ElemSection : Section {
3550b57cec5SDimitry Andric   ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
3560b57cec5SDimitry Andric 
3570b57cec5SDimitry Andric   static bool classof(const Section *S) {
3580b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_ELEM;
3590b57cec5SDimitry Andric   }
3600b57cec5SDimitry Andric 
3610b57cec5SDimitry Andric   std::vector<ElemSegment> Segments;
3620b57cec5SDimitry Andric };
3630b57cec5SDimitry Andric 
3640b57cec5SDimitry Andric struct CodeSection : Section {
3650b57cec5SDimitry Andric   CodeSection() : Section(wasm::WASM_SEC_CODE) {}
3660b57cec5SDimitry Andric 
3670b57cec5SDimitry Andric   static bool classof(const Section *S) {
3680b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_CODE;
3690b57cec5SDimitry Andric   }
3700b57cec5SDimitry Andric 
3710b57cec5SDimitry Andric   std::vector<Function> Functions;
3720b57cec5SDimitry Andric };
3730b57cec5SDimitry Andric 
3740b57cec5SDimitry Andric struct DataSection : Section {
3750b57cec5SDimitry Andric   DataSection() : Section(wasm::WASM_SEC_DATA) {}
3760b57cec5SDimitry Andric 
3770b57cec5SDimitry Andric   static bool classof(const Section *S) {
3780b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_DATA;
3790b57cec5SDimitry Andric   }
3800b57cec5SDimitry Andric 
3810b57cec5SDimitry Andric   std::vector<DataSegment> Segments;
3820b57cec5SDimitry Andric };
3830b57cec5SDimitry Andric 
3840b57cec5SDimitry Andric struct DataCountSection : Section {
3850b57cec5SDimitry Andric   DataCountSection() : Section(wasm::WASM_SEC_DATACOUNT) {}
3860b57cec5SDimitry Andric 
3870b57cec5SDimitry Andric   static bool classof(const Section *S) {
3880b57cec5SDimitry Andric     return S->Type == wasm::WASM_SEC_DATACOUNT;
3890b57cec5SDimitry Andric   }
3900b57cec5SDimitry Andric 
3910b57cec5SDimitry Andric   uint32_t Count;
3920b57cec5SDimitry Andric };
3930b57cec5SDimitry Andric 
3940b57cec5SDimitry Andric struct Object {
3950b57cec5SDimitry Andric   FileHeader Header;
3960b57cec5SDimitry Andric   std::vector<std::unique_ptr<Section>> Sections;
3970b57cec5SDimitry Andric };
3980b57cec5SDimitry Andric 
3990b57cec5SDimitry Andric } // end namespace WasmYAML
4000b57cec5SDimitry Andric } // end namespace llvm
4010b57cec5SDimitry Andric 
4020b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
4030b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
4040b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
4050b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
4060b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
4070b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
4080b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
4090b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
4100b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
4110b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
4120b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
4130b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
4140b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
4150b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
4160b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ProducerEntry)
4170b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::FeatureEntry)
4180b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo)
4190b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
4200b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction)
4210b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry)
4220b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat)
4230b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Event)
4240b57cec5SDimitry Andric 
4250b57cec5SDimitry Andric namespace llvm {
4260b57cec5SDimitry Andric namespace yaml {
4270b57cec5SDimitry Andric 
4280b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::FileHeader> {
4290b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
4300b57cec5SDimitry Andric };
4310b57cec5SDimitry Andric 
4320b57cec5SDimitry Andric template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
4330b57cec5SDimitry Andric   static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
4340b57cec5SDimitry Andric };
4350b57cec5SDimitry Andric 
4360b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Object> {
4370b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Object &Object);
4380b57cec5SDimitry Andric };
4390b57cec5SDimitry Andric 
4400b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Import> {
4410b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Import &Import);
4420b57cec5SDimitry Andric };
4430b57cec5SDimitry Andric 
4440b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Export> {
4450b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Export &Export);
4460b57cec5SDimitry Andric };
4470b57cec5SDimitry Andric 
4480b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Global> {
4490b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Global &Global);
4500b57cec5SDimitry Andric };
4510b57cec5SDimitry Andric 
4520b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
4530b57cec5SDimitry Andric   static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
4540b57cec5SDimitry Andric };
4550b57cec5SDimitry Andric 
4560b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
4570b57cec5SDimitry Andric   static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
4580b57cec5SDimitry Andric };
4590b57cec5SDimitry Andric 
4600b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> {
4610b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind);
4620b57cec5SDimitry Andric };
4630b57cec5SDimitry Andric 
4640b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
4650b57cec5SDimitry Andric   static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
4660b57cec5SDimitry Andric };
4670b57cec5SDimitry Andric 
4680b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
4690b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::SectionType &Type);
4700b57cec5SDimitry Andric };
4710b57cec5SDimitry Andric 
4720b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Signature> {
4730b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Signature &Signature);
4740b57cec5SDimitry Andric };
4750b57cec5SDimitry Andric 
4760b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Table> {
4770b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Table &Table);
4780b57cec5SDimitry Andric };
4790b57cec5SDimitry Andric 
4800b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Limits> {
4810b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Limits &Limits);
4820b57cec5SDimitry Andric };
4830b57cec5SDimitry Andric 
4840b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Function> {
4850b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Function &Function);
4860b57cec5SDimitry Andric };
4870b57cec5SDimitry Andric 
4880b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Relocation> {
4890b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
4900b57cec5SDimitry Andric };
4910b57cec5SDimitry Andric 
4920b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::NameEntry> {
4930b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
4940b57cec5SDimitry Andric };
4950b57cec5SDimitry Andric 
4960b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ProducerEntry> {
4970b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::ProducerEntry &ProducerEntry);
4980b57cec5SDimitry Andric };
4990b57cec5SDimitry Andric 
5000b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix> {
5010b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::FeaturePolicyPrefix &Prefix);
5020b57cec5SDimitry Andric };
5030b57cec5SDimitry Andric 
5040b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::FeatureEntry> {
5050b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::FeatureEntry &FeatureEntry);
5060b57cec5SDimitry Andric };
5070b57cec5SDimitry Andric 
5080b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::SegmentInfo> {
5090b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
5100b57cec5SDimitry Andric };
5110b57cec5SDimitry Andric 
5120b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::LocalDecl> {
5130b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
5140b57cec5SDimitry Andric };
5150b57cec5SDimitry Andric 
5160b57cec5SDimitry Andric template <> struct MappingTraits<wasm::WasmInitExpr> {
5170b57cec5SDimitry Andric   static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
5180b57cec5SDimitry Andric };
5190b57cec5SDimitry Andric 
5200b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::DataSegment> {
5210b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
5220b57cec5SDimitry Andric };
5230b57cec5SDimitry Andric 
5240b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ElemSegment> {
5250b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
5260b57cec5SDimitry Andric };
5270b57cec5SDimitry Andric 
5280b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::SymbolInfo> {
5290b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
5300b57cec5SDimitry Andric };
5310b57cec5SDimitry Andric 
5320b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::InitFunction> {
5330b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::InitFunction &Init);
5340b57cec5SDimitry Andric };
5350b57cec5SDimitry Andric 
5360b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> {
5370b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind);
5380b57cec5SDimitry Andric };
5390b57cec5SDimitry Andric 
5400b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ComdatEntry> {
5410b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry);
5420b57cec5SDimitry Andric };
5430b57cec5SDimitry Andric 
5440b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Comdat> {
5450b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Comdat &Comdat);
5460b57cec5SDimitry Andric };
5470b57cec5SDimitry Andric 
5480b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
5490b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::ValueType &Type);
5500b57cec5SDimitry Andric };
5510b57cec5SDimitry Andric 
5520b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
5530b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
5540b57cec5SDimitry Andric };
5550b57cec5SDimitry Andric 
5560b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
5570b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::TableType &Type);
5580b57cec5SDimitry Andric };
5590b57cec5SDimitry Andric 
5600b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
5610b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
5620b57cec5SDimitry Andric };
5630b57cec5SDimitry Andric 
5640b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
5650b57cec5SDimitry Andric   static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
5660b57cec5SDimitry Andric };
5670b57cec5SDimitry Andric 
5680b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Event> {
5690b57cec5SDimitry Andric   static void mapping(IO &IO, WasmYAML::Event &Event);
5700b57cec5SDimitry Andric };
5710b57cec5SDimitry Andric 
5720b57cec5SDimitry Andric } // end namespace yaml
5730b57cec5SDimitry Andric } // end namespace llvm
5740b57cec5SDimitry Andric 
5750b57cec5SDimitry Andric #endif // LLVM_OBJECTYAML_WASMYAML_H
576