summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h4
-rw-r--r--src/wasm-js.cpp3
-rw-r--r--src/wasm-s-parser.h6
-rw-r--r--src/wasm.h6
4 files changed, 11 insertions, 8 deletions
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<void ()> onError;
+ int functionCounter;
public:
// Assumes control of and modifies the input.
- SExpressionWasmBuilder(Module& wasm, Element& module, std::function<void ()> onError) : wasm(wasm), onError(onError) {
+ SExpressionWasmBuilder(Module& wasm, Element& module, std::function<void ()> 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<FunctionType*> functionTypes;
std::vector<Import*> imports;
std::vector<Export*> exports;
- Table table;
std::vector<Function*> functions;
+public:
// utility maps
std::map<Name, FunctionType*> functionTypesMap;
std::map<Name, Import*> importsMap;
std::map<Name, Export*> exportsMap;
std::map<Name, Function*> functionsMap;
+ Table table;
Memory memory;
Module() : functionTypeIndex(0), importIndex(0), exportIndex(0), functionIndex(0) {}