semi-working
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index ab10929..0237d63 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -84,17 +84,43 @@
global->base.toString());
}
- return ModuleRunnerBase<EvallingModuleRunner>::visitGlobalGet(curr);
+ return ModuleRunnerBase::visitGlobalGet(curr);
+ }
+
+ Flow visitLoad(Load* curr) {
+ auto* memory = wasm.getMemory(curr->memory);
+ if (memory->imported()) {
+ throw FailToEvalException("Can't load from imported memory");
+ }
+
+ return ModuleRunnerBase::visitLoad(curr);
+ }
+
+ Flow visitStore(Store* curr) {
+ auto* memory = wasm.getMemory(curr->memory);
+ if (memory->imported()) {
+ throw FailToEvalException("Can't store to imported memory");
+ }
+
+ return ModuleRunnerBase::visitStore(curr);
}
Flow visitTableGet(TableGet* curr) {
- // We support tableLoad, below, so that call_indirect works (it calls it
- // internally), but we want to disable table.get for now.
- throw FailToEvalException("TODO: table.get");
+ auto table = wasm.getTable(curr->table);
+ if (table->imported()) {
+ throw FailToEvalException("Can't get on imported table");
+ }
+
+ return ModuleRunnerBase::visitTableGet(curr);
}
- Flow visitTableSet(TableGet* curr) {
- throw FailToEvalException("TODO: table.set");
+ Flow visitTableSet(TableSet* curr) {
+ auto table = wasm.getTable(curr->table);
+ if (table->imported()) {
+ throw FailToEvalException("Can't set on imported table");
+ }
+
+ return ModuleRunnerBase::visitTableSet(curr);
}
bool allowContNew = true;
@@ -103,7 +129,7 @@
if (!allowContNew) {
throw FailToEvalException("cont.new disallowed");
}
- return ModuleRunnerBase<EvallingModuleRunner>::visitContNew(curr);
+ return ModuleRunnerBase::visitContNew(curr);
}
// This needs to be duplicated from ModuleRunner, unfortunately.
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 2a39335..2221a65 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -29,6 +29,7 @@
#define wasm_wasm_interpreter_h
#include <cmath>
+#include <iomanip>
#include <limits.h>
#include <sstream>
#include <variant>
@@ -3310,7 +3311,8 @@
it != linkedInstances.end()) {
importedInstance = it->second.get();
} else {
- WASM_UNREACHABLE("no imported module for getTableInstanceInfo");
+ Fatal() << "getTableInstanceInfo: no imported module providing "
+ << std::quoted(name.toString());
}
// auto& importedInstance = linkedInstances.at(table->module);
auto* tableExport = importedInstance->wasm.getExport(table->base);
@@ -3368,7 +3370,14 @@
MemoryInstanceInfo getMemoryInstanceInfo(Name name) {
auto* memory = wasm.getMemory(name);
if (memory->imported()) {
- auto& importedInstance = linkedInstances.at(memory->module);
+ SubType* importedInstance;
+ if (auto it = linkedInstances.find(memory->module);
+ it != linkedInstances.end()) {
+ importedInstance = it->second.get();
+ } else {
+ Fatal() << "getMemoryInstanceInfo: no imported module providing "
+ << std::quoted(name.toString());
+ }
auto* memoryExport = importedInstance->wasm.getExport(memory->base);
return importedInstance->getMemoryInstanceInfo(
*memoryExport->getInternalName());
diff --git a/test/ctor-eval/imports.wast b/test/ctor-eval/imports.wast
index fa5f7ba..0fcf5c2 100644
--- a/test/ctor-eval/imports.wast
+++ b/test/ctor-eval/imports.wast
@@ -1,14 +1,15 @@
(module
;; (import "import" "tag" (tag $tag))
;; (import "import" "func" (func $logi64 (param i64)))
- ;; (import "import" "global" (global $global i32))
+ (import "import" "global" (global $global i32))
;; (import "import" "table" (table $table 1 1 anyref))
(import "import" "memory" (memory $memory 1 1))
(global $non-imported-global (mut i32) (i32.const 5))
(func $foo (result i32)
(nop)
- (i32.store (i32.const 1) (i32.const 1))
+ ;; (i32.store (i32.const 1) (i32.const 1))
+;; (drop (i32.load $memory (i32.const 1)))
(drop (global.get $non-imported-global))
(global.set $non-imported-global (i32.const 2))
(i32.const 1)