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 @@
#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-parser.h"
#include "src/assert-scope.h"
......@@ -17,7 +15,8 @@
#include "src/handles.h"
#include "src/isolate.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/wasm-js.h"
......@@ -192,9 +191,11 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
Zone* compile_zone = info->zone();
Zone translate_zone(info->isolate()->allocator(), ZONE_NAME);
wasm::AsmJsParser parser(info->isolate(), &translate_zone, info->script(),
info->literal()->start_position(),
info->literal()->end_position());
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
handle(String::cast(info->script()->source())),
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()) {
DCHECK(!info->isolate()->has_pending_exception());
ReportCompilationFailure(info->script(), parser.failure_location(),
......
......@@ -11,9 +11,7 @@
#include "src/asmjs/asm-js.h"
#include "src/asmjs/asm-types.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/parsing/scanner-character-streams.h"
#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker.
#include "src/parsing/scanner.h"
#include "src/wasm/wasm-opcodes.h"
......@@ -68,16 +66,16 @@ namespace wasm {
#define TOK(name) AsmJsScanner::kToken_##name
AsmJsParser::AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script,
int start, int end)
AsmJsParser::AsmJsParser(Zone* zone, uintptr_t stack_limit,
std::unique_ptr<Utf16CharacterStream> stream)
: zone_(zone),
module_builder_(new (zone) WasmModuleBuilder(zone)),
return_type_(nullptr),
stack_limit_(isolate->stack_guard()->real_climit()),
stack_limit_(stack_limit),
global_var_info_(zone),
local_var_info_(zone),
failed_(false),
failure_location_(start),
failure_location_(kNoSourcePosition),
stdlib_name_(kTokenNone),
foreign_name_(kTokenNone),
heap_name_(kTokenNone),
......@@ -89,9 +87,6 @@ AsmJsParser::AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script,
pending_label_(0),
global_imports_(zone) {
InitializeStdlibTypes();
Handle<String> source(String::cast(script->source()), isolate);
std::unique_ptr<Utf16CharacterStream> stream(
ScannerStream::For(source, start, end));
scanner_.SetStream(std::move(stream));
}
......
......@@ -5,8 +5,8 @@
#ifndef V8_ASMJS_ASM_PARSER_H_
#define V8_ASMJS_ASM_PARSER_H_
#include <memory>
#include <string>
#include <vector>
#include "src/asmjs/asm-scanner.h"
#include "src/asmjs/asm-types.h"
......@@ -15,6 +15,9 @@
namespace v8 {
namespace internal {
class Utf16CharacterStream;
namespace wasm {
// A custom parser + validator + wasm converter for asm.js:
......@@ -46,8 +49,8 @@ class AsmJsParser {
typedef std::unordered_set<StandardMember, std::hash<int>> StdlibSet;
explicit AsmJsParser(Isolate* isolate, Zone* zone, Handle<Script> script,
int start, int end);
explicit AsmJsParser(Zone* zone, uintptr_t stack_limit,
std::unique_ptr<Utf16CharacterStream> stream);
bool Run();
const char* failure_message() const { return failure_message_; }
int failure_location() const { return failure_location_; }
......
......@@ -46,6 +46,10 @@ AsmJsScanner::AsmJsScanner()
#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) {
stream_ = std::move(stream);
Next();
......
......@@ -32,6 +32,8 @@ class V8_EXPORT_PRIVATE AsmJsScanner {
typedef int32_t token_t;
AsmJsScanner();
~AsmJsScanner();
// Pick the stream to parse (must be called before anything else).
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