/src/WasmEdge/include/validator/validator.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | //===-- wasmedge/validator/validator.h - validator class definition -------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the declaration of the validator class, which controls |
12 | | /// flow of WASM validation. |
13 | | /// |
14 | | //===----------------------------------------------------------------------===// |
15 | | #pragma once |
16 | | |
17 | | #include "ast/module.h" |
18 | | #include "common/configure.h" |
19 | | #include "validator/component_context.h" |
20 | | #include "validator/formchecker.h" |
21 | | |
22 | | #include <cstdint> |
23 | | |
24 | | namespace WasmEdge { |
25 | | namespace Validator { |
26 | | |
27 | | /// Validator flow control class. |
28 | | class Validator { |
29 | | public: |
30 | 3.44k | Validator(const Configure &Conf) noexcept : Conf(Conf) {} |
31 | 3.44k | ~Validator() noexcept = default; |
32 | | |
33 | | /// Validate AST::Module. |
34 | | Expect<void> validate(const AST::Module &Mod); |
35 | | /// Validate AST::Component. |
36 | | Expect<void> validate(const AST::Component::Component &Comp) noexcept; |
37 | | |
38 | | private: |
39 | | /// \name Validate WASM AST nodes |
40 | | /// @{ |
41 | | // Validate AST::Types |
42 | | Expect<void> validate(const AST::SubType &Type); |
43 | | Expect<void> validate(const AST::Limit &Lim); |
44 | | Expect<void> validate(const AST::TableType &Tab); |
45 | | Expect<void> validate(const AST::MemoryType &Mem); |
46 | | Expect<void> validate(const AST::GlobalType &Glob); |
47 | | // Validate AST::Segments |
48 | | Expect<void> validate(const AST::TableSegment &TabSeg); |
49 | | Expect<void> validate(const AST::GlobalSegment &GlobSeg); |
50 | | Expect<void> validate(const AST::ElementSegment &ElemSeg); |
51 | | Expect<void> validate(const AST::CodeSegment &CodeSeg, |
52 | | const uint32_t TypeIdx); |
53 | | Expect<void> validate(const AST::DataSegment &DataSeg); |
54 | | // Validate AST::Desc |
55 | | Expect<void> validate(const AST::ImportDesc &ImpDesc); |
56 | | Expect<void> validate(const AST::ExportDesc &ExpDesc); |
57 | | // Validate AST::Sections |
58 | | Expect<void> validate(const AST::TypeSection &TypeSec); |
59 | | Expect<void> validate(const AST::ImportSection &ImportSec); |
60 | | Expect<void> validate(const AST::FunctionSection &FuncSec); |
61 | | Expect<void> validate(const AST::TableSection &TabSec); |
62 | | Expect<void> validate(const AST::MemorySection &MemSec); |
63 | | Expect<void> validate(const AST::GlobalSection &GlobSec); |
64 | | Expect<void> validate(const AST::ElementSection &ElemSec); |
65 | | Expect<void> validate(const AST::CodeSection &CodeSec); |
66 | | Expect<void> validate(const AST::DataSection &DataSec); |
67 | | Expect<void> validate(const AST::StartSection &StartSec); |
68 | | Expect<void> validate(const AST::ExportSection &ExportSec); |
69 | | Expect<void> validate(const AST::TagSection &TagSec); |
70 | | // Validate const expression |
71 | | Expect<void> validateConstExpr(AST::InstrView Instrs, |
72 | | Span<const ValType> Returns); |
73 | | /// @} |
74 | | |
75 | | /// \name Validate Component Model AST nodes |
76 | | /// @{ |
77 | | // Validate component sections |
78 | | Expect<void> |
79 | | validate(const AST::Component::CoreModuleSection &ModSec) noexcept; |
80 | | Expect<void> |
81 | | validate(const AST::Component::CoreInstanceSection &InstSec) noexcept; |
82 | | Expect<void> |
83 | | validate(const AST::Component::CoreTypeSection &TypeSec) noexcept; |
84 | | Expect<void> |
85 | | validate(const AST::Component::ComponentSection &CompSec) noexcept; |
86 | | Expect<void> |
87 | | validate(const AST::Component::InstanceSection &InstSec) noexcept; |
88 | | Expect<void> validate(const AST::Component::AliasSection &AliasSec) noexcept; |
89 | | Expect<void> validate(const AST::Component::TypeSection &TypeSec) noexcept; |
90 | | Expect<void> validate(const AST::Component::CanonSection &CanonSec) noexcept; |
91 | | Expect<void> validate(const AST::Component::StartSection &StartSec) noexcept; |
92 | | Expect<void> validate(const AST::Component::ImportSection &ImpSec) noexcept; |
93 | | Expect<void> validate(const AST::Component::ExportSection &ExpSec) noexcept; |
94 | | // Validate component core:instance and instance |
95 | | Expect<void> validate(const AST::Component::CoreInstance &Inst) noexcept; |
96 | | Expect<void> validate(const AST::Component::Instance &Inst) noexcept; |
97 | | // Validate component core:alias and alias |
98 | | // Expect<void> validate(const AST::Component::CoreAlias &Alias) noexcept; |
99 | | Expect<void> validate(const AST::Component::Alias &Alias) noexcept; |
100 | | // Validate component core:deftype and deftype |
101 | | Expect<void> validate(const AST::Component::CoreDefType &DType) noexcept; |
102 | | Expect<void> validate(const AST::Component::DefType &DType) noexcept; |
103 | | // Validate component canonical |
104 | | Expect<void> validate(const AST::Component::Canonical &Canon) noexcept; |
105 | | // Validate component import |
106 | | Expect<void> validate(const AST::Component::Import &Im) noexcept; |
107 | | // Validate component export |
108 | | Expect<void> validate(const AST::Component::Export &Ex) noexcept; |
109 | | // Validate component descs |
110 | | // Expect<void> validate(const AST::Component::CoreImportDesc &Desc) noexcept; |
111 | | Expect<void> validate(const AST::Component::ExternDesc &Desc) noexcept; |
112 | | // decls |
113 | | // Expect<void> validate(const AST::Component::CoreImportDecl &Decl) noexcept; |
114 | | // Expect<void> validate(const AST::Component::CoreExportDecl &Decl) noexcept; |
115 | | Expect<void> validate(const AST::Component::CoreModuleDecl &Decl) noexcept; |
116 | | Expect<void> validate(const AST::Component::ImportDecl &Decl) noexcept; |
117 | | // Expect<void> validate(const AST::Component::ExportDecl &Decl) noexcept; |
118 | | Expect<void> validate(const AST::Component::InstanceDecl &Decl) noexcept; |
119 | | // Expect<void> validate(const AST::Component::ComponentDecl &Decl) noexcept; |
120 | | // types |
121 | | // TODO |
122 | | /// @} |
123 | | |
124 | | /// Memory page limit for WASM32 |
125 | | static inline const uint32_t LIMIT_MEMORYTYPE = 1U << 16; |
126 | | /// Proposal configure |
127 | | const Configure Conf; |
128 | | /// Formal checker |
129 | | FormChecker Checker; |
130 | | /// Context for Component validation |
131 | | ComponentContext CompCtx; |
132 | | }; |
133 | | |
134 | | } // namespace Validator |
135 | | } // namespace WasmEdge |