diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2019-11-25 15:46:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-25 15:46:56 -0800 |
commit | 8a70121a421204e05d020c67294e7e517c2d15d2 (patch) | |
tree | da493f5ee5c8a3dfd18fba7518e05d25b1a71fba /src/ir/module-utils.h | |
parent | d90583cf509c3f21b3b5136d3872b097c5f2800c (diff) | |
download | binaryen-8a70121a421204e05d020c67294e7e517c2d15d2.tar.gz binaryen-8a70121a421204e05d020c67294e7e517c2d15d2.tar.bz2 binaryen-8a70121a421204e05d020c67294e7e517c2d15d2.zip |
Remove FunctionType from Event (#2466)
This is the start of a larger refactoring to remove FunctionType entirely and
store types and signatures directly on the entities that use them. This PR
updates BrOnExn and Events to remove their use of FunctionType and makes the
BinaryWriter traverse the module and collect types rather than using the global
FunctionType list. While we are collecting types, we also sort them by frequency
as an optimization. Remaining uses of FunctionType in Function, CallIndirect,
and parsing will be removed in a future PR.
Diffstat (limited to 'src/ir/module-utils.h')
-rw-r--r-- | src/ir/module-utils.h | 61 |
1 files changed, 17 insertions, 44 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index 52765035c..0fd478551 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -38,51 +38,25 @@ struct BinaryIndexes { std::unordered_map<Name, Index> eventIndexes; BinaryIndexes(Module& wasm) { - auto addGlobal = [&](Global* curr) { - auto index = globalIndexes.size(); - globalIndexes[curr->name] = index; - }; - for (auto& curr : wasm.globals) { - if (curr->imported()) { - addGlobal(curr.get()); - } - } - for (auto& curr : wasm.globals) { - if (!curr->imported()) { - addGlobal(curr.get()); - } - } - assert(globalIndexes.size() == wasm.globals.size()); - auto addFunction = [&](Function* curr) { - auto index = functionIndexes.size(); - functionIndexes[curr->name] = index; - }; - for (auto& curr : wasm.functions) { - if (curr->imported()) { - addFunction(curr.get()); + auto addIndexes = [&](auto& source, auto& indexes) { + auto addIndex = [&](auto* curr) { + auto index = indexes.size(); + indexes[curr->name] = index; + }; + for (auto& curr : source) { + if (curr->imported()) { + addIndex(curr.get()); + } } - } - for (auto& curr : wasm.functions) { - if (!curr->imported()) { - addFunction(curr.get()); + for (auto& curr : source) { + if (!curr->imported()) { + addIndex(curr.get()); + } } - } - assert(functionIndexes.size() == wasm.functions.size()); - auto addEvent = [&](Event* curr) { - auto index = eventIndexes.size(); - eventIndexes[curr->name] = index; }; - for (auto& curr : wasm.events) { - if (curr->imported()) { - addEvent(curr.get()); - } - } - for (auto& curr : wasm.events) { - if (!curr->imported()) { - addEvent(curr.get()); - } - } - assert(eventIndexes.size() == wasm.events.size()); + addIndexes(wasm.functions, functionIndexes); + addIndexes(wasm.globals, globalIndexes); + addIndexes(wasm.events, eventIndexes); } }; @@ -126,8 +100,7 @@ inline Event* copyEvent(Event* event, Module& out) { auto* ret = new Event(); ret->name = event->name; ret->attribute = event->attribute; - ret->type = event->type; - ret->params = event->params; + ret->sig = event->sig; out.addEvent(ret); return ret; } |