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 /// 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/ADT/StringRef.h"
20 #include "llvm/BinaryFormat/Wasm.h"
21 #include "llvm/ObjectYAML/YAML.h"
22 #include "llvm/Support/Casting.h"
30 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionType)
31 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ValueType)
32 LLVM_YAML_STRONG_TYPEDEF(uint32_t, TableType)
33 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SignatureForm)
34 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind)
35 LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode)
36 LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType)
37 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolFlags)
38 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolKind)
39 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SegmentFlags)
40 LLVM_YAML_STRONG_TYPEDEF(uint32_t, LimitFlags)
41 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ComdatKind)
66 wasm::WasmInitExpr Offset;
67 std::vector<uint32_t> Functions;
74 wasm::WasmInitExpr InitExpr;
96 std::vector<LocalDecl> Locals;
108 uint32_t MemoryIndex;
109 uint32_t SectionOffset;
110 wasm::WasmInitExpr Offset;
111 yaml::BinaryRef Content;
128 SignatureForm Form = wasm::WASM_TYPE_FUNC;
129 std::vector<ValueType> ParamTypes;
130 ValueType ReturnType;
139 uint32_t ElementIndex;
140 wasm::WasmDataReference DataRef;
144 struct InitFunction {
156 std::vector<ComdatEntry> Entries;
160 explicit Section(SectionType SecType) : Type(SecType) {}
164 std::vector<Relocation> Relocations;
167 struct CustomSection : Section {
168 explicit CustomSection(StringRef Name)
169 : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
171 static bool classof(const Section *S) {
172 return S->Type == wasm::WASM_SEC_CUSTOM;
176 yaml::BinaryRef Payload;
179 struct NameSection : CustomSection {
180 NameSection() : CustomSection("name") {}
182 static bool classof(const Section *S) {
183 auto C = dyn_cast<CustomSection>(S);
184 return C && C->Name == "name";
187 std::vector<NameEntry> FunctionNames;
190 struct LinkingSection : CustomSection {
191 LinkingSection() : CustomSection("linking") {}
193 static bool classof(const Section *S) {
194 auto C = dyn_cast<CustomSection>(S);
195 return C && C->Name == "linking";
199 std::vector<SymbolInfo> SymbolTable;
200 std::vector<SegmentInfo> SegmentInfos;
201 std::vector<InitFunction> InitFunctions;
202 std::vector<Comdat> Comdats;
205 struct TypeSection : Section {
206 TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
208 static bool classof(const Section *S) {
209 return S->Type == wasm::WASM_SEC_TYPE;
212 std::vector<Signature> Signatures;
215 struct ImportSection : Section {
216 ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
218 static bool classof(const Section *S) {
219 return S->Type == wasm::WASM_SEC_IMPORT;
222 std::vector<Import> Imports;
225 struct FunctionSection : Section {
226 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
228 static bool classof(const Section *S) {
229 return S->Type == wasm::WASM_SEC_FUNCTION;
232 std::vector<uint32_t> FunctionTypes;
235 struct TableSection : Section {
236 TableSection() : Section(wasm::WASM_SEC_TABLE) {}
238 static bool classof(const Section *S) {
239 return S->Type == wasm::WASM_SEC_TABLE;
242 std::vector<Table> Tables;
245 struct MemorySection : Section {
246 MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
248 static bool classof(const Section *S) {
249 return S->Type == wasm::WASM_SEC_MEMORY;
252 std::vector<Limits> Memories;
255 struct GlobalSection : Section {
256 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
258 static bool classof(const Section *S) {
259 return S->Type == wasm::WASM_SEC_GLOBAL;
262 std::vector<Global> Globals;
265 struct ExportSection : Section {
266 ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
268 static bool classof(const Section *S) {
269 return S->Type == wasm::WASM_SEC_EXPORT;
272 std::vector<Export> Exports;
275 struct StartSection : Section {
276 StartSection() : Section(wasm::WASM_SEC_START) {}
278 static bool classof(const Section *S) {
279 return S->Type == wasm::WASM_SEC_START;
282 uint32_t StartFunction;
285 struct ElemSection : Section {
286 ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
288 static bool classof(const Section *S) {
289 return S->Type == wasm::WASM_SEC_ELEM;
292 std::vector<ElemSegment> Segments;
295 struct CodeSection : Section {
296 CodeSection() : Section(wasm::WASM_SEC_CODE) {}
298 static bool classof(const Section *S) {
299 return S->Type == wasm::WASM_SEC_CODE;
302 std::vector<Function> Functions;
305 struct DataSection : Section {
306 DataSection() : Section(wasm::WASM_SEC_DATA) {}
308 static bool classof(const Section *S) {
309 return S->Type == wasm::WASM_SEC_DATA;
312 std::vector<DataSegment> Segments;
317 std::vector<std::unique_ptr<Section>> Sections;
320 } // end namespace WasmYAML
321 } // end namespace llvm
323 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
324 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
325 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
326 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
327 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
328 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
329 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
330 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
331 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
332 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
333 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
334 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
335 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
336 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
337 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo)
338 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
339 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction)
340 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry)
341 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat)
346 template <> struct MappingTraits<WasmYAML::FileHeader> {
347 static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
350 template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
351 static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
354 template <> struct MappingTraits<WasmYAML::Object> {
355 static void mapping(IO &IO, WasmYAML::Object &Object);
358 template <> struct MappingTraits<WasmYAML::Import> {
359 static void mapping(IO &IO, WasmYAML::Import &Import);
362 template <> struct MappingTraits<WasmYAML::Export> {
363 static void mapping(IO &IO, WasmYAML::Export &Export);
366 template <> struct MappingTraits<WasmYAML::Global> {
367 static void mapping(IO &IO, WasmYAML::Global &Global);
370 template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
371 static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
374 template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
375 static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
378 template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> {
379 static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind);
382 template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
383 static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
386 template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
387 static void enumeration(IO &IO, WasmYAML::SectionType &Type);
390 template <> struct MappingTraits<WasmYAML::Signature> {
391 static void mapping(IO &IO, WasmYAML::Signature &Signature);
394 template <> struct MappingTraits<WasmYAML::Table> {
395 static void mapping(IO &IO, WasmYAML::Table &Table);
398 template <> struct MappingTraits<WasmYAML::Limits> {
399 static void mapping(IO &IO, WasmYAML::Limits &Limits);
402 template <> struct MappingTraits<WasmYAML::Function> {
403 static void mapping(IO &IO, WasmYAML::Function &Function);
406 template <> struct MappingTraits<WasmYAML::Relocation> {
407 static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
410 template <> struct MappingTraits<WasmYAML::NameEntry> {
411 static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
414 template <> struct MappingTraits<WasmYAML::SegmentInfo> {
415 static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
418 template <> struct MappingTraits<WasmYAML::LocalDecl> {
419 static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
422 template <> struct MappingTraits<wasm::WasmInitExpr> {
423 static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
426 template <> struct MappingTraits<WasmYAML::DataSegment> {
427 static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
430 template <> struct MappingTraits<WasmYAML::ElemSegment> {
431 static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
434 template <> struct MappingTraits<WasmYAML::SymbolInfo> {
435 static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
438 template <> struct MappingTraits<WasmYAML::InitFunction> {
439 static void mapping(IO &IO, WasmYAML::InitFunction &Init);
442 template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> {
443 static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind);
446 template <> struct MappingTraits<WasmYAML::ComdatEntry> {
447 static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry);
450 template <> struct MappingTraits<WasmYAML::Comdat> {
451 static void mapping(IO &IO, WasmYAML::Comdat &Comdat);
454 template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
455 static void enumeration(IO &IO, WasmYAML::ValueType &Type);
458 template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
459 static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
462 template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
463 static void enumeration(IO &IO, WasmYAML::TableType &Type);
466 template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
467 static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
470 template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
471 static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
474 } // end namespace yaml
475 } // end namespace llvm
477 #endif // LLVM_OBJECTYAML_WASMYAML_H