diff options
Diffstat (limited to 'src/shell-interface.h')
-rw-r--r-- | src/shell-interface.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h index 55f9b2a0b..f332307ad 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -86,6 +86,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { } } memory; + std::vector<Name> table; + ShellExternalInterface() : memory() {} void init(Module& wasm) override { @@ -98,6 +100,15 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { memory.set(offset + i, segment.data[i]); } } + + table.resize(wasm.table.initial); + for (auto& segment : wasm.table.segments) { + Address offset = ConstantExpressionRunner().visit(segment.offset).value.geti32(); + assert(offset + segment.data.size() <= wasm.table.initial); + for (size_t i = 0; i != segment.data.size(); ++i) { + table[offset + i] = segment.data[i]; + } + } } Literal callImport(Import *import, LiteralList& arguments) override { @@ -115,6 +126,19 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { abort(); } + Literal callTable(Index index, Name type, LiteralList& arguments, ModuleInstance& instance) override { + if (index >= table.size()) trap("callTable overflow"); + auto* func = instance.wasm.getFunction(table[index]); + if (func->type.is() && func->type != type) 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(func->name, arguments); + } + Literal load(Load* load, Address addr) override { switch (load->type) { case i32: { |