Commit 953bdee0 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Track token positions in scanner.

This adds support for tracking token positions in the asm.js scanner and
uses these positions to emit a mapping from WASM to asm.js positions.
Note that the mapping is still incomplete (some call sites are not yet
covered).

R=clemensh@chromium.org
TEST=debugger/debug/wasm/asm-debug
BUG=v8:6127

Change-Id: Ic8aad1a85e7d9e19da2eec523fcc73d4984afcc8
Reviewed-on: https://chromium-review.googlesource.com/466046
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44335}
parent e43cc913
......@@ -2000,6 +2000,7 @@ AsmType* AsmJsParser::ParenthesizedExpression() {
AsmType* AsmJsParser::ValidateCall() {
AsmType* return_type = call_coercion_;
call_coercion_ = nullptr;
int pos = static_cast<int>(scanner_.Position());
AsmJsScanner::token_t function_name = Consume();
int32_t tmp = TempVariable(0);
if (Check('[')) {
......@@ -2113,6 +2114,8 @@ AsmType* AsmJsParser::ValidateCall() {
} else {
index = function_info->import->cache_index[cache_index];
}
// TODO(mstarzinger): Fix the {to_number_position} and test it.
current_function_builder_->AddAsmWasmOffset(pos, pos);
current_function_builder_->Emit(kExprCallFunction);
current_function_builder_->EmitVarUint(index);
} else if (function_info->type->IsA(AsmType::None())) {
......@@ -2127,8 +2130,8 @@ AsmType* AsmJsParser::ValidateCall() {
current_function_builder_->EmitVarUint(signature_index);
current_function_builder_->EmitVarUint(0); // table index
} else {
// current_function_builder_->AddAsmWasmOffset(scanner_.GetPosition(),
// scanner_.GetPosition());
// TODO(mstarzinger): Fix the {to_number_position} and test it.
current_function_builder_->AddAsmWasmOffset(pos, pos);
current_function_builder_->Emit(kExprCallFunction);
current_function_builder_->EmitDirectCallIndex(function_info->index);
}
......
......@@ -303,4 +303,5 @@ class AsmJsParser {
} // namespace wasm
} // namespace internal
} // namespace v8
#endif
#endif // V8_ASMJS_ASM_PARSER_H_
......@@ -22,6 +22,9 @@ AsmJsScanner::AsmJsScanner()
: token_(kUninitialized),
preceding_token_(kUninitialized),
next_token_(kUninitialized),
position_(0),
preceding_position_(0),
next_position_(0),
rewind_(false),
in_local_scope_(false),
global_count_(0),
......@@ -49,8 +52,11 @@ void AsmJsScanner::SetStream(std::unique_ptr<Utf16CharacterStream> stream) {
void AsmJsScanner::Next() {
if (rewind_) {
preceding_token_ = token_;
preceding_position_ = position_;
token_ = next_token_;
position_ = next_position_;
next_token_ = kUninitialized;
next_position_ = 0;
rewind_ = false;
return;
}
......@@ -74,7 +80,10 @@ void AsmJsScanner::Next() {
preceded_by_newline_ = false;
preceding_token_ = token_;
preceding_position_ = position_;
for (;;) {
position_ = stream_->pos();
uc32 ch = stream_->Advance();
switch (ch) {
case ' ':
......@@ -145,13 +154,17 @@ void AsmJsScanner::Next() {
}
void AsmJsScanner::Rewind() {
DCHECK_NE(kUninitialized, preceding_token_);
// TODO(bradnelson): Currently rewinding needs to leave in place the
// preceding newline state (in case a |0 ends a line).
// This is weird and stateful, fix me.
DCHECK(!rewind_);
next_token_ = token_;
next_position_ = position_;
token_ = preceding_token_;
position_ = preceding_position_;
preceding_token_ = kUninitialized;
preceding_position_ = 0;
rewind_ = true;
identifier_string_.clear();
}
......@@ -207,6 +220,9 @@ void AsmJsScanner::Seek(int pos) {
preceding_token_ = kUninitialized;
token_ = kUninitialized;
next_token_ = kUninitialized;
preceding_position_ = 0;
position_ = 0;
next_position_ = 0;
rewind_ = false;
Next();
}
......
......@@ -37,6 +37,8 @@ class V8_EXPORT_PRIVATE AsmJsScanner {
// Get current token.
token_t Token() const { return token_; }
// Get position of current token.
size_t Position() const { return position_; }
// Advance to the next token.
void Next();
// Back up by one token.
......@@ -128,7 +130,10 @@ class V8_EXPORT_PRIVATE AsmJsScanner {
std::unique_ptr<Utf16CharacterStream> stream_;
token_t token_;
token_t preceding_token_;
token_t next_token_;
token_t next_token_; // Only set when in {rewind} state.
size_t position_; // Corresponds to {token} position.
size_t preceding_position_; // Corresponds to {preceding_token} position.
size_t next_position_; // Only set when in {rewind} state.
bool rewind_;
std::string identifier_string_;
bool in_local_scope_;
......@@ -156,4 +161,5 @@ class V8_EXPORT_PRIVATE AsmJsScanner {
} // namespace internal
} // namespace v8
#endif
#endif // V8_ASMJS_ASM_SCANNER_H_
......@@ -71,13 +71,6 @@
'debug/debug-evaluate-locals': [FAIL],
}], # variant == turbofan_opt
##############################################################################
['variant == asm_wasm', {
# Issue 6127: We won't fix these in the "old" validator. But we definitely
# need to re-enable these for the "new" validator.
'debug/wasm/asm-debug': [SKIP],
}], # variant == asm_wasm
##############################################################################
['variant == wasm_traps', {
'*': [SKIP],
......
......@@ -660,7 +660,6 @@
# Issue 6127: We won't fix these in the "old" validator. But we definitely
# need to re-enable these for the "new" validator.
'regress/regress-618608': [SKIP],
'regress/regress-670808': [SKIP],
'wasm/asm-wasm-exception-in-tonumber': [SKIP],
'wasm/asm-wasm-stack': [SKIP],
}], # variant == asm_wasm
......
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