diff options
author | Alon Zakai <azakai@google.com> | 2022-01-28 12:57:32 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 12:57:32 -0800 |
commit | f2d53918155cfe6e7fc333be22f25ae3776b1438 (patch) | |
tree | e7b10cd0def3481928702e83e0f6813a29796fc3 /src/binaryen-c.cpp | |
parent | 43844d4bf34646aab0a1d575ad815a42e37dfc08 (diff) | |
download | binaryen-f2d53918155cfe6e7fc333be22f25ae3776b1438.tar.gz binaryen-f2d53918155cfe6e7fc333be22f25ae3776b1438.tar.bz2 binaryen-f2d53918155cfe6e7fc333be22f25ae3776b1438.zip |
[NFC] Refactor ModuleInstanceBase+RuntimeExpressionRunner into a single class (#4479)
As recently discussed, the interpreter code is way too complex. Trying to add
ctor-eval stuff I need, I got stuck and ended up spending some time to get rid
of some of the complexity.
We had a ModuleInstanceBase class which was basically an instance of a
module, that is, an execution of it. And internally we have RuntimeExpressionRunner
which is a runner that integrates with the ModuleInstanceBase - basically, it uses
the runtime info to execute code. For example, the MIB has globals info, and the
RER would read it from there.
But these two classes are really just one functionality - an execution of a module.
We get rid of some complexity by removing the separation between them, ending
up with a class that can run a module.
One set of problems we avoid is that we can now extend the single class in a
simple way. Before, we would need to extend both - and inform each other of
those changes. That gets "fun" with CRTP which we use everywhere. In other
words, each of the two classes depended on the other / would need to be
templated on the other. Specifically, MIB.callFunction would need to be given
the RER to run with, and so that would need to be templated on it. This ends up
leading to a bunch more templating all around - all complexity that we just
don't need. See the simplification to the wasm-ctor-eval for some of that (and
even worse complexity would have been needed without this PR in the next
steps for that tool to eval GC stuff).
The final single class is now called ModuleRunner.
Also fixes a pre-existing issue uncovered by this PR. We had the delegate
target on the runner, but it should be tied to a function scope. This happened
to not be a problem if one always created a new runner for each scope, but
this PR makes the runner longer-lived, so the stale data ended up mattering.
The PR moves that data to the proper place.
Note: Diff without whitespace is far, far smaller.
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r-- | src/binaryen-c.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index be538ef86..df868dc62 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -4124,7 +4124,7 @@ BinaryenModuleRef BinaryenModuleRead(char* input, size_t inputSize) { void BinaryenModuleInterpret(BinaryenModuleRef module) { ShellExternalInterface interface; - ModuleInstance instance(*(Module*)module, &interface, {}); + ModuleRunner instance(*(Module*)module, &interface, {}); } BinaryenIndex BinaryenModuleAddDebugInfoFileName(BinaryenModuleRef module, |