summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 0be36a677..f2deed039 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -533,6 +533,7 @@ public:
struct ExternalInterface {
virtual void init(Module& wasm) {}
virtual Literal callImport(Import* import, LiteralList& arguments) = 0;
+ virtual Literal callTable(Index index, Name type, LiteralList& arguments, ModuleInstance& instance) = 0;
virtual Literal load(Load* load, Address addr) = 0;
virtual void store(Store* store, Address addr, Literal value) = 0;
virtual void growMemory(Address oldSize, Address newSize) = 0;
@@ -591,8 +592,8 @@ private:
return callFunctionInternal(name, arguments);
}
-private:
- // Internal function call.
+public:
+ // Internal function call. Must be public so that callTable implementations can use it (refactor?)
Literal callFunctionInternal(IString name, LiteralList& arguments) {
class FunctionScope {
@@ -672,18 +673,8 @@ private:
LiteralList arguments;
Flow flow = generateArguments(curr->operands, arguments);
if (flow.breaking()) return flow;
- size_t index = target.value.geti32();
- if (index >= instance.wasm.table.names.size()) trap("callIndirect: overflow");
- Name name = instance.wasm.table.names[index];
- Function *func = instance.wasm.getFunction(name);
- if (func->type.is() && func->type != curr->fullType) trap("callIndirect: bad type");
- if (func->params.size() != arguments.size()) trap("callIndirect: bad # of arguments");
- for (size_t i = 0; i < func->params.size(); i++) {
- if (func->params[i] != arguments[i].type) {
- trap("callIndirect: bad argument type");
- }
- }
- return instance.callFunctionInternal(name, arguments);
+ Index index = target.value.geti32();
+ return instance.externalInterface->callTable(index, curr->fullType, arguments, instance);
}
Flow visitGetLocal(GetLocal *curr) {
@@ -802,6 +793,8 @@ private:
return ret;
}
+private:
+
Address memorySize; // in pages
template <class LS>