2016-09-12 12:26:37 +00:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
|
|
|
#ifndef V8_WASM_MODULE_RUNNER_H_
|
|
|
|
#define V8_WASM_MODULE_RUNNER_H_
|
|
|
|
|
|
|
|
#include "src/isolate.h"
|
|
|
|
#include "src/objects.h"
|
|
|
|
#include "src/wasm/wasm-interpreter.h"
|
|
|
|
#include "src/wasm/wasm-module.h"
|
2016-11-16 16:17:22 +00:00
|
|
|
#include "src/wasm/wasm-objects.h"
|
2016-09-12 12:26:37 +00:00
|
|
|
#include "src/wasm/wasm-result.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/zone/zone.h"
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-01-27 13:53:13 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Handle;
|
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
namespace wasm {
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
// Decodes the given encoded module.
|
2017-05-08 12:45:20 +00:00
|
|
|
std::unique_ptr<WasmModule> DecodeWasmModuleForTesting(
|
2016-11-14 19:45:16 +00:00
|
|
|
Isolate* isolate, ErrorThrower* thrower, const byte* module_start,
|
|
|
|
const byte* module_end, ModuleOrigin origin, bool verify_functions = false);
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
// Instantiates a module without any imports and exports.
|
2016-11-16 16:17:22 +00:00
|
|
|
const Handle<WasmInstanceObject> InstantiateModuleForTesting(
|
2016-11-30 15:02:40 +00:00
|
|
|
Isolate* isolate, ErrorThrower* thrower, const WasmModule* module,
|
|
|
|
const ModuleWireBytes& wire_bytes);
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
|
2016-09-15 16:19:48 +00:00
|
|
|
ErrorThrower* thrower, const char* name,
|
2016-09-12 12:26:37 +00:00
|
|
|
int argc, Handle<Object> argv[],
|
2016-09-12 22:11:12 +00:00
|
|
|
ModuleOrigin origin);
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
// Decode, verify, and run the function labeled "main" in the
|
|
|
|
// given encoded module. The module should have no imports.
|
|
|
|
int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
|
2016-09-12 22:11:12 +00:00
|
|
|
const byte* module_end, ModuleOrigin origin);
|
2016-09-12 12:26:37 +00:00
|
|
|
|
|
|
|
// Interprets the given module, starting at the function specified by
|
|
|
|
// {function_index}. The return type of the function has to be int32. The module
|
|
|
|
// should not have any imports or exports
|
2017-06-12 11:13:15 +00:00
|
|
|
int32_t InterpretWasmModule(Isolate* isolate,
|
|
|
|
Handle<WasmInstanceObject> instance,
|
|
|
|
ErrorThrower* thrower, int32_t function_index,
|
|
|
|
WasmVal* args, bool* possible_nondeterminism);
|
2016-09-17 01:30:09 +00:00
|
|
|
|
2016-09-28 20:55:42 +00:00
|
|
|
// Compiles WasmModule bytes and return an instance of the compiled module.
|
2016-11-16 16:17:22 +00:00
|
|
|
const Handle<WasmInstanceObject> CompileInstantiateWasmModuleForTesting(
|
[wasm] Use a Managed<WasmModule> to hold metadata about modules.
This CL refactors the handling of metadata associated with WebAssembly
modules to reduce the duplicate marshalling of data from the C++ world
to the JavaScript world. It does this by wrapping the C++ WasmModule*
object in a Foreign that is rooted from the on-heap WasmCompiledModule
(which is itself just a FixedArray). Upon serialization, the C++ object
is ignored and the original WASM wire bytes are serialized. Upon
deserialization, the C++ object is reconstituted by reparsing the bytes.
This is motivated by increasing complications in implementing the JS
API, in particular WebAssembly.Table, which must perform signature
canonicalization across instances.
Additionally, this CL implements the proper base + offset initialization
behavior for tables.
R=rossberg@chromium.org,bradnelson@chromium.org,mtrofin@chromium.org,yangguo@chromium.org
BUG=v8:5507, chromium:575167, chromium:657316
Review-Url: https://chromiumcodereview.appspot.com/2424623002
Cr-Commit-Position: refs/heads/master@{#40434}
2016-10-19 13:06:44 +00:00
|
|
|
Isolate* isolate, ErrorThrower* thrower, const byte* module_start,
|
|
|
|
const byte* module_end, ModuleOrigin origin);
|
2016-09-28 20:55:42 +00:00
|
|
|
|
|
|
|
// Runs the module instance with arguments.
|
|
|
|
int32_t RunWasmModuleForTesting(Isolate* isolate, Handle<JSObject> instance,
|
|
|
|
int argc, Handle<Object> argv[],
|
|
|
|
ModuleOrigin origin);
|
2016-09-17 01:30:09 +00:00
|
|
|
// Install function map, module symbol for testing
|
|
|
|
void SetupIsolateForWasmModule(Isolate* isolate);
|
2017-06-12 11:13:15 +00:00
|
|
|
|
2016-09-12 12:26:37 +00:00
|
|
|
} // namespace testing
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_WASM_MODULE_RUNNER_H_
|