MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / validate

Method validate

lib/validator/validator.cpp:69–178  ·  view source on GitHub ↗

Validate Module. See "include/validator/validator.h".

Source from the content-addressed store, hash-verified

67
68// Validate Module. See "include/validator/validator.h".
69Expect<void> Validator::validate(const AST::Module &Mod) {
70 // https://webassembly.github.io/spec/core/valid/modules.html
71 Checker.reset(true);
72
73 // Validate and register type section.
74 EXPECTED_TRY(validate(Mod.getTypeSection()).map_error([](auto E) {
75 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Type));
76 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
77 return E;
78 }));
79
80 // Validate and register the import section in FormChecker.
81 EXPECTED_TRY(validate(Mod.getImportSection()).map_error([](auto E) {
82 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Import));
83 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
84 return E;
85 }));
86
87 // Validate the function section and register functions in FormChecker.
88 EXPECTED_TRY(validate(Mod.getFunctionSection()).map_error([](auto E) {
89 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Function));
90 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
91 return E;
92 }));
93
94 // Validate the table section and register tables in FormChecker.
95 EXPECTED_TRY(validate(Mod.getTableSection()).map_error([](auto E) {
96 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Table));
97 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
98 return E;
99 }));
100
101 // Validate the memory section and register memories in FormChecker.
102 EXPECTED_TRY(validate(Mod.getMemorySection()).map_error([](auto E) {
103 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Memory));
104 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
105 return E;
106 }));
107
108 // Validate the global section and register globals in FormChecker.
109 EXPECTED_TRY(validate(Mod.getGlobalSection()).map_error([](auto E) {
110 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Global));
111 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
112 return E;
113 }));
114
115 // Validate the tag section and register tags in FormChecker.
116 EXPECTED_TRY(validate(Mod.getTagSection()).map_error([](auto E) {
117 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Tag));
118 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
119 return E;
120 }));
121
122 // Validate export section.
123 EXPECTED_TRY(validate(Mod.getExportSection()).map_error([](auto E) {
124 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Sec_Export));
125 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Module));
126 return E;

Callers 12

validateConstExprMethod · 0.45
FuzzToolFunction · 0.45
ToolFunction · 0.45
CompilerFunction · 0.45
unsafeRegisterModuleMethod · 0.45
unsafeRunWasmFileMethod · 0.45
operator()Method · 0.45
unsafeValidateMethod · 0.45

Calls 15

InfoASTClass · 0.85
InfoProposalClass · 0.85
UnexpectFunction · 0.85
unlikelyFunction · 0.85
InfoForbidIndexClass · 0.85
checkSubtypeDepthFunction · 0.85
InfoLimitClass · 0.85
getMaxAddressFunction · 0.85
ValTypeClass · 0.85
InfoMismatchClass · 0.85
hasProposalMethod · 0.80
getParamTypesMethod · 0.80

Tested by

no test coverage detected