Coverage Report

Created: 2025-07-01 06:18

/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/context.h"
20
#include "validator/formchecker.h"
21
22
#include <cstdint>
23
#include <memory>
24
25
namespace WasmEdge {
26
namespace Validator {
27
28
/// Validator flow control class.
29
class Validator {
30
public:
31
3.80k
  Validator(const Configure &Conf) noexcept : Conf(Conf) {}
32
3.80k
  ~Validator() noexcept = default;
33
34
  /// Validate AST::Component.
35
  Expect<void> validate(const AST::Component::Component &Comp);
36
  /// Validate AST::Module.
37
  Expect<void> validate(const AST::Module &Mod);
38
39
private:
40
  /// Validate AST::Types
41
  Expect<void> validate(const AST::SubType &Type);
42
  Expect<void> validate(const AST::Limit &Lim);
43
  Expect<void> validate(const AST::TableType &Tab);
44
  Expect<void> validate(const AST::MemoryType &Mem);
45
  Expect<void> validate(const AST::GlobalType &Glob);
46
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
55
  /// Validate AST::Desc
56
  Expect<void> validate(const AST::ImportDesc &ImpDesc);
57
  Expect<void> validate(const AST::ExportDesc &ExpDesc);
58
59
  /// Validate AST::Sections
60
  Expect<void> validate(const AST::TypeSection &TypeSec);
61
  Expect<void> validate(const AST::ImportSection &ImportSec);
62
  Expect<void> validate(const AST::FunctionSection &FuncSec);
63
  Expect<void> validate(const AST::TableSection &TabSec);
64
  Expect<void> validate(const AST::MemorySection &MemSec);
65
  Expect<void> validate(const AST::GlobalSection &GlobSec);
66
  Expect<void> validate(const AST::ElementSection &ElemSec);
67
  Expect<void> validate(const AST::CodeSection &CodeSec);
68
  Expect<void> validate(const AST::DataSection &DataSec);
69
  Expect<void> validate(const AST::StartSection &StartSec);
70
  Expect<void> validate(const AST::ExportSection &ExportSec);
71
  Expect<void> validate(const AST::TagSection &TagSec);
72
73
  /// Validate const expression
74
  Expect<void> validateConstExpr(AST::InstrView Instrs,
75
                                 Span<const ValType> Returns);
76
77
  static inline const uint32_t LIMIT_MEMORYTYPE = 1U << 16;
78
  /// Proposal configure
79
  const Configure Conf;
80
  /// Formal checker
81
  FormChecker Checker;
82
  /// Context for Component validation
83
  Context Ctx;
84
};
85
86
} // namespace Validator
87
} // namespace WasmEdge