1 //===- WasmYAML.h - Wasm YAMLIO implementation ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file declares classes for handling the YAML representation
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_OBJECTYAML_WASMYAML_H
17 #define LLVM_OBJECTYAML_WASMYAML_H
19 #include "llvm/ObjectYAML/YAML.h"
20 #include "llvm/Support/Wasm.h"
25 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionType)
26 LLVM_YAML_STRONG_TYPEDEF(int32_t, ValueType)
27 LLVM_YAML_STRONG_TYPEDEF(int32_t, TableType)
28 LLVM_YAML_STRONG_TYPEDEF(int32_t, SignatureForm)
29 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind)
30 LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode)
31 LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType)
67 wasm::WasmInitExpr Offset;
68 std::vector<uint32_t> Functions;
74 wasm::WasmInitExpr InitExpr;
83 std::vector<LocalDecl> Locals;
96 wasm::WasmInitExpr Offset;
97 yaml::BinaryRef Content;
101 Signature() : Form(wasm::WASM_TYPE_FUNC) {}
105 std::vector<ValueType> ParamTypes;
106 ValueType ReturnType;
110 Section(SectionType SecType) : Type(SecType) {}
114 std::vector<Relocation> Relocations;
117 struct CustomSection : Section {
118 CustomSection() : Section(wasm::WASM_SEC_CUSTOM) {}
119 static bool classof(const Section *S) {
120 return S->Type == wasm::WASM_SEC_CUSTOM;
124 yaml::BinaryRef Payload;
127 struct TypeSection : Section {
128 TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
129 static bool classof(const Section *S) {
130 return S->Type == wasm::WASM_SEC_TYPE;
133 std::vector<Signature> Signatures;
136 struct ImportSection : Section {
137 ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
138 static bool classof(const Section *S) {
139 return S->Type == wasm::WASM_SEC_IMPORT;
142 std::vector<Import> Imports;
145 struct FunctionSection : Section {
146 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
147 static bool classof(const Section *S) {
148 return S->Type == wasm::WASM_SEC_FUNCTION;
151 std::vector<uint32_t> FunctionTypes;
154 struct TableSection : Section {
155 TableSection() : Section(wasm::WASM_SEC_TABLE) {}
156 static bool classof(const Section *S) {
157 return S->Type == wasm::WASM_SEC_TABLE;
160 std::vector<Table> Tables;
163 struct MemorySection : Section {
164 MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
165 static bool classof(const Section *S) {
166 return S->Type == wasm::WASM_SEC_MEMORY;
169 std::vector<Limits> Memories;
172 struct GlobalSection : Section {
173 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
174 static bool classof(const Section *S) {
175 return S->Type == wasm::WASM_SEC_GLOBAL;
178 std::vector<Global> Globals;
181 struct ExportSection : Section {
182 ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
183 static bool classof(const Section *S) {
184 return S->Type == wasm::WASM_SEC_EXPORT;
187 std::vector<Export> Exports;
190 struct StartSection : Section {
191 StartSection() : Section(wasm::WASM_SEC_START) {}
192 static bool classof(const Section *S) {
193 return S->Type == wasm::WASM_SEC_START;
196 uint32_t StartFunction;
199 struct ElemSection : Section {
200 ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
201 static bool classof(const Section *S) {
202 return S->Type == wasm::WASM_SEC_ELEM;
205 std::vector<ElemSegment> Segments;
208 struct CodeSection : Section {
209 CodeSection() : Section(wasm::WASM_SEC_CODE) {}
210 static bool classof(const Section *S) {
211 return S->Type == wasm::WASM_SEC_CODE;
214 std::vector<Function> Functions;
217 struct DataSection : Section {
218 DataSection() : Section(wasm::WASM_SEC_DATA) {}
219 static bool classof(const Section *S) {
220 return S->Type == wasm::WASM_SEC_DATA;
223 std::vector<DataSegment> Segments;
228 std::vector<std::unique_ptr<Section>> Sections;
231 } // end namespace WasmYAML
232 } // end namespace llvm
234 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
235 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
236 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
237 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
238 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
239 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
240 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
241 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
242 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
243 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
244 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
245 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
246 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
247 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
252 template <> struct MappingTraits<WasmYAML::FileHeader> {
253 static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
256 template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
257 static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
260 template <> struct MappingTraits<WasmYAML::Object> {
261 static void mapping(IO &IO, WasmYAML::Object &Object);
264 template <> struct MappingTraits<WasmYAML::Import> {
265 static void mapping(IO &IO, WasmYAML::Import &Import);
268 template <> struct MappingTraits<WasmYAML::Export> {
269 static void mapping(IO &IO, WasmYAML::Export &Export);
272 template <> struct MappingTraits<WasmYAML::Global> {
273 static void mapping(IO &IO, WasmYAML::Global &Global);
276 template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
277 static void enumeration(IO &IO, WasmYAML::SectionType &Type);
280 template <> struct MappingTraits<WasmYAML::Signature> {
281 static void mapping(IO &IO, WasmYAML::Signature &Signature);
284 template <> struct MappingTraits<WasmYAML::Table> {
285 static void mapping(IO &IO, WasmYAML::Table &Table);
288 template <> struct MappingTraits<WasmYAML::Limits> {
289 static void mapping(IO &IO, WasmYAML::Limits &Limits);
292 template <> struct MappingTraits<WasmYAML::Function> {
293 static void mapping(IO &IO, WasmYAML::Function &Function);
296 template <> struct MappingTraits<WasmYAML::Relocation> {
297 static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
300 template <> struct MappingTraits<WasmYAML::LocalDecl> {
301 static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
304 template <> struct MappingTraits<wasm::WasmInitExpr> {
305 static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
308 template <> struct MappingTraits<WasmYAML::DataSegment> {
309 static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
312 template <> struct MappingTraits<WasmYAML::ElemSegment> {
313 static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
316 template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
317 static void enumeration(IO &IO, WasmYAML::ValueType &Type);
320 template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
321 static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
324 template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
325 static void enumeration(IO &IO, WasmYAML::TableType &Type);
328 template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
329 static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
332 template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
333 static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
336 } // end namespace yaml
337 } // end namespace llvm