summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-interpreter.h25
-rw-r--r--src/wasm-js.cpp6
-rw-r--r--src/wasm-shell.cpp2
3 files changed, 16 insertions, 17 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 5279e8a35..25bdfd7d6 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -47,14 +47,21 @@ public:
virtual void trap() = 0;
};
+ Module& wasm;
+
ModuleInstance(Module& wasm, ExternalInterface* externalInterface) : wasm(wasm), externalInterface(externalInterface) {
- for (auto function : wasm.functions) {
- functions[function->name] = function;
- }
memorySize = wasm.memory.initial;
externalInterface->init(wasm);
}
+ Literal callExport(IString name, LiteralList& arguments) {
+ Export *export_ = wasm.exportsMap[name];
+ if (!export_) externalInterface->trap();
+ return callFunction(export_->value, arguments);
+ }
+
+private:
+
#ifdef WASM_INTERPRETER_DEBUG
int indent = 0;
#endif
@@ -665,7 +672,8 @@ public:
}
};
- Function *function = functions[name];
+ Function *function = wasm.functionsMap[name];
+ assert(function);
FunctionScope scope(function, arguments);
Literal ret = ExpressionRunner(*this, scope).visit(function->body).value;
@@ -674,13 +682,6 @@ public:
return ret;
}
- // Convenience method, for the case where you have no arguments.
- Literal callFunction(IString name) {
- LiteralList empty;
- return callFunction(name, empty);
- }
-
- std::map<IString, Function*> functions;
size_t memorySize;
template<class LS>
@@ -694,8 +695,6 @@ public:
return addr;
}
-private:
- Module& wasm;
ExternalInterface* externalInterface;
};
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index ddb31b33d..b26a5b4d6 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -210,8 +210,8 @@ extern "C" double EMSCRIPTEN_KEEPALIVE call_from_js(const char *target) {
std::cout << "call_from_js " << target << '\n';
#endif
IString name(target);
- assert(instance->functions.find(name) != instance->functions.end());
- Function *function = instance->functions[name];
+ Function *function = instance->wasm.functionsMap[name];
+ assert(function);
size_t seen = EM_ASM_INT_V({ return Module['tempArguments'].length });
size_t actual = function->params.size();
ModuleInstance::LiteralList arguments;
@@ -228,7 +228,7 @@ extern "C" double EMSCRIPTEN_KEEPALIVE call_from_js(const char *target) {
abort();
}
}
- Literal ret = instance->callFunction(name, arguments);
+ Literal ret = instance->callExport(name, arguments);
#ifdef WASM_JS_DEBUG
std::cout << "call_from_js returning " << ret << '\n';
#endif
diff --git a/src/wasm-shell.cpp b/src/wasm-shell.cpp
index 5f9fafd8f..8577b827e 100644
--- a/src/wasm-shell.cpp
+++ b/src/wasm-shell.cpp
@@ -133,7 +133,7 @@ struct Invocation {
}
Literal invoke() {
- return instance->callFunction(name, arguments);
+ return instance->callExport(name, arguments);
}
};