Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/include/ast/component/component.h
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2025 Second State INC
3
4
//===-- wasmedge/ast/component/component.h - Component class definition ---===//
5
//
6
// Part of the WasmEdge Project.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// This file contains the declaration of the Component node class, which is the
12
/// component module node in AST.
13
///
14
//===----------------------------------------------------------------------===//
15
#pragma once
16
17
#include "ast/component/section.h"
18
#include "common/span.h"
19
20
#include <variant>
21
#include <vector>
22
23
namespace WasmEdge {
24
namespace AST {
25
namespace Component {
26
27
// component ::= <preamble> s*:<section>*            => (component flatten(s*))
28
// preamble  ::= <magic> <version> <layer>
29
// magic     ::= 0x00 0x61 0x73 0x6D
30
// version   ::= 0x0d 0x00
31
// layer     ::= 0x01 0x00
32
// section   ::=    section_0(<core:custom>)         => ϵ
33
//             | m: section_1(<core:module>)         => [core-prefix(m)]
34
//             | i*:section_2(vec(<core:instance>))  => core-prefix(i)*
35
//             | t*:section_3(vec(<core:type>))      => core-prefix(t)*
36
//             | c: section_4(<component>)           => [c]
37
//             | i*:section_5(vec(<instance>))       => i*
38
//             | a*:section_6(vec(<alias>))          => a*
39
//             | t*:section_7(vec(<type>))           => t*
40
//             | c*:section_8(vec(<canon>))          => c*
41
//             | s: section_9(<start>)               => [s]
42
//             | i*:section_10(vec(<import>))        => i*
43
//             | e*:section_11(vec(<export>))        => e*
44
//             | v*:section_12(vec(<value>))         => v* 🪙
45
46
/// AST Component::Component node.
47
class Component {
48
  // TODO: COMPONENT - ValueSection
49
  using Section =
50
      std::variant<CustomSection, CoreModuleSection, CoreInstanceSection,
51
                   CoreTypeSection, ComponentSection, InstanceSection,
52
                   AliasSection, TypeSection, CanonSection, StartSection,
53
                   ImportSection, ExportSection>;
54
55
public:
56
  /// Getter of magic vector.
57
0
  const std::vector<Byte> &getMagic() const noexcept { return Magic; }
58
0
  std::vector<Byte> &getMagic() noexcept { return Magic; }
59
60
  /// Getter of version vector.
61
0
  const std::vector<Byte> &getVersion() const noexcept { return Version; }
62
0
  std::vector<Byte> &getVersion() noexcept { return Version; }
63
64
  /// Getter of layer vector.
65
0
  const std::vector<Byte> &getLayer() const noexcept { return Layer; }
66
0
  std::vector<Byte> &getLayer() noexcept { return Layer; }
67
68
0
  std::vector<Section> &getSections() noexcept { return Secs; }
69
0
  Span<const Section> getSections() const noexcept { return Secs; }
70
71
private:
72
  /// \name Data of Component node.
73
  /// @{
74
  std::vector<Byte> Magic;
75
  std::vector<Byte> Version;
76
  std::vector<Byte> Layer;
77
  std::vector<Section> Secs;
78
  /// @}
79
};
80
81
} // namespace Component
82
} // namespace AST
83
} // namespace WasmEdge