Validate Module. See "include/validator/validator.h".
| 67 | |
| 68 | // Validate Module. See "include/validator/validator.h". |
| 69 | Expect<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; |
no test coverage detected