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
)
37 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolFlags
)
38 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SegmentFlags
)
39 LLVM_YAML_STRONG_TYPEDEF(uint32_t, LimitFlags
)
64 wasm::WasmInitExpr Offset
;
65 std::vector
<uint32_t> Functions
;
71 wasm::WasmInitExpr InitExpr
;
92 std::vector
<LocalDecl
> Locals
;
104 uint32_t MemoryIndex
;
105 uint32_t SectionOffset
;
106 wasm::WasmInitExpr Offset
;
107 yaml::BinaryRef Content
;
124 SignatureForm Form
= wasm::WASM_TYPE_FUNC
;
125 std::vector
<ValueType
> ParamTypes
;
126 ValueType ReturnType
;
134 struct InitFunction
{
136 uint32_t FunctionIndex
;
140 explicit Section(SectionType SecType
) : Type(SecType
) {}
144 std::vector
<Relocation
> Relocations
;
147 struct CustomSection
: Section
{
148 explicit CustomSection(StringRef Name
)
149 : Section(wasm::WASM_SEC_CUSTOM
), Name(Name
) {}
151 static bool classof(const Section
*S
) {
152 return S
->Type
== wasm::WASM_SEC_CUSTOM
;
156 yaml::BinaryRef Payload
;
159 struct NameSection
: CustomSection
{
160 NameSection() : CustomSection("name") {}
162 static bool classof(const Section
*S
) {
163 auto C
= dyn_cast
<CustomSection
>(S
);
164 return C
&& C
->Name
== "name";
167 std::vector
<NameEntry
> FunctionNames
;
170 struct LinkingSection
: CustomSection
{
171 LinkingSection() : CustomSection("linking") {}
173 static bool classof(const Section
*S
) {
174 auto C
= dyn_cast
<CustomSection
>(S
);
175 return C
&& C
->Name
== "linking";
179 std::vector
<SymbolInfo
> SymbolInfos
;
180 std::vector
<SegmentInfo
> SegmentInfos
;
181 std::vector
<InitFunction
> InitFunctions
;
184 struct TypeSection
: Section
{
185 TypeSection() : Section(wasm::WASM_SEC_TYPE
) {}
187 static bool classof(const Section
*S
) {
188 return S
->Type
== wasm::WASM_SEC_TYPE
;
191 std::vector
<Signature
> Signatures
;
194 struct ImportSection
: Section
{
195 ImportSection() : Section(wasm::WASM_SEC_IMPORT
) {}
197 static bool classof(const Section
*S
) {
198 return S
->Type
== wasm::WASM_SEC_IMPORT
;
201 std::vector
<Import
> Imports
;
204 struct FunctionSection
: Section
{
205 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION
) {}
207 static bool classof(const Section
*S
) {
208 return S
->Type
== wasm::WASM_SEC_FUNCTION
;
211 std::vector
<uint32_t> FunctionTypes
;
214 struct TableSection
: Section
{
215 TableSection() : Section(wasm::WASM_SEC_TABLE
) {}
217 static bool classof(const Section
*S
) {
218 return S
->Type
== wasm::WASM_SEC_TABLE
;
221 std::vector
<Table
> Tables
;
224 struct MemorySection
: Section
{
225 MemorySection() : Section(wasm::WASM_SEC_MEMORY
) {}
227 static bool classof(const Section
*S
) {
228 return S
->Type
== wasm::WASM_SEC_MEMORY
;
231 std::vector
<Limits
> Memories
;
234 struct GlobalSection
: Section
{
235 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL
) {}
237 static bool classof(const Section
*S
) {
238 return S
->Type
== wasm::WASM_SEC_GLOBAL
;
241 std::vector
<Global
> Globals
;
244 struct ExportSection
: Section
{
245 ExportSection() : Section(wasm::WASM_SEC_EXPORT
) {}
247 static bool classof(const Section
*S
) {
248 return S
->Type
== wasm::WASM_SEC_EXPORT
;
251 std::vector
<Export
> Exports
;
254 struct StartSection
: Section
{
255 StartSection() : Section(wasm::WASM_SEC_START
) {}
257 static bool classof(const Section
*S
) {
258 return S
->Type
== wasm::WASM_SEC_START
;
261 uint32_t StartFunction
;
264 struct ElemSection
: Section
{
265 ElemSection() : Section(wasm::WASM_SEC_ELEM
) {}
267 static bool classof(const Section
*S
) {
268 return S
->Type
== wasm::WASM_SEC_ELEM
;
271 std::vector
<ElemSegment
> Segments
;
274 struct CodeSection
: Section
{
275 CodeSection() : Section(wasm::WASM_SEC_CODE
) {}
277 static bool classof(const Section
*S
) {
278 return S
->Type
== wasm::WASM_SEC_CODE
;
281 std::vector
<Function
> Functions
;
284 struct DataSection
: Section
{
285 DataSection() : Section(wasm::WASM_SEC_DATA
) {}
287 static bool classof(const Section
*S
) {
288 return S
->Type
== wasm::WASM_SEC_DATA
;
291 std::vector
<DataSegment
> Segments
;
296 std::vector
<std::unique_ptr
<Section
>> Sections
;
299 } // end namespace WasmYAML
300 } // end namespace llvm
302 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr
<llvm::WasmYAML::Section
>)
303 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature
)
304 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType
)
305 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table
)
306 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import
)
307 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export
)
308 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment
)
309 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits
)
310 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment
)
311 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global
)
312 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function
)
313 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl
)
314 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation
)
315 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry
)
316 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo
)
317 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo
)
318 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction
)
323 template <> struct MappingTraits
<WasmYAML::FileHeader
> {
324 static void mapping(IO
&IO
, WasmYAML::FileHeader
&FileHdr
);
327 template <> struct MappingTraits
<std::unique_ptr
<WasmYAML::Section
>> {
328 static void mapping(IO
&IO
, std::unique_ptr
<WasmYAML::Section
> &Section
);
331 template <> struct MappingTraits
<WasmYAML::Object
> {
332 static void mapping(IO
&IO
, WasmYAML::Object
&Object
);
335 template <> struct MappingTraits
<WasmYAML::Import
> {
336 static void mapping(IO
&IO
, WasmYAML::Import
&Import
);
339 template <> struct MappingTraits
<WasmYAML::Export
> {
340 static void mapping(IO
&IO
, WasmYAML::Export
&Export
);
343 template <> struct MappingTraits
<WasmYAML::Global
> {
344 static void mapping(IO
&IO
, WasmYAML::Global
&Global
);
347 template <> struct ScalarBitSetTraits
<WasmYAML::LimitFlags
> {
348 static void bitset(IO
&IO
, WasmYAML::LimitFlags
&Value
);
351 template <> struct ScalarBitSetTraits
<WasmYAML::SymbolFlags
> {
352 static void bitset(IO
&IO
, WasmYAML::SymbolFlags
&Value
);
355 template <> struct ScalarBitSetTraits
<WasmYAML::SegmentFlags
> {
356 static void bitset(IO
&IO
, WasmYAML::SegmentFlags
&Value
);
359 template <> struct ScalarEnumerationTraits
<WasmYAML::SectionType
> {
360 static void enumeration(IO
&IO
, WasmYAML::SectionType
&Type
);
363 template <> struct MappingTraits
<WasmYAML::Signature
> {
364 static void mapping(IO
&IO
, WasmYAML::Signature
&Signature
);
367 template <> struct MappingTraits
<WasmYAML::Table
> {
368 static void mapping(IO
&IO
, WasmYAML::Table
&Table
);
371 template <> struct MappingTraits
<WasmYAML::Limits
> {
372 static void mapping(IO
&IO
, WasmYAML::Limits
&Limits
);
375 template <> struct MappingTraits
<WasmYAML::Function
> {
376 static void mapping(IO
&IO
, WasmYAML::Function
&Function
);
379 template <> struct MappingTraits
<WasmYAML::Relocation
> {
380 static void mapping(IO
&IO
, WasmYAML::Relocation
&Relocation
);
383 template <> struct MappingTraits
<WasmYAML::NameEntry
> {
384 static void mapping(IO
&IO
, WasmYAML::NameEntry
&NameEntry
);
387 template <> struct MappingTraits
<WasmYAML::SegmentInfo
> {
388 static void mapping(IO
&IO
, WasmYAML::SegmentInfo
&SegmentInfo
);
391 template <> struct MappingTraits
<WasmYAML::LocalDecl
> {
392 static void mapping(IO
&IO
, WasmYAML::LocalDecl
&LocalDecl
);
395 template <> struct MappingTraits
<wasm::WasmInitExpr
> {
396 static void mapping(IO
&IO
, wasm::WasmInitExpr
&Expr
);
399 template <> struct MappingTraits
<WasmYAML::DataSegment
> {
400 static void mapping(IO
&IO
, WasmYAML::DataSegment
&Segment
);
403 template <> struct MappingTraits
<WasmYAML::ElemSegment
> {
404 static void mapping(IO
&IO
, WasmYAML::ElemSegment
&Segment
);
407 template <> struct MappingTraits
<WasmYAML::SymbolInfo
> {
408 static void mapping(IO
&IO
, WasmYAML::SymbolInfo
&Info
);
411 template <> struct MappingTraits
<WasmYAML::InitFunction
> {
412 static void mapping(IO
&IO
, WasmYAML::InitFunction
&Init
);
415 template <> struct ScalarEnumerationTraits
<WasmYAML::ValueType
> {
416 static void enumeration(IO
&IO
, WasmYAML::ValueType
&Type
);
419 template <> struct ScalarEnumerationTraits
<WasmYAML::ExportKind
> {
420 static void enumeration(IO
&IO
, WasmYAML::ExportKind
&Kind
);
423 template <> struct ScalarEnumerationTraits
<WasmYAML::TableType
> {
424 static void enumeration(IO
&IO
, WasmYAML::TableType
&Type
);
427 template <> struct ScalarEnumerationTraits
<WasmYAML::Opcode
> {
428 static void enumeration(IO
&IO
, WasmYAML::Opcode
&Opcode
);
431 template <> struct ScalarEnumerationTraits
<WasmYAML::RelocType
> {
432 static void enumeration(IO
&IO
, WasmYAML::RelocType
&Kind
);
435 } // end namespace yaml
436 } // end namespace llvm
438 #endif // LLVM_OBJECTYAML_WASMYAML_H