Commit adbc2d44 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Make validation error messages consistent.

This removes the debug information (i.e. direct references to the parser
source file) from the message, hence making messages consistent between
release and debug mode. The debug information can now be printed via the
new --trace-asm-parser flag.

Also adds two message test cases, showcasing that expected output can
now be tested. More tests might be added to the message test suite later
whenever it makes sense.

R=clemensh@chromium.org
BUG=v8:6127

Change-Id: I348044356896442ff9be2d638a564c82fec7a51c
Reviewed-on: https://chromium-review.googlesource.com/461942
Commit-Queue: Brad Nelson <bradnelson@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44248}
parent a857e3d0
......@@ -26,12 +26,14 @@ namespace internal {
namespace wasm {
#ifdef DEBUG
#define FAIL_AND_RETURN(ret, msg) \
failed_ = true; \
failure_message_ = std::string(msg) + \
" token: " + scanner_.Name(scanner_.Token()) + \
" see: " + __FILE__ + ":" + std::to_string(__LINE__); \
failure_location_ = scanner_.GetPosition(); \
#define FAIL_AND_RETURN(ret, msg) \
failed_ = true; \
failure_message_ = msg; \
failure_location_ = scanner_.GetPosition(); \
if (FLAG_trace_asm_parser) { \
PrintF("[asm.js failure: %s, token: '%s', see: %s:%d]\n", msg, \
scanner_.Name(scanner_.Token()).c_str(), __FILE__, __LINE__); \
} \
return ret;
#else
#define FAIL_AND_RETURN(ret, msg) \
......@@ -45,25 +47,13 @@ namespace wasm {
#define FAILn(msg) FAIL_AND_RETURN(nullptr, msg)
#define FAILf(msg) FAIL_AND_RETURN(false, msg)
#ifdef DEBUG
#define EXPECT_TOKEN_OR_RETURN(ret, token) \
do { \
if (scanner_.Token() != token) { \
FAIL_AND_RETURN(ret, std::string("expected token ") + \
scanner_.Name(token) + " but found " + \
scanner_.Name(scanner_.Token())); \
} \
scanner_.Next(); \
} while (false);
#else
#define EXPECT_TOKEN_OR_RETURN(ret, token) \
do { \
if (scanner_.Token() != token) { \
FAIL_AND_RETURN(ret, "unexpected token"); \
FAIL_AND_RETURN(ret, "Unexpected token"); \
} \
scanner_.Next(); \
} while (false);
#endif
} while (false)
#define EXPECT_TOKEN(token) EXPECT_TOKEN_OR_RETURN(, token)
#define EXPECT_TOKENn(token) EXPECT_TOKEN_OR_RETURN(nullptr, token)
......@@ -77,7 +67,7 @@ namespace wasm {
} \
call; \
if (failed_) return ret; \
} while (false);
} while (false)
#define RECURSE(call) RECURSE_OR_RETURN(, call)
#define RECURSEn(call) RECURSE_OR_RETURN(nullptr, call)
......
......@@ -554,6 +554,7 @@ DEFINE_BOOL(suppress_asm_messages, false,
DEFINE_BOOL(trace_asm_time, false, "log asm.js timing info to the console")
DEFINE_BOOL(trace_asm_scanner, false,
"log tokens encountered by asm.js scanner")
DEFINE_BOOL(trace_asm_parser, false, "verbose logging of asm.js parse failures")
DEFINE_BOOL(stress_validate_asm, false, "try to validate everything as asm.js")
DEFINE_BOOL(dump_wasm_module, false, "dump WASM module bytes")
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages --fast-validate-asm
function Module() {
"use asm"
function f(a) {
var b = 0;
b = (a + 23) | 0;
return b | 0;
}
return { f:f };
}
Module().f();
# Copyright 2017 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
*%(basename)s:11: Invalid asm.js: Unexpected token
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages --fast-validate-asm
function Module() {
"use asm"
function f(a) {
a = a | 0;
var b = 0;
b = (a + 23) | 0;
return b;
}
return { f:f };
}
Module().f();
# Copyright 2017 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
*%(basename)s:13: Invalid asm.js: Invalid return type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment