Commit 0a4c5c44 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Cleanup wasm interpreter

This is a cleanup in preparation to implement calling imported
functions via the wasm interpreter.
For imported functions, we do not create entries in the
interpreter_code_ vector any more.

I also simplified the interface and removed unused or redundant return
values. More things are now DCHECKed instead of bailing out.

Also, we previously had two PushFrame methods: One is supposed to
initialize the interpreter from external code (i.e. adds the first
frame to the stack), the other one is used to push new frames on the
frame stack for called functions. This CL renames the first to
InitFrame, and makes it use the second one. The other remaining user is
the DoCall method.

R=titzer@chromium.org
BUG=v8:5822

Change-Id: Id09ff1e3256428fbd8c955e4664507a0c3167e53
Reviewed-on: https://chromium-review.googlesource.com/453482
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43793}
parent 38c5e82f
...@@ -109,7 +109,7 @@ class InterpreterHandle { ...@@ -109,7 +109,7 @@ class InterpreterHandle {
DCHECK(thread->state() == WasmInterpreter::STOPPED || DCHECK(thread->state() == WasmInterpreter::STOPPED ||
thread->state() == WasmInterpreter::FINISHED); thread->state() == WasmInterpreter::FINISHED);
thread->Reset(); thread->Reset();
thread->PushFrame(&module()->functions[func_index], wasm_args.start()); thread->InitFrame(&module()->functions[func_index], wasm_args.start());
bool finished = false; bool finished = false;
while (!finished) { while (!finished) {
// TODO(clemensh): Add occasional StackChecks. // TODO(clemensh): Add occasional StackChecks.
......
This diff is collapsed.
...@@ -136,7 +136,7 @@ class V8_EXPORT_PRIVATE WasmInterpreter { ...@@ -136,7 +136,7 @@ class V8_EXPORT_PRIVATE WasmInterpreter {
public: public:
// Execution control. // Execution control.
State state(); State state();
void PushFrame(const WasmFunction* function, WasmVal* args); void InitFrame(const WasmFunction* function, WasmVal* args);
State Run(); State Run();
State Step(); State Step();
void Pause(); void Pause();
...@@ -201,11 +201,11 @@ class V8_EXPORT_PRIVATE WasmInterpreter { ...@@ -201,11 +201,11 @@ class V8_EXPORT_PRIVATE WasmInterpreter {
//========================================================================== //==========================================================================
// Testing functionality. // Testing functionality.
//========================================================================== //==========================================================================
// Manually adds a function to this interpreter, returning the index of the // Manually adds a function to this interpreter. The func_index of the
// function. // function must match the current number of functions.
int AddFunctionForTesting(const WasmFunction* function); void AddFunctionForTesting(const WasmFunction* function);
// Manually adds code to the interpreter for the given function. // Manually adds code to the interpreter for the given function.
bool SetFunctionCodeForTesting(const WasmFunction* function, void SetFunctionCodeForTesting(const WasmFunction* function,
const byte* start, const byte* end); const byte* start, const byte* end);
// Computes the control transfers for the given bytecode. Used internally in // Computes the control transfers for the given bytecode. Used internally in
......
...@@ -197,7 +197,7 @@ TEST(Breakpoint_I32Add) { ...@@ -197,7 +197,7 @@ TEST(Breakpoint_I32Add) {
for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) { for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) {
thread->Reset(); thread->Reset();
WasmVal args[] = {WasmVal(*a), WasmVal(b)}; WasmVal args[] = {WasmVal(*a), WasmVal(b)};
thread->PushFrame(r.function(), args); thread->InitFrame(r.function(), args);
for (int i = 0; i < kNumBreakpoints; i++) { for (int i = 0; i < kNumBreakpoints; i++) {
thread->Run(); // run to next breakpoint thread->Run(); // run to next breakpoint
...@@ -232,7 +232,7 @@ TEST(Step_I32Mul) { ...@@ -232,7 +232,7 @@ TEST(Step_I32Mul) {
for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) { for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) {
thread->Reset(); thread->Reset();
WasmVal args[] = {WasmVal(*a), WasmVal(b)}; WasmVal args[] = {WasmVal(*a), WasmVal(b)};
thread->PushFrame(r.function(), args); thread->InitFrame(r.function(), args);
// Run instructions one by one. // Run instructions one by one.
for (int i = 0; i < kTraceLength - 1; i++) { for (int i = 0; i < kTraceLength - 1; i++) {
...@@ -274,7 +274,7 @@ TEST(Breakpoint_I32And_disable) { ...@@ -274,7 +274,7 @@ TEST(Breakpoint_I32And_disable) {
do_break); do_break);
thread->Reset(); thread->Reset();
WasmVal args[] = {WasmVal(*a), WasmVal(b)}; WasmVal args[] = {WasmVal(*a), WasmVal(b)};
thread->PushFrame(r.function(), args); thread->InitFrame(r.function(), args);
if (do_break) { if (do_break) {
thread->Run(); // run to next breakpoint thread->Run(); // run to next breakpoint
......
...@@ -204,9 +204,7 @@ class TestingModule : public ModuleEnv { ...@@ -204,9 +204,7 @@ class TestingModule : public ModuleEnv {
} }
instance->function_code.push_back(code); instance->function_code.push_back(code);
if (interpreter_) { if (interpreter_) {
const WasmFunction* function = &module->functions.back(); interpreter_->AddFunctionForTesting(&module->functions.back());
int interpreter_index = interpreter_->AddFunctionForTesting(function);
CHECK_EQ(index, interpreter_index);
} }
DCHECK_LT(index, kMaxFunctions); // limited for testing. DCHECK_LT(index, kMaxFunctions); // limited for testing.
return index; return index;
...@@ -551,7 +549,7 @@ class WasmFunctionCompiler : private GraphAndBuilders { ...@@ -551,7 +549,7 @@ class WasmFunctionCompiler : private GraphAndBuilders {
if (interpreter_) { if (interpreter_) {
// Add the code to the interpreter. // Add the code to the interpreter.
CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end)); interpreter_->SetFunctionCodeForTesting(function_, start, end);
return; return;
} }
...@@ -799,7 +797,7 @@ class WasmRunner : public WasmRunnerBase { ...@@ -799,7 +797,7 @@ class WasmRunner : public WasmRunnerBase {
WasmInterpreter::Thread* thread = interpreter()->GetThread(0); WasmInterpreter::Thread* thread = interpreter()->GetThread(0);
thread->Reset(); thread->Reset();
std::array<WasmVal, sizeof...(p)> args{{WasmVal(p)...}}; std::array<WasmVal, sizeof...(p)> args{{WasmVal(p)...}};
thread->PushFrame(function(), args.data()); thread->InitFrame(function(), args.data());
if (thread->Run() == WasmInterpreter::FINISHED) { if (thread->Run() == WasmInterpreter::FINISHED) {
WasmVal val = thread->GetReturnValue(); WasmVal val = thread->GetReturnValue();
possible_nondeterminism_ |= thread->PossibleNondeterminism(); possible_nondeterminism_ |= thread->PossibleNondeterminism();
......
...@@ -143,7 +143,7 @@ int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower, ...@@ -143,7 +143,7 @@ int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower,
WasmInterpreter::Thread* thread = interpreter.GetThread(0); WasmInterpreter::Thread* thread = interpreter.GetThread(0);
thread->Reset(); thread->Reset();
thread->PushFrame(&(module->functions[function_index]), args); thread->InitFrame(&(module->functions[function_index]), args);
WasmInterpreter::State interpreter_result = thread->Run(); WasmInterpreter::State interpreter_result = thread->Run();
if (instance.mem_start) { if (instance.mem_start) {
free(instance.mem_start); free(instance.mem_start);
......
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