Skip to content

Commit 3ca38d8

Browse files
authored
[NFC] Add an explicit ModuleRunner.start() (#7463)
Previously the constructor ran the start method and other initialization. Doing that in an explicit function that the user calls makes it possible to do things in the middle. The specific thing I would like to do in the middle is have a function to change the interpreter instance's mode to "reject as nonconstant relaxed SIMD", but I've wanted this in the past too, and worked around it - seems best to just fix it. Adding more flags to the constructor is another option, but there are already several, and more in the parent classes, and several levels of inheritance through which all such options must be forwarded, which is annoying.
1 parent 69e665e commit 3ca38d8

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

src/binaryen-c.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5651,6 +5651,7 @@ BinaryenModuleRef BinaryenModuleRead(char* input, size_t inputSize) {
56515651
void BinaryenModuleInterpret(BinaryenModuleRef module) {
56525652
ShellExternalInterface interface;
56535653
ModuleRunner instance(*(Module*)module, &interface, {});
5654+
instance.instantiate();
56545655
}
56555656

56565657
BinaryenIndex BinaryenModuleAddDebugInfoFileName(BinaryenModuleRef module,

src/tools/execution-results.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ struct ExecutionResults {
271271
LoggingExternalInterface interface(loggings, wasm);
272272
try {
273273
ModuleRunner instance(wasm, &interface);
274+
instance.instantiate();
274275
interface.setModuleRunner(&instance);
275276
// execute all exported methods (that are therefore preserved through
276277
// opts)
@@ -430,6 +431,7 @@ struct ExecutionResults {
430431
LoggingExternalInterface interface(loggings, wasm);
431432
try {
432433
ModuleRunner instance(wasm, &interface);
434+
instance.instantiate();
433435
interface.setModuleRunner(&instance);
434436
return run(func, wasm, instance);
435437
} catch (const TrapException&) {

src/tools/wasm-ctor-eval.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ void evalCtors(Module& wasm,
12871287
try {
12881288
// create an instance for evalling
12891289
EvallingModuleRunner instance(wasm, &interface, linkedInstances);
1290+
instance.instantiate();
12901291
interface.instanceInitialized = true;
12911292
// go one by one, in order, until we fail
12921293
// TODO: if we knew priorities, we could reorder?

src/tools/wasm-shell.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct Shell {
139139
std::make_shared<ShellExternalInterface>(linkedInstances);
140140
auto instance =
141141
std::make_shared<ModuleRunner>(wasm, interface.get(), linkedInstances);
142+
instance->instantiate();
142143
return {{std::move(interface), std::move(instance)}};
143144
} catch (...) {
144145
return Err{"failed to instantiate module"};

src/wasm-interpreter.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,12 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
29002900
ExternalInterface* externalInterface,
29012901
std::map<Name, std::shared_ptr<SubType>> linkedInstances_ = {})
29022902
: ExpressionRunner<SubType>(&wasm), wasm(wasm),
2903-
externalInterface(externalInterface), linkedInstances(linkedInstances_) {
2903+
externalInterface(externalInterface), linkedInstances(linkedInstances_) {}
2904+
2905+
// Start up this instance. This must be called before doing anything else.
2906+
// (This is separate from the constructor so that it does not occur
2907+
// synchronously, which makes some code patterns harder to write.)
2908+
void instantiate() {
29042909
// import globals from the outside
29052910
externalInterface->importGlobals(globals, wasm);
29062911
// generate internal (non-imported) globals

0 commit comments

Comments
 (0)