From 5930e0ab393217e9a3da481bd2e80a886c4d7c90 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Tue, 18 Apr 2017 14:10:56 +0200 Subject: [PATCH] [asm.js] Use token position instead of stream position. This switches the parser to use token positions (i.e. {Position}) instead of stream positions (i.e. {GetPosition}) everywhere. Access to the latter is being removed as it is unsupported when the scanner is in rewind state anyways. This prevents "skipping" a token when seeking. R=bradnelson@chromium.org BUG=v8:6127 Change-Id: I9c13dd20a981061a2bccc4fb57e5c57d2a64ac5c Reviewed-on: https://chromium-review.googlesource.com/480300 Reviewed-by: Brad Nelson Commit-Queue: Brad Nelson Cr-Commit-Position: refs/heads/master@{#44699} --- src/asmjs/asm-parser.cc | 21 ++++++++++---------- src/asmjs/asm-parser.h | 4 ++-- src/asmjs/asm-scanner.cc | 7 +------ src/asmjs/asm-scanner.h | 7 +++---- test/unittests/asmjs/asm-scanner-unittest.cc | 3 ++- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/asmjs/asm-parser.cc b/src/asmjs/asm-parser.cc index 5d1eaafffbdc..b0ca1bf9f209 100644 --- a/src/asmjs/asm-parser.cc +++ b/src/asmjs/asm-parser.cc @@ -29,17 +29,17 @@ namespace wasm { #define FAIL_AND_RETURN(ret, msg) \ failed_ = true; \ failure_message_ = msg; \ - failure_location_ = scanner_.GetPosition(); \ + failure_location_ = static_cast(scanner_.Position()); \ 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) \ - failed_ = true; \ - failure_message_ = msg; \ - failure_location_ = scanner_.GetPosition(); \ +#define FAIL_AND_RETURN(ret, msg) \ + failed_ = true; \ + failure_message_ = msg; \ + failure_location_ = static_cast(scanner_.Position()); \ return ret; #endif @@ -1302,7 +1302,8 @@ void AsmJsParser::SwitchStatement() { pending_label_ = 0; // TODO(bradnelson): Make less weird. std::vector cases; - GatherCases(&cases); // Skips { implicitly. + GatherCases(&cases); + EXPECT_TOKEN('{'); size_t count = cases.size() + 1; for (size_t i = 0; i < count; ++i) { BareBegin(BlockKind::kOther); @@ -1958,17 +1959,17 @@ AsmType* AsmJsParser::BitwiseORExpression() { call_coercion_deferred_ = nullptr; // TODO(bradnelson): Make it prettier. bool zero = false; - int old_pos; + size_t old_pos; size_t old_code; if (a->IsA(AsmType::Intish()) && CheckForZero()) { - old_pos = scanner_.GetPosition(); + old_pos = scanner_.Position(); old_code = current_function_builder_->GetPosition(); scanner_.Rewind(); zero = true; } RECURSEn(b = BitwiseXORExpression()); // Handle |0 specially. - if (zero && old_pos == scanner_.GetPosition()) { + if (zero && old_pos == scanner_.Position()) { current_function_builder_->StashCode(nullptr, old_code); a = AsmType::Signed(); continue; @@ -2440,7 +2441,7 @@ void AsmJsParser::ValidateFloatCoercion() { } void AsmJsParser::GatherCases(std::vector* cases) { - int start = scanner_.GetPosition(); + size_t start = scanner_.Position(); int depth = 0; for (;;) { if (Peek('{')) { diff --git a/src/asmjs/asm-parser.h b/src/asmjs/asm-parser.h index 65974eb9ab67..3b019e3646b6 100644 --- a/src/asmjs/asm-parser.h +++ b/src/asmjs/asm-parser.h @@ -34,7 +34,7 @@ class AsmJsParser { explicit AsmJsParser(Isolate* isolate, Zone* zone, Handle