1 //===- WasmYAML.h - Wasm YAMLIO implementation ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file declares classes for handling the YAML representation
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_OBJECTYAML_WASMYAML_H
16 #define LLVM_OBJECTYAML_WASMYAML_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/BinaryFormat/Wasm.h"
20 #include "llvm/ObjectYAML/YAML.h"
21 #include "llvm/Support/Casting.h"
29 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionType
)
30 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ValueType
)
31 LLVM_YAML_STRONG_TYPEDEF(uint32_t, TableType
)
32 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SignatureForm
)
33 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind
)
34 LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode
)
35 LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType
)
36 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolFlags
)
37 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolKind
)
38 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SegmentFlags
)
39 LLVM_YAML_STRONG_TYPEDEF(uint32_t, LimitFlags
)
40 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ComdatKind
)
41 LLVM_YAML_STRONG_TYPEDEF(uint32_t, FeaturePolicyPrefix
)
66 wasm::WasmInitExpr Offset
;
67 std::vector
<uint32_t> Functions
;
74 wasm::WasmInitExpr InitExpr
;
103 std::vector
<LocalDecl
> Locals
;
104 yaml::BinaryRef Body
;
115 uint32_t SectionOffset
;
117 uint32_t MemoryIndex
;
118 wasm::WasmInitExpr Offset
;
119 yaml::BinaryRef Content
;
127 struct ProducerEntry
{
132 struct FeatureEntry
{
133 FeaturePolicyPrefix Prefix
;
146 SignatureForm Form
= wasm::WASM_TYPE_FUNC
;
147 std::vector
<ValueType
> ParamTypes
;
148 std::vector
<ValueType
> ReturnTypes
;
157 uint32_t ElementIndex
;
158 wasm::WasmDataReference DataRef
;
162 struct InitFunction
{
174 std::vector
<ComdatEntry
> Entries
;
178 explicit Section(SectionType SecType
) : Type(SecType
) {}
182 std::vector
<Relocation
> Relocations
;
185 struct CustomSection
: Section
{
186 explicit CustomSection(StringRef Name
)
187 : Section(wasm::WASM_SEC_CUSTOM
), Name(Name
) {}
189 static bool classof(const Section
*S
) {
190 return S
->Type
== wasm::WASM_SEC_CUSTOM
;
194 yaml::BinaryRef Payload
;
197 struct DylinkSection
: CustomSection
{
198 DylinkSection() : CustomSection("dylink") {}
200 static bool classof(const Section
*S
) {
201 auto C
= dyn_cast
<CustomSection
>(S
);
202 return C
&& C
->Name
== "dylink";
206 uint32_t MemoryAlignment
;
208 uint32_t TableAlignment
;
209 std::vector
<StringRef
> Needed
;
212 struct NameSection
: CustomSection
{
213 NameSection() : CustomSection("name") {}
215 static bool classof(const Section
*S
) {
216 auto C
= dyn_cast
<CustomSection
>(S
);
217 return C
&& C
->Name
== "name";
220 std::vector
<NameEntry
> FunctionNames
;
223 struct LinkingSection
: CustomSection
{
224 LinkingSection() : CustomSection("linking") {}
226 static bool classof(const Section
*S
) {
227 auto C
= dyn_cast
<CustomSection
>(S
);
228 return C
&& C
->Name
== "linking";
232 std::vector
<SymbolInfo
> SymbolTable
;
233 std::vector
<SegmentInfo
> SegmentInfos
;
234 std::vector
<InitFunction
> InitFunctions
;
235 std::vector
<Comdat
> Comdats
;
238 struct ProducersSection
: CustomSection
{
239 ProducersSection() : CustomSection("producers") {}
241 static bool classof(const Section
*S
) {
242 auto C
= dyn_cast
<CustomSection
>(S
);
243 return C
&& C
->Name
== "producers";
246 std::vector
<ProducerEntry
> Languages
;
247 std::vector
<ProducerEntry
> Tools
;
248 std::vector
<ProducerEntry
> SDKs
;
251 struct TargetFeaturesSection
: CustomSection
{
252 TargetFeaturesSection() : CustomSection("target_features") {}
254 static bool classof(const Section
*S
) {
255 auto C
= dyn_cast
<CustomSection
>(S
);
256 return C
&& C
->Name
== "target_features";
259 std::vector
<FeatureEntry
> Features
;
262 struct TypeSection
: Section
{
263 TypeSection() : Section(wasm::WASM_SEC_TYPE
) {}
265 static bool classof(const Section
*S
) {
266 return S
->Type
== wasm::WASM_SEC_TYPE
;
269 std::vector
<Signature
> Signatures
;
272 struct ImportSection
: Section
{
273 ImportSection() : Section(wasm::WASM_SEC_IMPORT
) {}
275 static bool classof(const Section
*S
) {
276 return S
->Type
== wasm::WASM_SEC_IMPORT
;
279 std::vector
<Import
> Imports
;
282 struct FunctionSection
: Section
{
283 FunctionSection() : Section(wasm::WASM_SEC_FUNCTION
) {}
285 static bool classof(const Section
*S
) {
286 return S
->Type
== wasm::WASM_SEC_FUNCTION
;
289 std::vector
<uint32_t> FunctionTypes
;
292 struct TableSection
: Section
{
293 TableSection() : Section(wasm::WASM_SEC_TABLE
) {}
295 static bool classof(const Section
*S
) {
296 return S
->Type
== wasm::WASM_SEC_TABLE
;
299 std::vector
<Table
> Tables
;
302 struct MemorySection
: Section
{
303 MemorySection() : Section(wasm::WASM_SEC_MEMORY
) {}
305 static bool classof(const Section
*S
) {
306 return S
->Type
== wasm::WASM_SEC_MEMORY
;
309 std::vector
<Limits
> Memories
;
312 struct GlobalSection
: Section
{
313 GlobalSection() : Section(wasm::WASM_SEC_GLOBAL
) {}
315 static bool classof(const Section
*S
) {
316 return S
->Type
== wasm::WASM_SEC_GLOBAL
;
319 std::vector
<Global
> Globals
;
322 struct EventSection
: Section
{
323 EventSection() : Section(wasm::WASM_SEC_EVENT
) {}
325 static bool classof(const Section
*S
) {
326 return S
->Type
== wasm::WASM_SEC_EVENT
;
329 std::vector
<Event
> Events
;
332 struct ExportSection
: Section
{
333 ExportSection() : Section(wasm::WASM_SEC_EXPORT
) {}
335 static bool classof(const Section
*S
) {
336 return S
->Type
== wasm::WASM_SEC_EXPORT
;
339 std::vector
<Export
> Exports
;
342 struct StartSection
: Section
{
343 StartSection() : Section(wasm::WASM_SEC_START
) {}
345 static bool classof(const Section
*S
) {
346 return S
->Type
== wasm::WASM_SEC_START
;
349 uint32_t StartFunction
;
352 struct ElemSection
: Section
{
353 ElemSection() : Section(wasm::WASM_SEC_ELEM
) {}
355 static bool classof(const Section
*S
) {
356 return S
->Type
== wasm::WASM_SEC_ELEM
;
359 std::vector
<ElemSegment
> Segments
;
362 struct CodeSection
: Section
{
363 CodeSection() : Section(wasm::WASM_SEC_CODE
) {}
365 static bool classof(const Section
*S
) {
366 return S
->Type
== wasm::WASM_SEC_CODE
;
369 std::vector
<Function
> Functions
;
372 struct DataSection
: Section
{
373 DataSection() : Section(wasm::WASM_SEC_DATA
) {}
375 static bool classof(const Section
*S
) {
376 return S
->Type
== wasm::WASM_SEC_DATA
;
379 std::vector
<DataSegment
> Segments
;
382 struct DataCountSection
: Section
{
383 DataCountSection() : Section(wasm::WASM_SEC_DATACOUNT
) {}
385 static bool classof(const Section
*S
) {
386 return S
->Type
== wasm::WASM_SEC_DATACOUNT
;
394 std::vector
<std::unique_ptr
<Section
>> Sections
;
397 } // end namespace WasmYAML
398 } // end namespace llvm
400 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr
<llvm::WasmYAML::Section
>)
401 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature
)
402 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType
)
403 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table
)
404 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import
)
405 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export
)
406 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment
)
407 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits
)
408 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment
)
409 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global
)
410 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function
)
411 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl
)
412 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation
)
413 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry
)
414 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ProducerEntry
)
415 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::FeatureEntry
)
416 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo
)
417 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo
)
418 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction
)
419 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry
)
420 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat
)
421 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Event
)
426 template <> struct MappingTraits
<WasmYAML::FileHeader
> {
427 static void mapping(IO
&IO
, WasmYAML::FileHeader
&FileHdr
);
430 template <> struct MappingTraits
<std::unique_ptr
<WasmYAML::Section
>> {
431 static void mapping(IO
&IO
, std::unique_ptr
<WasmYAML::Section
> &Section
);
434 template <> struct MappingTraits
<WasmYAML::Object
> {
435 static void mapping(IO
&IO
, WasmYAML::Object
&Object
);
438 template <> struct MappingTraits
<WasmYAML::Import
> {
439 static void mapping(IO
&IO
, WasmYAML::Import
&Import
);
442 template <> struct MappingTraits
<WasmYAML::Export
> {
443 static void mapping(IO
&IO
, WasmYAML::Export
&Export
);
446 template <> struct MappingTraits
<WasmYAML::Global
> {
447 static void mapping(IO
&IO
, WasmYAML::Global
&Global
);
450 template <> struct ScalarBitSetTraits
<WasmYAML::LimitFlags
> {
451 static void bitset(IO
&IO
, WasmYAML::LimitFlags
&Value
);
454 template <> struct ScalarBitSetTraits
<WasmYAML::SymbolFlags
> {
455 static void bitset(IO
&IO
, WasmYAML::SymbolFlags
&Value
);
458 template <> struct ScalarEnumerationTraits
<WasmYAML::SymbolKind
> {
459 static void enumeration(IO
&IO
, WasmYAML::SymbolKind
&Kind
);
462 template <> struct ScalarBitSetTraits
<WasmYAML::SegmentFlags
> {
463 static void bitset(IO
&IO
, WasmYAML::SegmentFlags
&Value
);
466 template <> struct ScalarEnumerationTraits
<WasmYAML::SectionType
> {
467 static void enumeration(IO
&IO
, WasmYAML::SectionType
&Type
);
470 template <> struct MappingTraits
<WasmYAML::Signature
> {
471 static void mapping(IO
&IO
, WasmYAML::Signature
&Signature
);
474 template <> struct MappingTraits
<WasmYAML::Table
> {
475 static void mapping(IO
&IO
, WasmYAML::Table
&Table
);
478 template <> struct MappingTraits
<WasmYAML::Limits
> {
479 static void mapping(IO
&IO
, WasmYAML::Limits
&Limits
);
482 template <> struct MappingTraits
<WasmYAML::Function
> {
483 static void mapping(IO
&IO
, WasmYAML::Function
&Function
);
486 template <> struct MappingTraits
<WasmYAML::Relocation
> {
487 static void mapping(IO
&IO
, WasmYAML::Relocation
&Relocation
);
490 template <> struct MappingTraits
<WasmYAML::NameEntry
> {
491 static void mapping(IO
&IO
, WasmYAML::NameEntry
&NameEntry
);
494 template <> struct MappingTraits
<WasmYAML::ProducerEntry
> {
495 static void mapping(IO
&IO
, WasmYAML::ProducerEntry
&ProducerEntry
);
498 template <> struct ScalarEnumerationTraits
<WasmYAML::FeaturePolicyPrefix
> {
499 static void enumeration(IO
&IO
, WasmYAML::FeaturePolicyPrefix
&Prefix
);
502 template <> struct MappingTraits
<WasmYAML::FeatureEntry
> {
503 static void mapping(IO
&IO
, WasmYAML::FeatureEntry
&FeatureEntry
);
506 template <> struct MappingTraits
<WasmYAML::SegmentInfo
> {
507 static void mapping(IO
&IO
, WasmYAML::SegmentInfo
&SegmentInfo
);
510 template <> struct MappingTraits
<WasmYAML::LocalDecl
> {
511 static void mapping(IO
&IO
, WasmYAML::LocalDecl
&LocalDecl
);
514 template <> struct MappingTraits
<wasm::WasmInitExpr
> {
515 static void mapping(IO
&IO
, wasm::WasmInitExpr
&Expr
);
518 template <> struct MappingTraits
<WasmYAML::DataSegment
> {
519 static void mapping(IO
&IO
, WasmYAML::DataSegment
&Segment
);
522 template <> struct MappingTraits
<WasmYAML::ElemSegment
> {
523 static void mapping(IO
&IO
, WasmYAML::ElemSegment
&Segment
);
526 template <> struct MappingTraits
<WasmYAML::SymbolInfo
> {
527 static void mapping(IO
&IO
, WasmYAML::SymbolInfo
&Info
);
530 template <> struct MappingTraits
<WasmYAML::InitFunction
> {
531 static void mapping(IO
&IO
, WasmYAML::InitFunction
&Init
);
534 template <> struct ScalarEnumerationTraits
<WasmYAML::ComdatKind
> {
535 static void enumeration(IO
&IO
, WasmYAML::ComdatKind
&Kind
);
538 template <> struct MappingTraits
<WasmYAML::ComdatEntry
> {
539 static void mapping(IO
&IO
, WasmYAML::ComdatEntry
&ComdatEntry
);
542 template <> struct MappingTraits
<WasmYAML::Comdat
> {
543 static void mapping(IO
&IO
, WasmYAML::Comdat
&Comdat
);
546 template <> struct ScalarEnumerationTraits
<WasmYAML::ValueType
> {
547 static void enumeration(IO
&IO
, WasmYAML::ValueType
&Type
);
550 template <> struct ScalarEnumerationTraits
<WasmYAML::ExportKind
> {
551 static void enumeration(IO
&IO
, WasmYAML::ExportKind
&Kind
);
554 template <> struct ScalarEnumerationTraits
<WasmYAML::TableType
> {
555 static void enumeration(IO
&IO
, WasmYAML::TableType
&Type
);
558 template <> struct ScalarEnumerationTraits
<WasmYAML::Opcode
> {
559 static void enumeration(IO
&IO
, WasmYAML::Opcode
&Opcode
);
562 template <> struct ScalarEnumerationTraits
<WasmYAML::RelocType
> {
563 static void enumeration(IO
&IO
, WasmYAML::RelocType
&Kind
);
566 template <> struct MappingTraits
<WasmYAML::Event
> {
567 static void mapping(IO
&IO
, WasmYAML::Event
&Event
);
570 } // end namespace yaml
571 } // end namespace llvm
573 #endif // LLVM_OBJECTYAML_WASMYAML_H