From a2741b360b444a26cd87327a3d60a601bb33119f Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Tue, 23 Jul 2019 17:12:22 -0700 Subject: Finalize tail call support (#2246) Adds tail call support to fuzzer and makes small changes to handle return calls in multiple utilities and passes. Makes larger changes to DAE and inlining passes to properly handle tail calls. --- src/wasm-interpreter.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 42e904fd3..f683f9b38 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1435,6 +1435,15 @@ private: #ifdef WASM_INTERPRETER_DEBUG std::cout << "(returned to " << scope.function->name << ")\n"; #endif + // TODO: make this a proper tail call (return first) + if (curr->isReturn) { + Const c; + c.value = ret.value; + c.finalize(); + Return return_; + return_.value = &c; + return this->visit(&return_); + } return ret; } Flow visitCallIndirect(CallIndirect* curr) { @@ -1449,8 +1458,19 @@ private: return target; } Index index = target.value.geti32(); - return instance.externalInterface->callTable( - index, arguments, curr->type, *instance.self()); + Type type = curr->isReturn ? scope.function->result : curr->type; + Flow ret = instance.externalInterface->callTable( + index, arguments, type, *instance.self()); + // TODO: make this a proper tail call (return first) + if (curr->isReturn) { + Const c; + c.value = ret.value; + c.finalize(); + Return return_; + return_.value = &c; + return this->visit(&return_); + } + return ret; } Flow visitLocalGet(LocalGet* curr) { -- cgit v1.2.3