diff options
author | Alon Zakai <azakai@google.com> | 2024-08-16 12:53:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 12:53:52 -0700 |
commit | 958ff4115e542ef1d0ae712f4961e342386efe54 (patch) | |
tree | 7805d641d9a73b32650a053931c4bd8c3814d804 /src/tools | |
parent | 7209629bec3961fcc12b150ba6df546d3997b6c2 (diff) | |
download | binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.tar.gz binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.tar.bz2 binaryen-958ff4115e542ef1d0ae712f4961e342386efe54.zip |
Implement table.init (#6827)
Also use TableInit in the interpreter to initialize module's table
state, which will now handle traps properly, fixing #6431
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 22e666a52..6c72f1c73 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -86,13 +86,6 @@ public: return ModuleRunnerBase<EvallingModuleRunner>::visitGlobalGet(curr); } - - Flow visitTableSet(TableSet* curr) { - // TODO: Full dynamic table support. For now we stop evalling when we see a - // table.set. (To support this we need to track sets and add code to - // serialize them.) - throw FailToEvalException("table.set: TODO"); - } }; // Build an artificial `env` module based on a module's imports, so that the @@ -174,6 +167,9 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface { // not yet been re-added are a blind spot for it). std::unordered_set<Name> usedGlobalNames; + // Set to true after we create the instance. + bool instanceInitialized = false; + CtorEvalExternalInterface( std::map<Name, std::shared_ptr<EvallingModuleRunner>> linkedInstances_ = {}) { @@ -363,7 +359,8 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface { } Index tableSize(Name tableName) override { - throw FailToEvalException("table size"); + // See callTable above, we assume the table is not modified FIXME + return wasm->getTableOrNull(tableName)->initial; } Literal tableLoad(Name tableName, Index index) override { @@ -371,7 +368,15 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface { } // called during initialization - void tableStore(Name tableName, Index index, const Literal& value) override {} + void tableStore(Name tableName, Index index, const Literal& value) override { + // We allow stores to the table during initialization, but not after, as we + // assume the table does not change at runtime. + // TODO: Allow table changes by updating the table later like we do with the + // memory, by tracking and serializing them. + if (instanceInitialized) { + throw FailToEvalException("tableStore after init: TODO"); + } + } int8_t load8s(Address addr, Name memoryName) override { return doLoad<int8_t>(addr, memoryName); @@ -1294,6 +1299,7 @@ void evalCtors(Module& wasm, try { // create an instance for evalling EvallingModuleRunner instance(wasm, &interface, linkedInstances); + interface.instanceInitialized = true; // go one by one, in order, until we fail // TODO: if we knew priorities, we could reorder? for (auto& ctor : ctors) { |