diff options
Diffstat (limited to 'src/shell-interface.h')
-rw-r--r-- | src/shell-interface.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h index ee9ff166a..b9a90131b 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -111,7 +111,24 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { } } - void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override {} + void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override { + // add spectest globals + for (auto& import : wasm.imports) { + if (import->kind == Import::Global && import->module == SPECTEST && import->base == GLOBAL) { + switch (import->globalType) { + 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 == Import::Memory && import->module == SPECTEST && import->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 { if (import->module == SPECTEST && import->base == PRINT) { @@ -130,7 +147,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { Literal callTable(Index index, LiteralList& arguments, WasmType result, ModuleInstance& instance) override { if (index >= table.size()) trap("callTable overflow"); - auto* func = instance.wasm.getFunction(table[index]); + auto* func = instance.wasm.checkFunction(table[index]); + if (!func) trap("uninitialized table element"); 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) { |