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/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(int32_t, ValueType)
32 LLVM_YAML_STRONG_TYPEDEF(int32_t, TableType)
33 LLVM_YAML_STRONG_TYPEDEF(int32_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)
61 wasm::WasmInitExpr Offset;
62 std::vector<uint32_t> Functions;
68 wasm::WasmInitExpr InitExpr;
89 std::vector<LocalDecl> Locals;
101 uint32_t MemoryIndex;
102 uint32_t SectionOffset;
103 wasm::WasmInitExpr Offset;
104 yaml::BinaryRef Content;
114 SignatureForm Form = wasm::WASM_TYPE_FUNC;
115 std::vector<ValueType> ParamTypes;
116 ValueType ReturnType;
125 explicit Section(SectionType SecType) : Type(SecType) {}
129 std::vector<Relocation> Relocations;
132 struct CustomSection : Section {
133 explicit CustomSection(StringRef Name)
134 : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
136 static bool classof(const Section *S) {
137 return S->Type == wasm::WASM_SEC_CUSTOM;
141 yaml::BinaryRef Payload;
144 struct NameSection : CustomSection {
145 NameSection() : CustomSection("name") {}
147 static bool classof(const Section *S) {
148 auto C = dyn_cast<CustomSection>(S);
149 return C && C->Name == "name";
152 std::vector<NameEntry> FunctionNames;
155 struct LinkingSection : CustomSection {
156 LinkingSection() : CustomSection("linking") {}
158 static bool classof(const Section *S) {
159 auto C = dyn_cast<CustomSection>(S);
160 return C && C->Name == "linking";
163 std::vector<SymbolInfo> SymbolInfos;
165 uint32_t DataAlignment;
168 struct TypeSection : Section {
169 TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
171 static bool classof(const Section *S) {
172 return S->Type == wasm::WASM_SEC_TYPE;
175 std::vector<Signature> Signatures;
178 struct ImportSection : Section {
179 ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
181 static bool classof(const Section *S) {
182 return S->Type == wasm::WASM_SEC_IMPORT;
185 std::vector<Import> Imports;
188 struct FunctionSection : Section {
189 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
191 static bool classof(const Section *S) {
192 return S->Type == wasm::WASM_SEC_FUNCTION;
195 std::vector<uint32_t> FunctionTypes;
198 struct TableSection : Section {
199 TableSection() : Section(wasm::WASM_SEC_TABLE) {}
201 static bool classof(const Section *S) {
202 return S->Type == wasm::WASM_SEC_TABLE;
205 std::vector<Table> Tables;
208 struct MemorySection : Section {
209 MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
211 static bool classof(const Section *S) {
212 return S->Type == wasm::WASM_SEC_MEMORY;
215 std::vector<Limits> Memories;
218 struct GlobalSection : Section {
219 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
221 static bool classof(const Section *S) {
222 return S->Type == wasm::WASM_SEC_GLOBAL;
225 std::vector<Global> Globals;
228 struct ExportSection : Section {
229 ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
231 static bool classof(const Section *S) {
232 return S->Type == wasm::WASM_SEC_EXPORT;
235 std::vector<Export> Exports;
238 struct StartSection : Section {
239 StartSection() : Section(wasm::WASM_SEC_START) {}
241 static bool classof(const Section *S) {
242 return S->Type == wasm::WASM_SEC_START;
245 uint32_t StartFunction;
248 struct ElemSection : Section {
249 ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
251 static bool classof(const Section *S) {
252 return S->Type == wasm::WASM_SEC_ELEM;
255 std::vector<ElemSegment> Segments;
258 struct CodeSection : Section {
259 CodeSection() : Section(wasm::WASM_SEC_CODE) {}
261 static bool classof(const Section *S) {
262 return S->Type == wasm::WASM_SEC_CODE;
265 std::vector<Function> Functions;
268 struct DataSection : Section {
269 DataSection() : Section(wasm::WASM_SEC_DATA) {}
271 static bool classof(const Section *S) {
272 return S->Type == wasm::WASM_SEC_DATA;
275 std::vector<DataSegment> Segments;
280 std::vector<std::unique_ptr<Section>> Sections;
283 } // end namespace WasmYAML
284 } // end namespace llvm
286 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
287 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
288 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
289 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
290 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
291 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
292 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
293 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
294 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
295 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
296 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
297 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
298 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
299 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
300 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
305 template <> struct MappingTraits<WasmYAML::FileHeader> {
306 static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
309 template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
310 static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
313 template <> struct MappingTraits<WasmYAML::Object> {
314 static void mapping(IO &IO, WasmYAML::Object &Object);
317 template <> struct MappingTraits<WasmYAML::Import> {
318 static void mapping(IO &IO, WasmYAML::Import &Import);
321 template <> struct MappingTraits<WasmYAML::Export> {
322 static void mapping(IO &IO, WasmYAML::Export &Export);
325 template <> struct MappingTraits<WasmYAML::Global> {
326 static void mapping(IO &IO, WasmYAML::Global &Global);
329 template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
330 static void enumeration(IO &IO, WasmYAML::SectionType &Type);
333 template <> struct MappingTraits<WasmYAML::Signature> {
334 static void mapping(IO &IO, WasmYAML::Signature &Signature);
337 template <> struct MappingTraits<WasmYAML::Table> {
338 static void mapping(IO &IO, WasmYAML::Table &Table);
341 template <> struct MappingTraits<WasmYAML::Limits> {
342 static void mapping(IO &IO, WasmYAML::Limits &Limits);
345 template <> struct MappingTraits<WasmYAML::Function> {
346 static void mapping(IO &IO, WasmYAML::Function &Function);
349 template <> struct MappingTraits<WasmYAML::Relocation> {
350 static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
353 template <> struct MappingTraits<WasmYAML::NameEntry> {
354 static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
357 template <> struct MappingTraits<WasmYAML::LocalDecl> {
358 static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
361 template <> struct MappingTraits<wasm::WasmInitExpr> {
362 static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
365 template <> struct MappingTraits<WasmYAML::DataSegment> {
366 static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
369 template <> struct MappingTraits<WasmYAML::ElemSegment> {
370 static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
373 template <> struct MappingTraits<WasmYAML::SymbolInfo> {
374 static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
377 template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
378 static void enumeration(IO &IO, WasmYAML::ValueType &Type);
381 template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
382 static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
385 template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
386 static void enumeration(IO &IO, WasmYAML::TableType &Type);
389 template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
390 static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
393 template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
394 static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
397 } // end namespace yaml
398 } // end namespace llvm
400 #endif // LLVM_OBJECTYAML_WASMYAML_H