summaryrefslogtreecommitdiff
path: root/src/shell-interface.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shell-interface.h')
-rw-r--r--src/shell-interface.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h
index 5b01b4be6..abfd4ac18 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -26,6 +26,7 @@
#include "support/name.h"
#include "wasm.h"
#include "wasm-interpreter.h"
+#include "ir/module-utils.h"
namespace wasm {
@@ -118,24 +119,25 @@ struct ShellExternalInterface final : ModuleInstance::ExternalInterface {
void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override {
// add spectest globals
- for (auto& import : wasm.imports) {
- if (import->kind == ExternalKind::Global && import->module == SPECTEST && import->base == GLOBAL) {
- switch (import->globalType) {
+ ModuleUtils::iterImportedGlobals(wasm, [&](Global* import) {
+ if (import->module == SPECTEST && import->base == GLOBAL) {
+ switch (import->type) {
case i32: globals[import->name] = Literal(int32_t(666)); break;
case i64: globals[import->name] = Literal(int64_t(666)); break;
case f32: globals[import->name] = Literal(float(666.6)); break;
case f64: globals[import->name] = Literal(double(666.6)); break;
default: WASM_UNREACHABLE();
}
- } else if (import->kind == ExternalKind::Memory && import->module == SPECTEST && import->base == MEMORY) {
- // imported memory has initial 1 and max 2
- wasm.memory.initial = 1;
- wasm.memory.max = 2;
}
+ });
+ if (wasm.memory.imported() && wasm.memory.module == SPECTEST && wasm.memory.base == MEMORY) {
+ // imported memory has initial 1 and max 2
+ wasm.memory.initial = 1;
+ wasm.memory.max = 2;
}
}
- Literal callImport(Import *import, LiteralList& arguments) override {
+ Literal callImport(Function* import, LiteralList& arguments) override {
if (import->module == SPECTEST && import->base == PRINT) {
for (auto argument : arguments) {
std::cout << '(' << argument << ')' << '\n';
@@ -163,7 +165,11 @@ struct ShellExternalInterface final : ModuleInstance::ExternalInterface {
if (func->result != result) {
trap("callIndirect: bad result type");
}
- return instance.callFunctionInternal(func->name, arguments);
+ if (func->imported()) {
+ return callImport(func, arguments);
+ } else {
+ return instance.callFunctionInternal(func->name, arguments);
+ }
}
int8_t load8s(Address addr) override { return memory.get<int8_t>(addr); }