diff options
author | Alon Zakai <azakai@google.com> | 2022-01-26 12:59:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-26 12:59:48 -0800 |
commit | 22003d8d4ab317a5da01edae63fadebc2e81bbd6 (patch) | |
tree | 13abfb13dc0594eb1e93ba581e0b094f165a9e15 | |
parent | 97bb0bdacbb8ccd59aca116c66f0f43f322aebaa (diff) | |
download | binaryen-22003d8d4ab317a5da01edae63fadebc2e81bbd6.tar.gz binaryen-22003d8d4ab317a5da01edae63fadebc2e81bbd6.tar.bz2 binaryen-22003d8d4ab317a5da01edae63fadebc2e81bbd6.zip |
[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.
-rw-r--r-- | src/wasm-interpreter.h | 29 |
1 files changed, 20 insertions, 9 deletions
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<RuntimeExpressionRunner> { + template<typename RERSubType> + class RuntimeExpressionRunnerBase : public ExpressionRunner<RERSubType> { ModuleInstanceBase& instance; FunctionScope& scope; // Stack of <caught exception, caught catch's try label> @@ -2718,10 +2718,10 @@ public: } public: - RuntimeExpressionRunner(ModuleInstanceBase& instance, - FunctionScope& scope, - Index maxDepth) - : ExpressionRunner<RuntimeExpressionRunner>(&instance.wasm, maxDepth), + RuntimeExpressionRunnerBase(ModuleInstanceBase& instance, + FunctionScope& scope, + Index maxDepth) + : ExpressionRunner<RERSubType>(&instance.wasm, maxDepth), instance(instance), scope(scope) {} Flow visitCall(Call* curr) { @@ -3550,17 +3550,29 @@ public: } }; + class RuntimeExpressionRunner + : public RuntimeExpressionRunnerBase<RuntimeExpressionRunner> { + public: + RuntimeExpressionRunner(ModuleInstanceBase& instance, + FunctionScope& scope, + Index maxDepth) + : RuntimeExpressionRunnerBase<RuntimeExpressionRunner>( + instance, scope, maxDepth) {} + }; + // Call a function, starting an invocation. + template<typename Runner = RuntimeExpressionRunner> 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<Runner>(name, arguments); } // Internal function call. Must be public so that callTable implementations // can use it (refactor?) + template<typename Runner = RuntimeExpressionRunner> 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(); |