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;
102 wasm::WasmInitExpr Offset;
103 yaml::BinaryRef Content;
113 SignatureForm Form = wasm::WASM_TYPE_FUNC;
114 std::vector<ValueType> ParamTypes;
115 ValueType ReturnType;
124 explicit Section(SectionType SecType) : Type(SecType) {}
128 std::vector<Relocation> Relocations;
131 struct CustomSection : Section {
132 explicit CustomSection(StringRef Name)
133 : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
135 static bool classof(const Section *S) {
136 return S->Type == wasm::WASM_SEC_CUSTOM;
140 yaml::BinaryRef Payload;
143 struct NameSection : CustomSection {
144 NameSection() : CustomSection("name") {}
146 static bool classof(const Section *S) {
147 auto C = dyn_cast<CustomSection>(S);
148 return C && C->Name == "name";
151 std::vector<NameEntry> FunctionNames;
154 struct LinkingSection : CustomSection {
155 LinkingSection() : CustomSection("linking") {}
157 static bool classof(const Section *S) {
158 auto C = dyn_cast<CustomSection>(S);
159 return C && C->Name == "linking";
162 std::vector<SymbolInfo> SymbolInfos;
164 uint32_t DataAlignment;
167 struct TypeSection : Section {
168 TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
170 static bool classof(const Section *S) {
171 return S->Type == wasm::WASM_SEC_TYPE;
174 std::vector<Signature> Signatures;
177 struct ImportSection : Section {
178 ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
180 static bool classof(const Section *S) {
181 return S->Type == wasm::WASM_SEC_IMPORT;
184 std::vector<Import> Imports;
187 struct FunctionSection : Section {
188 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
190 static bool classof(const Section *S) {
191 return S->Type == wasm::WASM_SEC_FUNCTION;
194 std::vector<uint32_t> FunctionTypes;
197 struct TableSection : Section {
198 TableSection() : Section(wasm::WASM_SEC_TABLE) {}
200 static bool classof(const Section *S) {
201 return S->Type == wasm::WASM_SEC_TABLE;
204 std::vector<Table> Tables;
207 struct MemorySection : Section {
208 MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
210 static bool classof(const Section *S) {
211 return S->Type == wasm::WASM_SEC_MEMORY;
214 std::vector<Limits> Memories;
217 struct GlobalSection : Section {
218 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
220 static bool classof(const Section *S) {
221 return S->Type == wasm::WASM_SEC_GLOBAL;
224 std::vector<Global> Globals;
227 struct ExportSection : Section {
228 ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
230 static bool classof(const Section *S) {
231 return S->Type == wasm::WASM_SEC_EXPORT;
234 std::vector<Export> Exports;
237 struct StartSection : Section {
238 StartSection() : Section(wasm::WASM_SEC_START) {}
240 static bool classof(const Section *S) {
241 return S->Type == wasm::WASM_SEC_START;
244 uint32_t StartFunction;
247 struct ElemSection : Section {
248 ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
250 static bool classof(const Section *S) {
251 return S->Type == wasm::WASM_SEC_ELEM;
254 std::vector<ElemSegment> Segments;
257 struct CodeSection : Section {
258 CodeSection() : Section(wasm::WASM_SEC_CODE) {}
260 static bool classof(const Section *S) {
261 return S->Type == wasm::WASM_SEC_CODE;
264 std::vector<Function> Functions;
267 struct DataSection : Section {
268 DataSection() : Section(wasm::WASM_SEC_DATA) {}
270 static bool classof(const Section *S) {
271 return S->Type == wasm::WASM_SEC_DATA;
274 std::vector<DataSegment> Segments;
279 std::vector<std::unique_ptr<Section>> Sections;
282 } // end namespace WasmYAML
283 } // end namespace llvm
285 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
286 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
287 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
288 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
289 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
290 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
291 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
292 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
293 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
294 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
295 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
296 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
297 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
298 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
299 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
304 template <> struct MappingTraits<WasmYAML::FileHeader> {
305 static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
308 template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
309 static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
312 template <> struct MappingTraits<WasmYAML::Object> {
313 static void mapping(IO &IO, WasmYAML::Object &Object);
316 template <> struct MappingTraits<WasmYAML::Import> {
317 static void mapping(IO &IO, WasmYAML::Import &Import);
320 template <> struct MappingTraits<WasmYAML::Export> {
321 static void mapping(IO &IO, WasmYAML::Export &Export);
324 template <> struct MappingTraits<WasmYAML::Global> {
325 static void mapping(IO &IO, WasmYAML::Global &Global);
328 template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
329 static void enumeration(IO &IO, WasmYAML::SectionType &Type);
332 template <> struct MappingTraits<WasmYAML::Signature> {
333 static void mapping(IO &IO, WasmYAML::Signature &Signature);
336 template <> struct MappingTraits<WasmYAML::Table> {
337 static void mapping(IO &IO, WasmYAML::Table &Table);
340 template <> struct MappingTraits<WasmYAML::Limits> {
341 static void mapping(IO &IO, WasmYAML::Limits &Limits);
344 template <> struct MappingTraits<WasmYAML::Function> {
345 static void mapping(IO &IO, WasmYAML::Function &Function);
348 template <> struct MappingTraits<WasmYAML::Relocation> {
349 static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
352 template <> struct MappingTraits<WasmYAML::NameEntry> {
353 static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
356 template <> struct MappingTraits<WasmYAML::LocalDecl> {
357 static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
360 template <> struct MappingTraits<wasm::WasmInitExpr> {
361 static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
364 template <> struct MappingTraits<WasmYAML::DataSegment> {
365 static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
368 template <> struct MappingTraits<WasmYAML::ElemSegment> {
369 static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
372 template <> struct MappingTraits<WasmYAML::SymbolInfo> {
373 static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
376 template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
377 static void enumeration(IO &IO, WasmYAML::ValueType &Type);
380 template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
381 static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
384 template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
385 static void enumeration(IO &IO, WasmYAML::TableType &Type);
388 template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
389 static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
392 template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
393 static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
396 } // end namespace yaml
397 } // end namespace llvm
399 #endif // LLVM_OBJECTYAML_WASMYAML_H