From 55af054b6b0b6d30fca7da43ac1c4522ff812e67 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 24 Mar 2021 16:40:00 -0700 Subject: Validator: Pass the module along when printing errors, so type names are used (#3727) For example, on this invalid wat: (module (type $vec (struct (field i64))) (func $test (drop (struct.new_with_rtt $vec (i32.const 1) (rtt.canon $vec)) ) ) ) We used to print: [wasm-validator error in function test] struct.new operand must have proper type, on (struct.new_with_rtt ${i64} (i32.const 1) (rtt.canon ${i64}) ) We will now print: [wasm-validator error in function test] struct.new operand must have proper type, on (struct.new_with_rtt $vec (i32.const 1) (rtt.canon $vec) ) Note that $vec is used. In real-world examples the autogenerated structural name can be huge, which this avoids. --- src/passes/Print.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 6dfd495c0..31a6ccaae 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -31,7 +31,8 @@ namespace wasm { static std::ostream& printExpression(Expression* expression, std::ostream& o, bool minify = false, - bool full = false); + bool full = false, + Module* wasm = nullptr); static std::ostream& printStackInst(StackInst* inst, std::ostream& o, Function* func = nullptr); @@ -3039,13 +3040,15 @@ Pass* createPrintStackIRPass() { return new PrintStackIR(); } static std::ostream& printExpression(Expression* expression, std::ostream& o, bool minify, - bool full) { + bool full, + Module* wasm) { if (!expression) { o << "(null expression)"; return o; } PrintSExpression print(o); print.setMinify(minify); + print.currModule = wasm; if (full || isFullForced()) { print.setFull(true); o << "[" << expression->type << "] "; @@ -3215,6 +3218,10 @@ std::ostream& operator<<(std::ostream& o, wasm::Expression* expression) { return wasm::printExpression(expression, o); } +std::ostream& operator<<(std::ostream& o, wasm::ModuleExpression pair) { + return wasm::printExpression(pair.second, o, false, false, &pair.first); +} + std::ostream& operator<<(std::ostream& o, wasm::StackInst& inst) { return wasm::printStackInst(&inst, o); } -- cgit v1.2.3