From 22003d8d4ab317a5da01edae63fadebc2e81bbd6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 26 Jan 2022 12:59:48 -0800 Subject: [NFC] Templatize/generalize RuntimeExpressionRunner (#4477) Add a base class for it, that is templated and can be extended in general ways, and make callFunction templated on the runner to use as well. This allows the interpreter's behavior to be customized in a way that we couldn't so far. wasm-ctor-eval wants to use a special Runner when it evals a function, so that it can track certain operations, which this will enable. --- src/wasm-interpreter.h | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 64dc824f6..ce89f045e 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -2684,8 +2684,8 @@ public: // Executes expressions with concrete runtime info, the function and module at // runtime - class RuntimeExpressionRunner - : public ExpressionRunner { + template + class RuntimeExpressionRunnerBase : public ExpressionRunner { ModuleInstanceBase& instance; FunctionScope& scope; // Stack of @@ -2718,10 +2718,10 @@ public: } public: - RuntimeExpressionRunner(ModuleInstanceBase& instance, - FunctionScope& scope, - Index maxDepth) - : ExpressionRunner(&instance.wasm, maxDepth), + RuntimeExpressionRunnerBase(ModuleInstanceBase& instance, + FunctionScope& scope, + Index maxDepth) + : ExpressionRunner(&instance.wasm, maxDepth), instance(instance), scope(scope) {} Flow visitCall(Call* curr) { @@ -3550,17 +3550,29 @@ public: } }; + class RuntimeExpressionRunner + : public RuntimeExpressionRunnerBase { + public: + RuntimeExpressionRunner(ModuleInstanceBase& instance, + FunctionScope& scope, + Index maxDepth) + : RuntimeExpressionRunnerBase( + instance, scope, maxDepth) {} + }; + // Call a function, starting an invocation. + template Literals callFunction(Name name, const Literals& arguments) { // if the last call ended in a jump up the stack, it might have left stuff // for us to clean up here callDepth = 0; functionStack.clear(); - return callFunctionInternal(name, arguments); + return callFunctionInternal(name, arguments); } // Internal function call. Must be public so that callTable implementations // can use it (refactor?) + template Literals callFunctionInternal(Name name, const Literals& arguments) { if (callDepth > maxDepth) { externalInterface->trap("stack limit"); @@ -3581,8 +3593,7 @@ public: } #endif - Flow flow = - RuntimeExpressionRunner(*this, scope, maxDepth).visit(function->body); + Flow flow = Runner(*this, scope, maxDepth).visit(function->body); // cannot still be breaking, it means we missed our stop assert(!flow.breaking() || flow.breakTo == RETURN_FLOW); auto type = flow.getType(); -- cgit v1.2.3