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

[asm.js] Make the parser independent of the Isolate.

This removes any kind of heap access from the asm.js validator internals
and hence makes it independent of a specific Isolate. It is a precursor
towards potentially being able to run validation while streaming.

R=clemensh@chromium.org

Change-Id: Ia3770bf03bb973b56de897b27be60d7e050af2c4
Reviewed-on: https://chromium-review.googlesource.com/518188
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45628}
parent 8f61fbc6
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "src/asmjs/asm-js.h" #include "src/asmjs/asm-js.h"
#include "src/api-natives.h"
#include "src/api.h"
#include "src/asmjs/asm-names.h" #include "src/asmjs/asm-names.h"
#include "src/asmjs/asm-parser.h" #include "src/asmjs/asm-parser.h"
#include "src/assert-scope.h" #include "src/assert-scope.h"
...@@ -17,7 +15,8 @@ ...@@ -17,7 +15,8 @@
#include "src/handles.h" #include "src/handles.h"
#include "src/isolate.h" #include "src/isolate.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/objects.h" #include "src/parsing/scanner-character-streams.h"
#include "src/parsing/scanner.h"
#include "src/wasm/module-decoder.h" #include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-js.h" #include "src/wasm/wasm-js.h"
...@@ -192,9 +191,11 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) { ...@@ -192,9 +191,11 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
Zone* compile_zone = info->zone(); Zone* compile_zone = info->zone();
Zone translate_zone(info->isolate()->allocator(), ZONE_NAME); Zone translate_zone(info->isolate()->allocator(), ZONE_NAME);
wasm::AsmJsParser parser(info->isolate(), &translate_zone, info->script(), std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
info->literal()->start_position(), handle(String::cast(info->script()->source())),
info->literal()->end_position()); info->literal()->start_position(), info->literal()->end_position()));
uintptr_t stack_limit = info->isolate()->stack_guard()->real_climit();
wasm::AsmJsParser parser(&translate_zone, stack_limit, std::move(stream));
if (!parser.Run()) { if (!parser.Run()) {
DCHECK(!info->isolate()->has_pending_exception()); DCHECK(!info->isolate()->has_pending_exception());
ReportCompilationFailure(info->script(), parser.failure_location(), ReportCompilationFailure(info->script(), parser.failure_location(),
......
...@@ -11,9 +11,7 @@ ...@@ -11,9 +11,7 @@
#include "src/asmjs/asm-js.h" #include "src/asmjs/asm-js.h"
#include "src/asmjs/asm-types.h" #include "src/asmjs/asm-types.h"
#include "src/objects-inl.h" #include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker.
#include "src/objects.h"
#include "src/parsing/scanner-character-streams.h"
#include "src/parsing/scanner.h" #include "src/parsing/scanner.h"
#include "src/wasm/wasm-opcodes.h" #include "src/wasm/wasm-opcodes.h"
...@@ -68,16 +66,16 @@ namespace wasm { ...@@ -68,16 +66,16 @@ namespace wasm {
#define TOK(name) AsmJsScanner::kToken_##name #define TOK(name) AsmJsScanner::kToken_##name
AsmJsParser::AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script, AsmJsParser::AsmJsParser(Zone* zone, uintptr_t stack_limit,
int start, int end) std::unique_ptr<Utf16CharacterStream> stream)
: zone_(zone), : zone_(zone),
module_builder_(new (zone) WasmModuleBuilder(zone)), module_builder_(new (zone) WasmModuleBuilder(zone)),
return_type_(nullptr), return_type_(nullptr),
stack_limit_(isolate->stack_guard()->real_climit()), stack_limit_(stack_limit),
global_var_info_(zone), global_var_info_(zone),
local_var_info_(zone), local_var_info_(zone),
failed_(false), failed_(false),
failure_location_(start), failure_location_(kNoSourcePosition),
stdlib_name_(kTokenNone), stdlib_name_(kTokenNone),
foreign_name_(kTokenNone), foreign_name_(kTokenNone),
heap_name_(kTokenNone), heap_name_(kTokenNone),
...@@ -89,9 +87,6 @@ AsmJsParser::AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script, ...@@ -89,9 +87,6 @@ AsmJsParser::AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script,
pending_label_(0), pending_label_(0),
global_imports_(zone) { global_imports_(zone) {
InitializeStdlibTypes(); InitializeStdlibTypes();
Handle<String> source(String::cast(script->source()), isolate);
std::unique_ptr<Utf16CharacterStream> stream(
ScannerStream::For(source, start, end));
scanner_.SetStream(std::move(stream)); scanner_.SetStream(std::move(stream));
} }
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#ifndef V8_ASMJS_ASM_PARSER_H_ #ifndef V8_ASMJS_ASM_PARSER_H_
#define V8_ASMJS_ASM_PARSER_H_ #define V8_ASMJS_ASM_PARSER_H_
#include <memory>
#include <string> #include <string>
#include <vector>
#include "src/asmjs/asm-scanner.h" #include "src/asmjs/asm-scanner.h"
#include "src/asmjs/asm-types.h" #include "src/asmjs/asm-types.h"
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class Utf16CharacterStream;
namespace wasm { namespace wasm {
// A custom parser + validator + wasm converter for asm.js: // A custom parser + validator + wasm converter for asm.js:
...@@ -46,8 +49,8 @@ class AsmJsParser { ...@@ -46,8 +49,8 @@ class AsmJsParser {
typedef std::unordered_set<StandardMember, std::hash<int>> StdlibSet; typedef std::unordered_set<StandardMember, std::hash<int>> StdlibSet;
explicit AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script, explicit AsmJsParser(Zone* zone, uintptr_t stack_limit,
int start, int end); std::unique_ptr<Utf16CharacterStream> stream);
bool Run(); bool Run();
const char* failure_message() const { return failure_message_; } const char* failure_message() const { return failure_message_; }
int failure_location() const { return failure_location_; } int failure_location() const { return failure_location_; }
......
...@@ -46,6 +46,10 @@ AsmJsScanner::AsmJsScanner() ...@@ -46,6 +46,10 @@ AsmJsScanner::AsmJsScanner()
#undef V #undef V
} }
// Destructor of unique_ptr<T> requires complete declaration of T, we only want
// to include the necessary declaration here instead of the header file.
AsmJsScanner::~AsmJsScanner() {}
void AsmJsScanner::SetStream(std::unique_ptr<Utf16CharacterStream> stream) { void AsmJsScanner::SetStream(std::unique_ptr<Utf16CharacterStream> stream) {
stream_ = std::move(stream); stream_ = std::move(stream);
Next(); Next();
......
...@@ -32,6 +32,8 @@ class V8_EXPORT_PRIVATE AsmJsScanner { ...@@ -32,6 +32,8 @@ class V8_EXPORT_PRIVATE AsmJsScanner {
typedef int32_t token_t; typedef int32_t token_t;
AsmJsScanner(); AsmJsScanner();
~AsmJsScanner();
// Pick the stream to parse (must be called before anything else). // Pick the stream to parse (must be called before anything else).
void SetStream(std::unique_ptr<Utf16CharacterStream> stream); void SetStream(std::unique_ptr<Utf16CharacterStream> stream);
......
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