2017-09-01 12:57:34 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "test/cctest/wasm/wasm-run-utils.h"
|
|
|
|
|
2017-09-13 10:56:20 +00:00
|
|
|
#include "src/assembler-inl.h"
|
2018-05-07 14:09:04 +00:00
|
|
|
#include "src/code-factory.h"
|
2017-10-02 08:27:24 +00:00
|
|
|
#include "src/wasm/wasm-memory.h"
|
2017-09-08 08:39:19 +00:00
|
|
|
#include "src/wasm/wasm-objects-inl.h"
|
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
2017-09-12 12:39:42 +00:00
|
|
|
TestingModuleBuilder::TestingModuleBuilder(
|
2018-04-06 10:18:18 +00:00
|
|
|
Zone* zone, ManuallyImportedJSFunction* maybe_import,
|
2018-04-19 10:16:37 +00:00
|
|
|
WasmExecutionMode mode, RuntimeExceptionSupport exception_support,
|
2018-04-06 10:18:18 +00:00
|
|
|
LowerSimd lower_simd)
|
2018-04-26 14:37:05 +00:00
|
|
|
: test_module_(std::make_shared<WasmModule>()),
|
|
|
|
test_module_ptr_(test_module_.get()),
|
2017-09-01 12:57:34 +00:00
|
|
|
isolate_(CcTest::InitIsolateOnce()),
|
2017-10-25 12:46:43 +00:00
|
|
|
execution_mode_(mode),
|
2017-10-05 20:22:49 +00:00
|
|
|
runtime_exception_support_(exception_support),
|
2018-01-05 08:43:05 +00:00
|
|
|
lower_simd_(lower_simd) {
|
2017-09-04 12:15:18 +00:00
|
|
|
WasmJs::Install(isolate_, true);
|
2018-05-25 16:07:28 +00:00
|
|
|
test_module_->globals_buffer_size = kMaxGlobalsSize;
|
2017-09-01 12:57:34 +00:00
|
|
|
memset(globals_data_, 0, sizeof(globals_data_));
|
2018-04-06 10:18:18 +00:00
|
|
|
|
|
|
|
uint32_t maybe_import_index = 0;
|
|
|
|
if (maybe_import) {
|
|
|
|
// Manually add an imported function before any other functions.
|
|
|
|
// This must happen before the instance objectis created, since the
|
|
|
|
// instance object allocates import entries.
|
|
|
|
maybe_import_index = AddFunction(maybe_import->sig, nullptr);
|
|
|
|
DCHECK_EQ(0, maybe_import_index);
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->num_imported_functions = 1;
|
|
|
|
test_module_->functions[0].imported = true;
|
2018-04-06 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
instance_object_ = InitInstanceObject();
|
2018-04-06 10:18:18 +00:00
|
|
|
|
|
|
|
if (maybe_import) {
|
|
|
|
// Manually compile a wasm to JS wrapper and insert it into the instance.
|
|
|
|
CodeSpaceMemoryModificationScope modification_scope(isolate_->heap());
|
|
|
|
Handle<Code> code = compiler::CompileWasmToJSWrapper(
|
|
|
|
isolate_, maybe_import->js_function, maybe_import->sig,
|
2018-05-25 16:07:28 +00:00
|
|
|
maybe_import_index, test_module_->origin,
|
2018-04-19 10:16:37 +00:00
|
|
|
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler
|
|
|
|
: kNoTrapHandler);
|
2018-04-09 08:55:55 +00:00
|
|
|
native_module_->ResizeCodeTableForTesting(maybe_import_index + 1,
|
|
|
|
kMaxFunctions);
|
2018-04-06 10:18:18 +00:00
|
|
|
auto wasm_to_js_wrapper = native_module_->AddCodeCopy(
|
|
|
|
code, wasm::WasmCode::kWasmToJsWrapper, maybe_import_index);
|
|
|
|
|
2018-04-27 13:18:30 +00:00
|
|
|
ImportedFunctionEntry(instance_object_, maybe_import_index)
|
2018-05-15 09:10:57 +00:00
|
|
|
.set_wasm_to_js(*maybe_import->js_function, wasm_to_js_wrapper);
|
2018-04-06 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 14:04:14 +00:00
|
|
|
if (mode == kExecuteInterpreter) {
|
2017-09-01 12:57:34 +00:00
|
|
|
interpreter_ = WasmDebugInfo::SetupForTesting(instance_object_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
byte* TestingModuleBuilder::AddMemory(uint32_t size) {
|
2018-04-26 14:37:05 +00:00
|
|
|
CHECK(!test_module_->has_memory);
|
2017-09-01 12:57:34 +00:00
|
|
|
CHECK_NULL(mem_start_);
|
|
|
|
CHECK_EQ(0, mem_size_);
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
DCHECK(!instance_object_->has_memory_object());
|
2018-05-25 16:07:28 +00:00
|
|
|
DCHECK_IMPLIES(test_module_->origin == kWasmOrigin,
|
2018-04-27 21:59:20 +00:00
|
|
|
size % kWasmPageSize == 0);
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->has_memory = true;
|
2018-04-30 18:52:41 +00:00
|
|
|
uint32_t alloc_size = RoundUp(size, kWasmPageSize);
|
2018-04-04 13:34:28 +00:00
|
|
|
Handle<JSArrayBuffer> new_buffer;
|
2018-04-30 18:52:41 +00:00
|
|
|
CHECK(wasm::NewArrayBuffer(isolate_, alloc_size).ToHandle(&new_buffer));
|
2017-09-01 12:57:34 +00:00
|
|
|
CHECK(!new_buffer.is_null());
|
|
|
|
mem_start_ = reinterpret_cast<byte*>(new_buffer->backing_store());
|
|
|
|
mem_size_ = size;
|
|
|
|
CHECK(size == 0 || mem_start_);
|
|
|
|
memset(mem_start_, 0, size);
|
|
|
|
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
// Create the WasmMemoryObject.
|
|
|
|
Handle<WasmMemoryObject> memory_object = WasmMemoryObject::New(
|
|
|
|
isolate_, new_buffer,
|
2018-04-26 14:37:05 +00:00
|
|
|
(test_module_->maximum_pages != 0) ? test_module_->maximum_pages : -1);
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
instance_object_->set_memory_object(*memory_object);
|
|
|
|
WasmMemoryObject::AddInstance(isolate_, memory_object, instance_object_);
|
2018-04-30 18:52:41 +00:00
|
|
|
// TODO(wasm): Delete the following two lines when test-run-wasm will use a
|
|
|
|
// multiple of kPageSize as memory size. At the moment, the effect of these
|
|
|
|
// two lines is used to shrink the memory for testing purposes.
|
|
|
|
instance_object_->SetRawMemory(mem_start_, mem_size_);
|
2017-09-01 12:57:34 +00:00
|
|
|
return mem_start_;
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:25:36 +00:00
|
|
|
uint32_t TestingModuleBuilder::AddFunction(FunctionSig* sig, const char* name) {
|
2018-04-26 14:37:05 +00:00
|
|
|
if (test_module_->functions.size() == 0) {
|
2017-09-01 12:57:34 +00:00
|
|
|
// TODO(titzer): Reserving space here to avoid the underlying WasmFunction
|
|
|
|
// structs from moving.
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->functions.reserve(kMaxFunctions);
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
2018-04-26 14:37:05 +00:00
|
|
|
uint32_t index = static_cast<uint32_t>(test_module_->functions.size());
|
2018-04-06 10:18:18 +00:00
|
|
|
if (native_module_) {
|
2018-04-09 08:55:55 +00:00
|
|
|
native_module_->ResizeCodeTableForTesting(index + 1, kMaxFunctions);
|
2018-04-06 10:18:18 +00:00
|
|
|
}
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->functions.push_back({sig, index, 0, {0, 0}, false, false});
|
2017-09-01 12:57:34 +00:00
|
|
|
if (name) {
|
|
|
|
Vector<const byte> name_vec = Vector<const byte>::cast(CStrVector(name));
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->AddNameForTesting(
|
2018-03-13 16:14:01 +00:00
|
|
|
index, {AddBytes(name_vec), static_cast<uint32_t>(name_vec.length())});
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
if (interpreter_) {
|
2018-04-26 14:37:05 +00:00
|
|
|
interpreter_->AddFunctionForTesting(&test_module_->functions.back());
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
DCHECK_LT(index, kMaxFunctions); // limited for testing.
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> TestingModuleBuilder::WrapCode(uint32_t index) {
|
|
|
|
// Wrap the code so it can be called as a JS function.
|
2017-11-28 22:25:36 +00:00
|
|
|
Link();
|
2018-05-07 13:37:03 +00:00
|
|
|
wasm::WasmCode* code = native_module_->code(index);
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
Handle<Code> ret_code = compiler::CompileJSToWasmWrapper(
|
2018-05-15 17:08:44 +00:00
|
|
|
isolate_, test_module_ptr_, code->instruction_start(), index,
|
2018-04-19 10:16:37 +00:00
|
|
|
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler : kNoTrapHandler);
|
2017-09-01 12:57:34 +00:00
|
|
|
Handle<JSFunction> ret = WasmExportedFunction::New(
|
|
|
|
isolate_, instance_object(), MaybeHandle<String>(),
|
|
|
|
static_cast<int>(index),
|
2018-04-26 14:37:05 +00:00
|
|
|
static_cast<int>(test_module_->functions[index].sig->parameter_count()),
|
2017-09-01 12:57:34 +00:00
|
|
|
ret_code);
|
|
|
|
|
2018-04-09 12:34:46 +00:00
|
|
|
// Add reference to the exported wrapper code.
|
2018-05-11 14:07:21 +00:00
|
|
|
Handle<WasmModuleObject> module_object(instance_object()->module_object(),
|
|
|
|
isolate_);
|
|
|
|
Handle<FixedArray> old_arr(module_object->export_wrappers(), isolate_);
|
2017-09-01 12:57:34 +00:00
|
|
|
Handle<FixedArray> new_arr =
|
|
|
|
isolate_->factory()->NewFixedArray(old_arr->length() + 1);
|
|
|
|
old_arr->CopyTo(0, *new_arr, 0, old_arr->length());
|
2018-04-09 12:34:46 +00:00
|
|
|
new_arr->set(old_arr->length(), *ret_code);
|
2018-05-11 14:07:21 +00:00
|
|
|
module_object->set_export_wrappers(*new_arr);
|
2017-09-01 12:57:34 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:25:31 +00:00
|
|
|
void TestingModuleBuilder::AddIndirectFunctionTable(
|
|
|
|
const uint16_t* function_indexes, uint32_t table_size) {
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->function_tables.emplace_back();
|
|
|
|
WasmIndirectFunctionTable& table = test_module_->function_tables.back();
|
2017-09-01 12:57:34 +00:00
|
|
|
table.initial_size = table_size;
|
|
|
|
table.maximum_size = table_size;
|
|
|
|
table.has_maximum_size = true;
|
|
|
|
for (uint32_t i = 0; i < table_size; ++i) {
|
|
|
|
table.values.push_back(function_indexes[i]);
|
|
|
|
}
|
2018-04-06 10:18:18 +00:00
|
|
|
WasmInstanceObject::EnsureIndirectFunctionTableWithMinimumSize(
|
|
|
|
instance_object(), table_size);
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestingModuleBuilder::PopulateIndirectFunctionTable() {
|
|
|
|
if (interpret()) return;
|
2018-04-06 10:18:18 +00:00
|
|
|
auto instance = instance_object();
|
|
|
|
uint32_t num_tables = 1; // TODO(titzer): multiple tables.
|
|
|
|
for (uint32_t i = 0; i < num_tables; i++) {
|
2018-04-26 14:37:05 +00:00
|
|
|
WasmIndirectFunctionTable& table = test_module_->function_tables[i];
|
2018-04-06 10:18:18 +00:00
|
|
|
int table_size = static_cast<int>(instance->indirect_function_table_size());
|
2017-09-01 12:57:34 +00:00
|
|
|
for (int j = 0; j < table_size; j++) {
|
2018-04-26 14:37:05 +00:00
|
|
|
WasmFunction& function = test_module_->functions[table.values[j]];
|
|
|
|
int sig_id = test_module_->signature_map.Find(function.sig);
|
2018-05-07 13:37:03 +00:00
|
|
|
auto wasm_code = native_module_->code(function.func_index);
|
2018-05-15 17:08:44 +00:00
|
|
|
IndirectFunctionTableEntry(instance, j)
|
|
|
|
.set(sig_id, *instance, wasm_code->instruction_start());
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t TestingModuleBuilder::AddBytes(Vector<const byte> bytes) {
|
2017-12-18 14:08:14 +00:00
|
|
|
Handle<WasmSharedModuleData> shared(
|
2018-05-14 13:55:40 +00:00
|
|
|
instance_object_->module_object()->shared(), isolate_);
|
2017-12-17 19:10:22 +00:00
|
|
|
Handle<SeqOneByteString> old_bytes(shared->module_bytes(), isolate_);
|
2017-09-01 12:57:34 +00:00
|
|
|
uint32_t old_size = static_cast<uint32_t>(old_bytes->length());
|
|
|
|
// Avoid placing strings at offset 0, this might be interpreted as "not
|
|
|
|
// set", e.g. for function names.
|
|
|
|
uint32_t bytes_offset = old_size ? old_size : 1;
|
|
|
|
ScopedVector<byte> new_bytes(bytes_offset + bytes.length());
|
|
|
|
memcpy(new_bytes.start(), old_bytes->GetChars(), old_size);
|
|
|
|
memcpy(new_bytes.start() + bytes_offset, bytes.start(), bytes.length());
|
|
|
|
Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast(
|
|
|
|
isolate_->factory()->NewStringFromOneByte(new_bytes).ToHandleChecked());
|
2017-12-17 19:10:22 +00:00
|
|
|
shared->set_module_bytes(*new_bytes_str);
|
2017-09-01 12:57:34 +00:00
|
|
|
return bytes_offset;
|
|
|
|
}
|
|
|
|
|
2018-04-19 10:16:37 +00:00
|
|
|
ModuleEnv TestingModuleBuilder::CreateModuleEnv() {
|
|
|
|
return {
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_ptr_,
|
2018-04-19 10:16:37 +00:00
|
|
|
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler : kNoTrapHandler,
|
|
|
|
runtime_exception_support_};
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const WasmGlobal* TestingModuleBuilder::AddGlobal(ValueType type) {
|
2018-04-24 13:07:51 +00:00
|
|
|
byte size = ValueTypes::MemSize(ValueTypes::MachineTypeFor(type));
|
2017-09-01 12:57:34 +00:00
|
|
|
global_offset = (global_offset + size - 1) & ~(size - 1); // align
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->globals.push_back(
|
2018-04-25 18:12:51 +00:00
|
|
|
{type, true, WasmInitExpr(), {global_offset}, false, false});
|
2017-09-01 12:57:34 +00:00
|
|
|
global_offset += size;
|
|
|
|
// limit number of globals.
|
|
|
|
CHECK_LT(global_offset, kMaxGlobalsSize);
|
2018-04-26 14:37:05 +00:00
|
|
|
return &test_module_->globals.back();
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
|
|
|
|
Handle<SeqOneByteString> empty_string = Handle<SeqOneByteString>::cast(
|
|
|
|
isolate_->factory()->NewStringFromOneByte({}).ToHandleChecked());
|
2018-05-30 09:48:05 +00:00
|
|
|
size_t module_size = 0;
|
2018-04-26 14:37:05 +00:00
|
|
|
auto managed_module =
|
2018-05-30 09:48:05 +00:00
|
|
|
Managed<WasmModule>::FromSharedPtr(isolate_, module_size, test_module_);
|
2018-04-26 14:37:05 +00:00
|
|
|
DCHECK_EQ(test_module_ptr_, managed_module->raw());
|
2017-09-01 12:57:34 +00:00
|
|
|
Handle<Script> script =
|
|
|
|
isolate_->factory()->NewScript(isolate_->factory()->empty_string());
|
|
|
|
script->set_type(Script::TYPE_WASM);
|
|
|
|
Handle<WasmSharedModuleData> shared_module_data =
|
2018-04-26 14:37:05 +00:00
|
|
|
WasmSharedModuleData::New(isolate_, managed_module, empty_string, script,
|
2017-09-01 12:57:34 +00:00
|
|
|
Handle<ByteArray>::null());
|
|
|
|
Handle<FixedArray> export_wrappers = isolate_->factory()->NewFixedArray(0);
|
2018-04-24 13:10:51 +00:00
|
|
|
ModuleEnv env = CreateModuleEnv();
|
2018-04-06 10:18:18 +00:00
|
|
|
Handle<WasmCompiledModule> compiled_module =
|
2018-05-11 14:07:21 +00:00
|
|
|
WasmCompiledModule::New(isolate_, test_module_ptr_, env);
|
2018-04-27 13:34:00 +00:00
|
|
|
compiled_module->GetNativeModule()->SetSharedModuleData(shared_module_data);
|
2018-05-14 13:55:40 +00:00
|
|
|
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
|
|
|
|
isolate_, compiled_module, export_wrappers, shared_module_data);
|
2017-11-28 22:25:36 +00:00
|
|
|
// This method is called when we initialize TestEnvironment. We don't
|
|
|
|
// have a memory yet, so we won't create it here. We'll update the
|
|
|
|
// interpreter when we get a memory. We do have globals, though.
|
|
|
|
native_module_ = compiled_module->GetNativeModule();
|
|
|
|
|
2018-03-05 12:58:35 +00:00
|
|
|
DCHECK(compiled_module->IsWasmCompiledModule());
|
2018-05-03 08:37:54 +00:00
|
|
|
auto instance =
|
|
|
|
WasmInstanceObject::New(isolate_, module_object, compiled_module);
|
2018-04-06 10:18:18 +00:00
|
|
|
instance->set_globals_start(globals_data_);
|
2017-11-28 22:25:36 +00:00
|
|
|
Handle<WeakCell> weak_instance = isolate()->factory()->NewWeakCell(instance);
|
2017-12-18 14:08:14 +00:00
|
|
|
compiled_module->set_weak_owning_instance(*weak_instance);
|
2017-10-16 08:49:45 +00:00
|
|
|
return instance;
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 23:09:14 +00:00
|
|
|
void TestBuildingGraphWithBuilder(compiler::WasmGraphBuilder* builder,
|
|
|
|
Zone* zone, FunctionSig* sig,
|
|
|
|
const byte* start, const byte* end) {
|
2017-09-01 12:57:34 +00:00
|
|
|
DecodeResult result =
|
2017-12-05 23:09:14 +00:00
|
|
|
BuildTFGraph(zone->allocator(), builder, sig, start, end);
|
2017-09-01 12:57:34 +00:00
|
|
|
if (result.failed()) {
|
2017-12-01 15:22:00 +00:00
|
|
|
#ifdef DEBUG
|
2017-09-01 12:57:34 +00:00
|
|
|
if (!FLAG_trace_wasm_decoder) {
|
|
|
|
// Retry the compilation with the tracing flag on, to help in debugging.
|
|
|
|
FLAG_trace_wasm_decoder = true;
|
2017-12-05 23:09:14 +00:00
|
|
|
result = BuildTFGraph(zone->allocator(), builder, sig, start, end);
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
2017-12-01 15:22:00 +00:00
|
|
|
#endif
|
2017-09-01 12:57:34 +00:00
|
|
|
|
|
|
|
uint32_t pc = result.error_offset();
|
2017-12-18 16:19:23 +00:00
|
|
|
FATAL("Verification failed; pc = +%x, msg = %s", pc,
|
|
|
|
result.error_msg().c_str());
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
2017-12-05 23:09:14 +00:00
|
|
|
builder->LowerInt64();
|
2017-09-01 12:57:34 +00:00
|
|
|
if (!CpuFeatures::SupportsWasmSimd128()) {
|
2017-12-05 23:09:14 +00:00
|
|
|
builder->SimdScalarLoweringForTesting();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-19 10:16:37 +00:00
|
|
|
void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph,
|
|
|
|
ModuleEnv* module, FunctionSig* sig,
|
|
|
|
compiler::SourcePositionTable* source_position_table,
|
|
|
|
const byte* start, const byte* end) {
|
2018-05-25 07:52:27 +00:00
|
|
|
compiler::WasmGraphBuilder builder(jsgraph->isolate(), module, zone, jsgraph,
|
|
|
|
CodeFactory::CEntry(jsgraph->isolate(), 1),
|
|
|
|
sig, source_position_table);
|
|
|
|
TestBuildingGraphWithBuilder(&builder, zone, sig, start, end);
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WasmFunctionWrapper::WasmFunctionWrapper(Zone* zone, int num_params)
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
: GraphAndBuilders(zone),
|
|
|
|
inner_code_node_(nullptr),
|
|
|
|
context_address_(nullptr),
|
|
|
|
signature_(nullptr) {
|
2017-09-01 12:57:34 +00:00
|
|
|
// One additional parameter for the pointer to the return value memory.
|
|
|
|
Signature<MachineType>::Builder sig_builder(zone, 1, num_params + 1);
|
|
|
|
|
|
|
|
sig_builder.AddReturn(MachineType::Int32());
|
|
|
|
for (int i = 0; i < num_params + 1; i++) {
|
|
|
|
sig_builder.AddParam(MachineType::Pointer());
|
|
|
|
}
|
|
|
|
signature_ = sig_builder.Build();
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:19:25 +00:00
|
|
|
void WasmFunctionWrapper::Init(CallDescriptor* call_descriptor,
|
2017-09-01 12:57:34 +00:00
|
|
|
MachineType return_type,
|
|
|
|
Vector<MachineType> param_types) {
|
2018-02-09 19:19:25 +00:00
|
|
|
DCHECK_NOT_NULL(call_descriptor);
|
2017-09-01 12:57:34 +00:00
|
|
|
DCHECK_EQ(signature_->parameter_count(), param_types.length() + 1);
|
|
|
|
|
|
|
|
// Create the TF graph for the wrapper.
|
|
|
|
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
// Function, context_address, effect, and control.
|
|
|
|
Node** parameters = zone()->NewArray<Node*>(param_types.length() + 4);
|
|
|
|
graph()->SetStart(graph()->NewNode(common()->Start(7)));
|
2017-09-01 12:57:34 +00:00
|
|
|
Node* effect = graph()->start();
|
|
|
|
int parameter_count = 0;
|
|
|
|
|
|
|
|
// Dummy node which gets replaced in SetInnerCode.
|
|
|
|
inner_code_node_ = graph()->NewNode(common()->Int32Constant(0));
|
|
|
|
parameters[parameter_count++] = inner_code_node_;
|
|
|
|
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
// Dummy node that gets replaced in SetContextAddress.
|
|
|
|
context_address_ = graph()->NewNode(IntPtrConstant(0));
|
|
|
|
parameters[parameter_count++] = context_address_;
|
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
int param_idx = 0;
|
|
|
|
for (MachineType t : param_types) {
|
|
|
|
DCHECK_NE(MachineType::None(), t);
|
|
|
|
parameters[parameter_count] = graph()->NewNode(
|
|
|
|
machine()->Load(t),
|
|
|
|
graph()->NewNode(common()->Parameter(param_idx++), graph()->start()),
|
|
|
|
graph()->NewNode(common()->Int32Constant(0)), effect, graph()->start());
|
|
|
|
effect = parameters[parameter_count++];
|
|
|
|
}
|
|
|
|
|
|
|
|
parameters[parameter_count++] = effect;
|
|
|
|
parameters[parameter_count++] = graph()->start();
|
2018-02-09 19:19:25 +00:00
|
|
|
Node* call = graph()->NewNode(common()->Call(call_descriptor),
|
|
|
|
parameter_count, parameters);
|
2017-09-01 12:57:34 +00:00
|
|
|
|
|
|
|
if (!return_type.IsNone()) {
|
|
|
|
effect = graph()->NewNode(
|
|
|
|
machine()->Store(compiler::StoreRepresentation(
|
|
|
|
return_type.representation(), WriteBarrierKind::kNoWriteBarrier)),
|
|
|
|
graph()->NewNode(common()->Parameter(param_types.length()),
|
|
|
|
graph()->start()),
|
|
|
|
graph()->NewNode(common()->Int32Constant(0)), call, effect,
|
|
|
|
graph()->start());
|
|
|
|
}
|
|
|
|
Node* zero = graph()->NewNode(common()->Int32Constant(0));
|
|
|
|
Node* r = graph()->NewNode(
|
|
|
|
common()->Return(), zero,
|
|
|
|
graph()->NewNode(common()->Int32Constant(WASM_WRAPPER_RETURN_VALUE)),
|
|
|
|
effect, graph()->start());
|
|
|
|
graph()->SetEnd(graph()->NewNode(common()->End(1), r));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Code> WasmFunctionWrapper::GetWrapperCode() {
|
|
|
|
if (code_.is_null()) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor =
|
2017-09-01 12:57:34 +00:00
|
|
|
compiler::Linkage::GetSimplifiedCDescriptor(zone(), signature_, true);
|
|
|
|
|
|
|
|
if (kPointerSize == 4) {
|
|
|
|
size_t num_params = signature_->parameter_count();
|
|
|
|
// One additional parameter for the pointer of the return value.
|
|
|
|
Signature<MachineRepresentation>::Builder rep_builder(zone(), 1,
|
|
|
|
num_params + 1);
|
|
|
|
|
|
|
|
rep_builder.AddReturn(MachineRepresentation::kWord32);
|
|
|
|
for (size_t i = 0; i < num_params + 1; i++) {
|
|
|
|
rep_builder.AddParam(MachineRepresentation::kWord32);
|
|
|
|
}
|
|
|
|
compiler::Int64Lowering r(graph(), machine(), common(), zone(),
|
|
|
|
rep_builder.Build());
|
|
|
|
r.LowerGraph();
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(ArrayVector("testing"), graph()->zone(),
|
|
|
|
Code::C_WASM_ENTRY);
|
2017-11-15 14:36:57 +00:00
|
|
|
code_ = compiler::Pipeline::GenerateCodeForTesting(
|
2018-02-09 19:19:25 +00:00
|
|
|
&info, isolate, call_descriptor, graph(), nullptr);
|
2017-09-01 12:57:34 +00:00
|
|
|
CHECK(!code_.is_null());
|
|
|
|
#ifdef ENABLE_DISASSEMBLER
|
|
|
|
if (FLAG_print_opt_code) {
|
2018-03-21 16:19:54 +00:00
|
|
|
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
|
|
|
|
OFStream os(tracing_scope.file());
|
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
code_->Disassemble("wasm wrapper", os);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return code_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
|
|
|
|
size_t locals_size = local_decls.Size();
|
|
|
|
size_t total_size = end - start + locals_size + 1;
|
|
|
|
byte* buffer = static_cast<byte*>(zone()->New(total_size));
|
|
|
|
// Prepend the local decls to the code.
|
|
|
|
local_decls.Emit(buffer);
|
|
|
|
// Emit the code.
|
|
|
|
memcpy(buffer + locals_size, start, end - start);
|
|
|
|
// Append an extra end opcode.
|
|
|
|
buffer[total_size - 1] = kExprEnd;
|
|
|
|
|
|
|
|
start = buffer;
|
|
|
|
end = buffer + total_size;
|
|
|
|
|
|
|
|
CHECK_GE(kMaxInt, end - start);
|
|
|
|
int len = static_cast<int>(end - start);
|
|
|
|
function_->code = {builder_->AddBytes(Vector<const byte>(start, len)),
|
|
|
|
static_cast<uint32_t>(len)};
|
|
|
|
|
|
|
|
if (interpreter_) {
|
|
|
|
// Add the code to the interpreter.
|
|
|
|
interpreter_->SetFunctionCodeForTesting(function_, start, end);
|
|
|
|
}
|
|
|
|
|
2017-09-12 12:39:42 +00:00
|
|
|
Handle<WasmCompiledModule> compiled_module(
|
|
|
|
builder_->instance_object()->compiled_module(), isolate());
|
2017-11-28 22:25:36 +00:00
|
|
|
NativeModule* native_module = compiled_module->GetNativeModule();
|
2018-05-14 13:55:40 +00:00
|
|
|
Handle<SeqOneByteString> wire_bytes(
|
|
|
|
builder_->instance_object()->module_object()->shared()->module_bytes(),
|
|
|
|
isolate());
|
2017-09-12 12:39:42 +00:00
|
|
|
|
2018-04-19 10:16:37 +00:00
|
|
|
ModuleEnv module_env = builder_->CreateModuleEnv();
|
2017-09-12 12:39:42 +00:00
|
|
|
ErrorThrower thrower(isolate(), "WasmFunctionCompiler::Build");
|
|
|
|
ScopedVector<uint8_t> func_wire_bytes(function_->code.length());
|
|
|
|
memcpy(func_wire_bytes.start(),
|
|
|
|
wire_bytes->GetChars() + function_->code.offset(),
|
|
|
|
func_wire_bytes.length());
|
2018-03-13 16:14:01 +00:00
|
|
|
WireBytesRef func_name_ref =
|
|
|
|
module_env.module->LookupName(*wire_bytes, function_->func_index);
|
|
|
|
ScopedVector<char> func_name(func_name_ref.length());
|
|
|
|
memcpy(func_name.start(), wire_bytes->GetChars() + func_name_ref.offset(),
|
|
|
|
func_name_ref.length());
|
2017-09-12 12:39:42 +00:00
|
|
|
|
|
|
|
FunctionBody func_body{function_->sig, function_->code.offset(),
|
|
|
|
func_wire_bytes.start(), func_wire_bytes.end()};
|
2018-04-19 10:16:37 +00:00
|
|
|
WasmCompilationUnit::CompilationMode comp_mode =
|
2017-10-25 12:46:43 +00:00
|
|
|
builder_->execution_mode() == WasmExecutionMode::kExecuteLiftoff
|
2018-04-19 10:16:37 +00:00
|
|
|
? WasmCompilationUnit::CompilationMode::kLiftoff
|
|
|
|
: WasmCompilationUnit::CompilationMode::kTurbofan;
|
|
|
|
WasmCompilationUnit unit(isolate(), &module_env, native_module, func_body,
|
|
|
|
func_name, function_->func_index,
|
2018-05-07 14:09:04 +00:00
|
|
|
CodeFactory::CEntry(isolate(), 1), comp_mode,
|
2018-04-19 10:16:37 +00:00
|
|
|
isolate()->counters(), builder_->lower_simd());
|
2017-09-12 12:39:42 +00:00
|
|
|
unit.ExecuteCompilation();
|
2018-03-22 12:24:51 +00:00
|
|
|
wasm::WasmCode* wasm_code = unit.FinishCompilation(&thrower);
|
|
|
|
if (wasm::WasmCode::ShouldBeLogged(isolate())) {
|
|
|
|
wasm_code->LogCode(isolate());
|
|
|
|
}
|
2017-09-12 12:39:42 +00:00
|
|
|
CHECK(!thrower.error());
|
2018-03-12 12:49:18 +00:00
|
|
|
if (trap_handler::IsTrapHandlerEnabled()) {
|
2018-04-05 13:51:09 +00:00
|
|
|
native_module->UnpackAndRegisterProtectedInstructions();
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 12:39:42 +00:00
|
|
|
WasmFunctionCompiler::WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
|
|
|
|
TestingModuleBuilder* builder,
|
|
|
|
const char* name)
|
2017-09-01 12:57:34 +00:00
|
|
|
: GraphAndBuilders(zone),
|
|
|
|
jsgraph(builder->isolate(), this->graph(), this->common(), nullptr,
|
|
|
|
nullptr, this->machine()),
|
|
|
|
sig(sig),
|
|
|
|
descriptor_(nullptr),
|
|
|
|
builder_(builder),
|
|
|
|
local_decls(zone, sig),
|
|
|
|
source_position_table_(this->graph()),
|
2017-09-12 12:39:42 +00:00
|
|
|
interpreter_(builder->interpreter()) {
|
2017-09-01 12:57:34 +00:00
|
|
|
// Get a new function from the testing module.
|
2017-11-28 22:25:36 +00:00
|
|
|
int index = builder->AddFunction(sig, name);
|
2017-09-01 12:57:34 +00:00
|
|
|
function_ = builder_->GetFunctionAt(index);
|
|
|
|
}
|
|
|
|
|
2018-03-12 12:49:18 +00:00
|
|
|
WasmFunctionCompiler::~WasmFunctionCompiler() {}
|
2017-09-25 16:13:13 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
FunctionSig* WasmRunnerBase::CreateSig(MachineType return_type,
|
|
|
|
Vector<MachineType> param_types) {
|
|
|
|
int return_count = return_type.IsNone() ? 0 : 1;
|
|
|
|
int param_count = param_types.length();
|
|
|
|
|
|
|
|
// Allocate storage array in zone.
|
|
|
|
ValueType* sig_types = zone_.NewArray<ValueType>(return_count + param_count);
|
|
|
|
|
|
|
|
// Convert machine types to local types, and check that there are no
|
|
|
|
// MachineType::None()'s in the parameters.
|
|
|
|
int idx = 0;
|
2018-04-24 13:07:51 +00:00
|
|
|
if (return_count) sig_types[idx++] = ValueTypes::ValueTypeFor(return_type);
|
2017-09-01 12:57:34 +00:00
|
|
|
for (MachineType param : param_types) {
|
|
|
|
CHECK_NE(MachineType::None(), param);
|
2018-04-24 13:07:51 +00:00
|
|
|
sig_types[idx++] = ValueTypes::ValueTypeFor(param);
|
2017-09-01 12:57:34 +00:00
|
|
|
}
|
|
|
|
return new (&zone_) FunctionSig(return_count, param_count, sig_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool WasmRunnerBase::trap_happened;
|
|
|
|
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|