From 15903fda75b5392df886b512bae8b8d74fafc61f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 11 Nov 2015 13:59:38 -0800 Subject: don't allow direct access to the vectors on the Module object --- src/asm2wasm.h | 4 ++-- src/wasm-js.cpp | 3 ++- src/wasm-s-parser.h | 6 ++++-- src/wasm.h | 6 +++--- 4 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 954bcfb8b..61c67c5d8 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -1101,8 +1101,8 @@ void Asm2WasmBuilder::optimize() { }; BlockBreakOptimizer blockBreakOptimizer; - for (auto function : wasm.functions) { - blockBreakOptimizer.startWalk(function); + for (auto pair : wasm.functionsMap) { + blockBreakOptimizer.startWalk(pair.second); } } diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp index c522a71f6..868c8e6ac 100644 --- a/src/wasm-js.cpp +++ b/src/wasm-js.cpp @@ -75,7 +75,8 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm(char *input) { EM_ASM({ Module['asmExports'] = {}; }); - for (auto& curr : module->exports) { + for (auto& pair : module->exportsMap) { + auto& curr = pair.second; EM_ASM_({ var name = Pointer_stringify($0); Module['asmExports'][name] = function() { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index a33866af9..3fd977f09 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -235,10 +235,11 @@ class SExpressionWasmBuilder { Module& wasm; MixedArena allocator; std::function onError; + int functionCounter; public: // Assumes control of and modifies the input. - SExpressionWasmBuilder(Module& wasm, Element& module, std::function onError) : wasm(wasm), onError(onError) { + SExpressionWasmBuilder(Module& wasm, Element& module, std::function onError) : wasm(wasm), onError(onError), functionCounter(0) { assert(module[0]->str() == MODULE); for (unsigned i = 1; i < module.size(); i++) { parseModuleElement(*module[i]); @@ -282,8 +283,9 @@ private: i++; } else { // unnamed, use an index - func->name = IString(std::to_string(wasm.functions.size()).c_str(), false); + func->name = IString(std::to_string(functionCounter).c_str(), false); } + functionCounter++; func->body = nullptr; localIndex = 0; otherIndex = 0; diff --git a/src/wasm.h b/src/wasm.h index 63b861174..9dc140efe 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -924,20 +924,20 @@ public: }; class Module { -public: - // wasm contents + // wasm contents (don't access these from outside; use add*() and the *Map objects) std::vector functionTypes; std::vector imports; std::vector exports; - Table table; std::vector functions; +public: // utility maps std::map functionTypesMap; std::map importsMap; std::map exportsMap; std::map functionsMap; + Table table; Memory memory; Module() : functionTypeIndex(0), importIndex(0), exportIndex(0), functionIndex(0) {} -- cgit v1.2.3