From 6c6aae1358d657fe16fcfdc3a0eccfcea66cc841 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 12 Aug 2022 14:29:12 -0700 Subject: Function-level pass-debug mode 2 validation (#4897) In BINARYEN_PASS_DEBUG=2 we save the module before each pass, and if validation fails afterwards, we print the module before. This PR does the same for function-parallel passes - in that case, we can actually show the specific function that broke validation, as opposed to the whole module. --- src/wasm/wasm-validator.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 10310f8c0..572a3b4ba 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -223,6 +223,9 @@ struct FunctionValidator : public WalkerPass> { // Validate a specific expression. void validate(Expression* curr) { walk(curr); } + // Validate a function. + void validate(Function* func) { walkFunction(func); } + std::unordered_map> breakTypes; std::unordered_set delegateTargetNames; std::unordered_set rethrowTargetNames; @@ -3215,4 +3218,18 @@ bool WasmValidator::validate(Module& module, Flags flags) { return info.valid.load(); } +bool WasmValidator::validate(Function* func, Module& module, Flags flags) { + ValidationInfo info(module); + info.validateWeb = (flags & Web) != 0; + info.validateGlobally = (flags & Globally) != 0; + info.quiet = (flags & Quiet) != 0; + FunctionValidator(module, &info).validate(func); + // print all the data + if (!info.valid.load() && !info.quiet) { + std::cerr << info.getStream(func).str(); + std::cerr << info.getStream(nullptr).str(); + } + return info.valid.load(); +} + } // namespace wasm -- cgit v1.2.3