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
6581ad6265SDimitry Andric struct InitExpr {
InitExprInitExpr6681ad6265SDimitry Andric InitExpr() {}
6781ad6265SDimitry Andric bool Extended;
6881ad6265SDimitry Andric union {
6981ad6265SDimitry Andric wasm::WasmInitExprMVP Inst;
7081ad6265SDimitry Andric yaml::BinaryRef Body;
7181ad6265SDimitry Andric };
7281ad6265SDimitry Andric };
7381ad6265SDimitry Andric
740b57cec5SDimitry Andric struct ElemSegment {
75fe6060f1SDimitry Andric uint32_t Flags;
76fe6060f1SDimitry Andric uint32_t TableNumber;
77fe6060f1SDimitry Andric ValueType ElemKind;
7881ad6265SDimitry Andric InitExpr Offset;
790b57cec5SDimitry Andric std::vector<uint32_t> Functions;
800b57cec5SDimitry Andric };
810b57cec5SDimitry Andric
820b57cec5SDimitry Andric struct Global {
830b57cec5SDimitry Andric uint32_t Index;
840b57cec5SDimitry Andric ValueType Type;
850b57cec5SDimitry Andric bool Mutable;
8681ad6265SDimitry Andric InitExpr Init;
870b57cec5SDimitry Andric };
880b57cec5SDimitry Andric
890b57cec5SDimitry Andric struct Import {
ImportImport9081ad6265SDimitry Andric Import() {}
910b57cec5SDimitry Andric StringRef Module;
920b57cec5SDimitry Andric StringRef Field;
930b57cec5SDimitry Andric ExportKind Kind;
940b57cec5SDimitry Andric union {
950b57cec5SDimitry Andric uint32_t SigIndex;
960b57cec5SDimitry Andric Table TableImport;
970b57cec5SDimitry Andric Limits Memory;
98349cc55cSDimitry Andric uint32_t TagIndex;
9981ad6265SDimitry Andric Global GlobalImport;
1000b57cec5SDimitry Andric };
1010b57cec5SDimitry Andric };
1020b57cec5SDimitry Andric
1030b57cec5SDimitry Andric struct LocalDecl {
1040b57cec5SDimitry Andric ValueType Type;
1050b57cec5SDimitry Andric uint32_t Count;
1060b57cec5SDimitry Andric };
1070b57cec5SDimitry Andric
1080b57cec5SDimitry Andric struct Function {
1090b57cec5SDimitry Andric uint32_t Index;
1100b57cec5SDimitry Andric std::vector<LocalDecl> Locals;
1110b57cec5SDimitry Andric yaml::BinaryRef Body;
1120b57cec5SDimitry Andric };
1130b57cec5SDimitry Andric
1140b57cec5SDimitry Andric struct Relocation {
1150b57cec5SDimitry Andric RelocType Type;
1160b57cec5SDimitry Andric uint32_t Index;
1175ffd83dbSDimitry Andric // TODO(wvo): this would strictly be better as Hex64, but that will change
1185ffd83dbSDimitry Andric // all existing obj2yaml output.
1190b57cec5SDimitry Andric yaml::Hex32 Offset;
1205ffd83dbSDimitry Andric int64_t Addend;
1210b57cec5SDimitry Andric };
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric struct DataSegment {
1240b57cec5SDimitry Andric uint32_t SectionOffset;
1250b57cec5SDimitry Andric uint32_t InitFlags;
1260b57cec5SDimitry Andric uint32_t MemoryIndex;
12781ad6265SDimitry Andric InitExpr Offset;
1280b57cec5SDimitry Andric yaml::BinaryRef Content;
1290b57cec5SDimitry Andric };
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andric struct NameEntry {
1320b57cec5SDimitry Andric uint32_t Index;
1330b57cec5SDimitry Andric StringRef Name;
1340b57cec5SDimitry Andric };
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andric struct ProducerEntry {
1370b57cec5SDimitry Andric std::string Name;
1380b57cec5SDimitry Andric std::string Version;
1390b57cec5SDimitry Andric };
1400b57cec5SDimitry Andric
1410b57cec5SDimitry Andric struct FeatureEntry {
1420b57cec5SDimitry Andric FeaturePolicyPrefix Prefix;
1430b57cec5SDimitry Andric std::string Name;
1440b57cec5SDimitry Andric };
1450b57cec5SDimitry Andric
1460b57cec5SDimitry Andric struct SegmentInfo {
1470b57cec5SDimitry Andric uint32_t Index;
1480b57cec5SDimitry Andric StringRef Name;
1490b57cec5SDimitry Andric uint32_t Alignment;
1500b57cec5SDimitry Andric SegmentFlags Flags;
1510b57cec5SDimitry Andric };
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric struct Signature {
1540b57cec5SDimitry Andric uint32_t Index;
1550b57cec5SDimitry Andric SignatureForm Form = wasm::WASM_TYPE_FUNC;
1560b57cec5SDimitry Andric std::vector<ValueType> ParamTypes;
1578bcb0991SDimitry Andric std::vector<ValueType> ReturnTypes;
1580b57cec5SDimitry Andric };
1590b57cec5SDimitry Andric
1600b57cec5SDimitry Andric struct SymbolInfo {
1610b57cec5SDimitry Andric uint32_t Index;
1620b57cec5SDimitry Andric StringRef Name;
1630b57cec5SDimitry Andric SymbolKind Kind;
1640b57cec5SDimitry Andric SymbolFlags Flags;
1650b57cec5SDimitry Andric union {
1660b57cec5SDimitry Andric uint32_t ElementIndex;
1670b57cec5SDimitry Andric wasm::WasmDataReference DataRef;
1680b57cec5SDimitry Andric };
1690b57cec5SDimitry Andric };
1700b57cec5SDimitry Andric
1710b57cec5SDimitry Andric struct InitFunction {
1720b57cec5SDimitry Andric uint32_t Priority;
1730b57cec5SDimitry Andric uint32_t Symbol;
1740b57cec5SDimitry Andric };
1750b57cec5SDimitry Andric
1760b57cec5SDimitry Andric struct ComdatEntry {
1770b57cec5SDimitry Andric ComdatKind Kind;
1780b57cec5SDimitry Andric uint32_t Index;
1790b57cec5SDimitry Andric };
1800b57cec5SDimitry Andric
1810b57cec5SDimitry Andric struct Comdat {
1820b57cec5SDimitry Andric StringRef Name;
1830b57cec5SDimitry Andric std::vector<ComdatEntry> Entries;
1840b57cec5SDimitry Andric };
1850b57cec5SDimitry Andric
1860b57cec5SDimitry Andric struct Section {
SectionSection1870b57cec5SDimitry Andric explicit Section(SectionType SecType) : Type(SecType) {}
1880b57cec5SDimitry Andric virtual ~Section();
1890b57cec5SDimitry Andric
1900b57cec5SDimitry Andric SectionType Type;
1910b57cec5SDimitry Andric std::vector<Relocation> Relocations;
192*8a4dda33SDimitry Andric std::optional<uint8_t> HeaderSecSizeEncodingLen;
1930b57cec5SDimitry Andric };
1940b57cec5SDimitry Andric
1950b57cec5SDimitry Andric struct CustomSection : Section {
CustomSectionCustomSection1960b57cec5SDimitry Andric explicit CustomSection(StringRef Name)
1970b57cec5SDimitry Andric : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
1980b57cec5SDimitry Andric
classofCustomSection1990b57cec5SDimitry Andric static bool classof(const Section *S) {
2000b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_CUSTOM;
2010b57cec5SDimitry Andric }
2020b57cec5SDimitry Andric
2030b57cec5SDimitry Andric StringRef Name;
2040b57cec5SDimitry Andric yaml::BinaryRef Payload;
2050b57cec5SDimitry Andric };
2060b57cec5SDimitry Andric
207349cc55cSDimitry Andric struct DylinkImportInfo {
208349cc55cSDimitry Andric StringRef Module;
209349cc55cSDimitry Andric StringRef Field;
210349cc55cSDimitry Andric SymbolFlags Flags;
211349cc55cSDimitry Andric };
212349cc55cSDimitry Andric
213349cc55cSDimitry Andric struct DylinkExportInfo {
214349cc55cSDimitry Andric StringRef Name;
215349cc55cSDimitry Andric SymbolFlags Flags;
216349cc55cSDimitry Andric };
217349cc55cSDimitry Andric
2180b57cec5SDimitry Andric struct DylinkSection : CustomSection {
DylinkSectionDylinkSection219349cc55cSDimitry Andric DylinkSection() : CustomSection("dylink.0") {}
2200b57cec5SDimitry Andric
classofDylinkSection2210b57cec5SDimitry Andric static bool classof(const Section *S) {
2220b57cec5SDimitry Andric auto C = dyn_cast<CustomSection>(S);
223349cc55cSDimitry Andric return C && C->Name == "dylink.0";
2240b57cec5SDimitry Andric }
2250b57cec5SDimitry Andric
2260b57cec5SDimitry Andric uint32_t MemorySize;
2270b57cec5SDimitry Andric uint32_t MemoryAlignment;
2280b57cec5SDimitry Andric uint32_t TableSize;
2290b57cec5SDimitry Andric uint32_t TableAlignment;
2300b57cec5SDimitry Andric std::vector<StringRef> Needed;
231349cc55cSDimitry Andric std::vector<DylinkImportInfo> ImportInfo;
232349cc55cSDimitry Andric std::vector<DylinkExportInfo> ExportInfo;
2330b57cec5SDimitry Andric };
2340b57cec5SDimitry Andric
2350b57cec5SDimitry Andric struct NameSection : CustomSection {
NameSectionNameSection2360b57cec5SDimitry Andric NameSection() : CustomSection("name") {}
2370b57cec5SDimitry Andric
classofNameSection2380b57cec5SDimitry Andric static bool classof(const Section *S) {
2390b57cec5SDimitry Andric auto C = dyn_cast<CustomSection>(S);
2400b57cec5SDimitry Andric return C && C->Name == "name";
2410b57cec5SDimitry Andric }
2420b57cec5SDimitry Andric
2430b57cec5SDimitry Andric std::vector<NameEntry> FunctionNames;
244e8d8bef9SDimitry Andric std::vector<NameEntry> GlobalNames;
245e8d8bef9SDimitry Andric std::vector<NameEntry> DataSegmentNames;
2460b57cec5SDimitry Andric };
2470b57cec5SDimitry Andric
2480b57cec5SDimitry Andric struct LinkingSection : CustomSection {
LinkingSectionLinkingSection2490b57cec5SDimitry Andric LinkingSection() : CustomSection("linking") {}
2500b57cec5SDimitry Andric
classofLinkingSection2510b57cec5SDimitry Andric static bool classof(const Section *S) {
2520b57cec5SDimitry Andric auto C = dyn_cast<CustomSection>(S);
2530b57cec5SDimitry Andric return C && C->Name == "linking";
2540b57cec5SDimitry Andric }
2550b57cec5SDimitry Andric
2560b57cec5SDimitry Andric uint32_t Version;
2570b57cec5SDimitry Andric std::vector<SymbolInfo> SymbolTable;
2580b57cec5SDimitry Andric std::vector<SegmentInfo> SegmentInfos;
2590b57cec5SDimitry Andric std::vector<InitFunction> InitFunctions;
2600b57cec5SDimitry Andric std::vector<Comdat> Comdats;
2610b57cec5SDimitry Andric };
2620b57cec5SDimitry Andric
2630b57cec5SDimitry Andric struct ProducersSection : CustomSection {
ProducersSectionProducersSection2640b57cec5SDimitry Andric ProducersSection() : CustomSection("producers") {}
2650b57cec5SDimitry Andric
classofProducersSection2660b57cec5SDimitry Andric static bool classof(const Section *S) {
2670b57cec5SDimitry Andric auto C = dyn_cast<CustomSection>(S);
2680b57cec5SDimitry Andric return C && C->Name == "producers";
2690b57cec5SDimitry Andric }
2700b57cec5SDimitry Andric
2710b57cec5SDimitry Andric std::vector<ProducerEntry> Languages;
2720b57cec5SDimitry Andric std::vector<ProducerEntry> Tools;
2730b57cec5SDimitry Andric std::vector<ProducerEntry> SDKs;
2740b57cec5SDimitry Andric };
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andric struct TargetFeaturesSection : CustomSection {
TargetFeaturesSectionTargetFeaturesSection2770b57cec5SDimitry Andric TargetFeaturesSection() : CustomSection("target_features") {}
2780b57cec5SDimitry Andric
classofTargetFeaturesSection2790b57cec5SDimitry Andric static bool classof(const Section *S) {
2800b57cec5SDimitry Andric auto C = dyn_cast<CustomSection>(S);
2810b57cec5SDimitry Andric return C && C->Name == "target_features";
2820b57cec5SDimitry Andric }
2830b57cec5SDimitry Andric
2840b57cec5SDimitry Andric std::vector<FeatureEntry> Features;
2850b57cec5SDimitry Andric };
2860b57cec5SDimitry Andric
2870b57cec5SDimitry Andric struct TypeSection : Section {
TypeSectionTypeSection2880b57cec5SDimitry Andric TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
2890b57cec5SDimitry Andric
classofTypeSection2900b57cec5SDimitry Andric static bool classof(const Section *S) {
2910b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_TYPE;
2920b57cec5SDimitry Andric }
2930b57cec5SDimitry Andric
2940b57cec5SDimitry Andric std::vector<Signature> Signatures;
2950b57cec5SDimitry Andric };
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andric struct ImportSection : Section {
ImportSectionImportSection2980b57cec5SDimitry Andric ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
2990b57cec5SDimitry Andric
classofImportSection3000b57cec5SDimitry Andric static bool classof(const Section *S) {
3010b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_IMPORT;
3020b57cec5SDimitry Andric }
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric std::vector<Import> Imports;
3050b57cec5SDimitry Andric };
3060b57cec5SDimitry Andric
3070b57cec5SDimitry Andric struct FunctionSection : Section {
FunctionSectionFunctionSection3080b57cec5SDimitry Andric FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
3090b57cec5SDimitry Andric
classofFunctionSection3100b57cec5SDimitry Andric static bool classof(const Section *S) {
3110b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_FUNCTION;
3120b57cec5SDimitry Andric }
3130b57cec5SDimitry Andric
3140b57cec5SDimitry Andric std::vector<uint32_t> FunctionTypes;
3150b57cec5SDimitry Andric };
3160b57cec5SDimitry Andric
3170b57cec5SDimitry Andric struct TableSection : Section {
TableSectionTableSection3180b57cec5SDimitry Andric TableSection() : Section(wasm::WASM_SEC_TABLE) {}
3190b57cec5SDimitry Andric
classofTableSection3200b57cec5SDimitry Andric static bool classof(const Section *S) {
3210b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_TABLE;
3220b57cec5SDimitry Andric }
3230b57cec5SDimitry Andric
3240b57cec5SDimitry Andric std::vector<Table> Tables;
3250b57cec5SDimitry Andric };
3260b57cec5SDimitry Andric
3270b57cec5SDimitry Andric struct MemorySection : Section {
MemorySectionMemorySection3280b57cec5SDimitry Andric MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
3290b57cec5SDimitry Andric
classofMemorySection3300b57cec5SDimitry Andric static bool classof(const Section *S) {
3310b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_MEMORY;
3320b57cec5SDimitry Andric }
3330b57cec5SDimitry Andric
3340b57cec5SDimitry Andric std::vector<Limits> Memories;
3350b57cec5SDimitry Andric };
3360b57cec5SDimitry Andric
337fe6060f1SDimitry Andric struct TagSection : Section {
TagSectionTagSection338fe6060f1SDimitry Andric TagSection() : Section(wasm::WASM_SEC_TAG) {}
3390b57cec5SDimitry Andric
classofTagSection3400b57cec5SDimitry Andric static bool classof(const Section *S) {
341fe6060f1SDimitry Andric return S->Type == wasm::WASM_SEC_TAG;
3420b57cec5SDimitry Andric }
3430b57cec5SDimitry Andric
344349cc55cSDimitry Andric std::vector<uint32_t> TagTypes;
3450b57cec5SDimitry Andric };
3460b57cec5SDimitry Andric
3475ffd83dbSDimitry Andric struct GlobalSection : Section {
GlobalSectionGlobalSection3485ffd83dbSDimitry Andric GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
3495ffd83dbSDimitry Andric
classofGlobalSection3505ffd83dbSDimitry Andric static bool classof(const Section *S) {
3515ffd83dbSDimitry Andric return S->Type == wasm::WASM_SEC_GLOBAL;
3525ffd83dbSDimitry Andric }
3535ffd83dbSDimitry Andric
3545ffd83dbSDimitry Andric std::vector<Global> Globals;
3555ffd83dbSDimitry Andric };
3565ffd83dbSDimitry Andric
3570b57cec5SDimitry Andric struct ExportSection : Section {
ExportSectionExportSection3580b57cec5SDimitry Andric ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
3590b57cec5SDimitry Andric
classofExportSection3600b57cec5SDimitry Andric static bool classof(const Section *S) {
3610b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_EXPORT;
3620b57cec5SDimitry Andric }
3630b57cec5SDimitry Andric
3640b57cec5SDimitry Andric std::vector<Export> Exports;
3650b57cec5SDimitry Andric };
3660b57cec5SDimitry Andric
3670b57cec5SDimitry Andric struct StartSection : Section {
StartSectionStartSection3680b57cec5SDimitry Andric StartSection() : Section(wasm::WASM_SEC_START) {}
3690b57cec5SDimitry Andric
classofStartSection3700b57cec5SDimitry Andric static bool classof(const Section *S) {
3710b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_START;
3720b57cec5SDimitry Andric }
3730b57cec5SDimitry Andric
3740b57cec5SDimitry Andric uint32_t StartFunction;
3750b57cec5SDimitry Andric };
3760b57cec5SDimitry Andric
3770b57cec5SDimitry Andric struct ElemSection : Section {
ElemSectionElemSection3780b57cec5SDimitry Andric ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
3790b57cec5SDimitry Andric
classofElemSection3800b57cec5SDimitry Andric static bool classof(const Section *S) {
3810b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_ELEM;
3820b57cec5SDimitry Andric }
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andric std::vector<ElemSegment> Segments;
3850b57cec5SDimitry Andric };
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andric struct CodeSection : Section {
CodeSectionCodeSection3880b57cec5SDimitry Andric CodeSection() : Section(wasm::WASM_SEC_CODE) {}
3890b57cec5SDimitry Andric
classofCodeSection3900b57cec5SDimitry Andric static bool classof(const Section *S) {
3910b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_CODE;
3920b57cec5SDimitry Andric }
3930b57cec5SDimitry Andric
3940b57cec5SDimitry Andric std::vector<Function> Functions;
3950b57cec5SDimitry Andric };
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andric struct DataSection : Section {
DataSectionDataSection3980b57cec5SDimitry Andric DataSection() : Section(wasm::WASM_SEC_DATA) {}
3990b57cec5SDimitry Andric
classofDataSection4000b57cec5SDimitry Andric static bool classof(const Section *S) {
4010b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_DATA;
4020b57cec5SDimitry Andric }
4030b57cec5SDimitry Andric
4040b57cec5SDimitry Andric std::vector<DataSegment> Segments;
4050b57cec5SDimitry Andric };
4060b57cec5SDimitry Andric
4070b57cec5SDimitry Andric struct DataCountSection : Section {
DataCountSectionDataCountSection4080b57cec5SDimitry Andric DataCountSection() : Section(wasm::WASM_SEC_DATACOUNT) {}
4090b57cec5SDimitry Andric
classofDataCountSection4100b57cec5SDimitry Andric static bool classof(const Section *S) {
4110b57cec5SDimitry Andric return S->Type == wasm::WASM_SEC_DATACOUNT;
4120b57cec5SDimitry Andric }
4130b57cec5SDimitry Andric
4140b57cec5SDimitry Andric uint32_t Count;
4150b57cec5SDimitry Andric };
4160b57cec5SDimitry Andric
4170b57cec5SDimitry Andric struct Object {
4180b57cec5SDimitry Andric FileHeader Header;
4190b57cec5SDimitry Andric std::vector<std::unique_ptr<Section>> Sections;
4200b57cec5SDimitry Andric };
4210b57cec5SDimitry Andric
4220b57cec5SDimitry Andric } // end namespace WasmYAML
4230b57cec5SDimitry Andric } // end namespace llvm
4240b57cec5SDimitry Andric
4250b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)4260b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
4270b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
4280b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
4290b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
4300b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
4310b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
4320b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
4330b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
4340b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
4350b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
4360b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
4370b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
4380b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
4390b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ProducerEntry)
4400b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::FeatureEntry)
4410b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo)
4420b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
4430b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction)
4440b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry)
4450b57cec5SDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat)
446349cc55cSDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DylinkImportInfo)
447349cc55cSDimitry Andric LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DylinkExportInfo)
4480b57cec5SDimitry Andric
4490b57cec5SDimitry Andric namespace llvm {
4500b57cec5SDimitry Andric namespace yaml {
4510b57cec5SDimitry Andric
4520b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::FileHeader> {
4530b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
4540b57cec5SDimitry Andric };
4550b57cec5SDimitry Andric
4560b57cec5SDimitry Andric template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
4570b57cec5SDimitry Andric static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
4580b57cec5SDimitry Andric };
4590b57cec5SDimitry Andric
4600b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Object> {
4610b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Object &Object);
4620b57cec5SDimitry Andric };
4630b57cec5SDimitry Andric
4640b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Import> {
4650b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Import &Import);
4660b57cec5SDimitry Andric };
4670b57cec5SDimitry Andric
4680b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Export> {
4690b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Export &Export);
4700b57cec5SDimitry Andric };
4710b57cec5SDimitry Andric
4720b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Global> {
4730b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Global &Global);
4740b57cec5SDimitry Andric };
4750b57cec5SDimitry Andric
4760b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
4770b57cec5SDimitry Andric static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
4780b57cec5SDimitry Andric };
4790b57cec5SDimitry Andric
4800b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
4810b57cec5SDimitry Andric static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
4820b57cec5SDimitry Andric };
4830b57cec5SDimitry Andric
4840b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> {
4850b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind);
4860b57cec5SDimitry Andric };
4870b57cec5SDimitry Andric
4880b57cec5SDimitry Andric template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
4890b57cec5SDimitry Andric static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
4900b57cec5SDimitry Andric };
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
4930b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::SectionType &Type);
4940b57cec5SDimitry Andric };
4950b57cec5SDimitry Andric
4960b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Signature> {
4970b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Signature &Signature);
4980b57cec5SDimitry Andric };
4990b57cec5SDimitry Andric
5000b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Table> {
5010b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Table &Table);
5020b57cec5SDimitry Andric };
5030b57cec5SDimitry Andric
5040b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Limits> {
5050b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Limits &Limits);
5060b57cec5SDimitry Andric };
5070b57cec5SDimitry Andric
5080b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Function> {
5090b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Function &Function);
5100b57cec5SDimitry Andric };
5110b57cec5SDimitry Andric
5120b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Relocation> {
5130b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
5140b57cec5SDimitry Andric };
5150b57cec5SDimitry Andric
5160b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::NameEntry> {
5170b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
5180b57cec5SDimitry Andric };
5190b57cec5SDimitry Andric
5200b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ProducerEntry> {
5210b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::ProducerEntry &ProducerEntry);
5220b57cec5SDimitry Andric };
5230b57cec5SDimitry Andric
5240b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::FeaturePolicyPrefix> {
5250b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::FeaturePolicyPrefix &Prefix);
5260b57cec5SDimitry Andric };
5270b57cec5SDimitry Andric
5280b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::FeatureEntry> {
5290b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::FeatureEntry &FeatureEntry);
5300b57cec5SDimitry Andric };
5310b57cec5SDimitry Andric
5320b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::SegmentInfo> {
5330b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
5340b57cec5SDimitry Andric };
5350b57cec5SDimitry Andric
5360b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::LocalDecl> {
5370b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
5380b57cec5SDimitry Andric };
5390b57cec5SDimitry Andric
54081ad6265SDimitry Andric template <> struct MappingTraits<WasmYAML::InitExpr> {
54181ad6265SDimitry Andric static void mapping(IO &IO, WasmYAML::InitExpr &Expr);
5420b57cec5SDimitry Andric };
5430b57cec5SDimitry Andric
5440b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::DataSegment> {
5450b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
5460b57cec5SDimitry Andric };
5470b57cec5SDimitry Andric
5480b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ElemSegment> {
5490b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
5500b57cec5SDimitry Andric };
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::SymbolInfo> {
5530b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
5540b57cec5SDimitry Andric };
5550b57cec5SDimitry Andric
5560b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::InitFunction> {
5570b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::InitFunction &Init);
5580b57cec5SDimitry Andric };
5590b57cec5SDimitry Andric
5600b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> {
5610b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind);
5620b57cec5SDimitry Andric };
5630b57cec5SDimitry Andric
5640b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::ComdatEntry> {
5650b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry);
5660b57cec5SDimitry Andric };
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andric template <> struct MappingTraits<WasmYAML::Comdat> {
5690b57cec5SDimitry Andric static void mapping(IO &IO, WasmYAML::Comdat &Comdat);
5700b57cec5SDimitry Andric };
5710b57cec5SDimitry Andric
5720b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
5730b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::ValueType &Type);
5740b57cec5SDimitry Andric };
5750b57cec5SDimitry Andric
5760b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
5770b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
5780b57cec5SDimitry Andric };
5790b57cec5SDimitry Andric
5800b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
5810b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::TableType &Type);
5820b57cec5SDimitry Andric };
5830b57cec5SDimitry Andric
5840b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
5850b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
5860b57cec5SDimitry Andric };
5870b57cec5SDimitry Andric
5880b57cec5SDimitry Andric template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
5890b57cec5SDimitry Andric static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
5900b57cec5SDimitry Andric };
5910b57cec5SDimitry Andric
592349cc55cSDimitry Andric template <> struct MappingTraits<WasmYAML::DylinkImportInfo> {
593349cc55cSDimitry Andric static void mapping(IO &IO, WasmYAML::DylinkImportInfo &Info);
594349cc55cSDimitry Andric };
595349cc55cSDimitry Andric
596349cc55cSDimitry Andric template <> struct MappingTraits<WasmYAML::DylinkExportInfo> {
597349cc55cSDimitry Andric static void mapping(IO &IO, WasmYAML::DylinkExportInfo &Info);
5980b57cec5SDimitry Andric };
5990b57cec5SDimitry Andric
6000b57cec5SDimitry Andric } // end namespace yaml
6010b57cec5SDimitry Andric } // end namespace llvm
6020b57cec5SDimitry Andric
6030b57cec5SDimitry Andric #endif // LLVM_OBJECTYAML_WASMYAML_H
604