diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-06 10:24:13 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-06 10:24:13 -0800 |
commit | 40a7faed41cfb05d7d877878e14a553457e284b1 (patch) | |
tree | ad66dc63a5ddd860ab4867554228e0e2d5c8ff37 /src/wasm-interpreter.h | |
parent | d1d4442df4388bdcfd283a2cfb789ddce4834ef8 (diff) | |
download | binaryen-40a7faed41cfb05d7d877878e14a553457e284b1.tar.gz binaryen-40a7faed41cfb05d7d877878e14a553457e284b1.tar.bz2 binaryen-40a7faed41cfb05d7d877878e14a553457e284b1.zip |
call exports, not functions, from the outside
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 25 |
1 files changed, 12 insertions, 13 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; }; |