diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-05-31 20:02:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-31 20:02:37 -0700 |
commit | fe99e3458f11d1a01fa3ad5b68883dbcba3903af (patch) | |
tree | 6f5eda61c7c7cba9c3b16be5e361cdc148d8b315 /src/ir/module-utils.h | |
parent | 7306f60a4474ca1fa948bddee5c068e7c2f635f6 (diff) | |
download | binaryen-fe99e3458f11d1a01fa3ad5b68883dbcba3903af.tar.gz binaryen-fe99e3458f11d1a01fa3ad5b68883dbcba3903af.tar.bz2 binaryen-fe99e3458f11d1a01fa3ad5b68883dbcba3903af.zip |
Add event section (#2151)
This adds support for the event and the event section, as specified in
https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model.
Wasm events are features that suspend the current execution and transfer
the control flow to a corresponding handler. Currently the only
supported event kind is exceptions.
For events, this includes support for
- Binary file reading/writing
- Wast file reading/writing
- Binaryen.js API
- Fuzzer
- Validation
- Metadce
- Passes: metrics, minify-imports-and-exports,
remove-unused-module-elements
Diffstat (limited to 'src/ir/module-utils.h')
-rw-r--r-- | src/ir/module-utils.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index 5569843fd..067f59416 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -34,6 +34,7 @@ namespace ModuleUtils { struct BinaryIndexes { std::unordered_map<Name, Index> functionIndexes; std::unordered_map<Name, Index> globalIndexes; + std::unordered_map<Name, Index> eventIndexes; BinaryIndexes(Module& wasm) { auto addGlobal = [&](Global* curr) { @@ -66,6 +67,21 @@ struct BinaryIndexes { } } 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()); } }; @@ -105,6 +121,16 @@ inline Global* copyGlobal(Global* global, Module& out) { return ret; } +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; + out.addEvent(ret); + return ret; +} + inline void copyModule(Module& in, Module& out) { // we use names throughout, not raw points, so simple copying is fine // for everything *but* expressions @@ -120,6 +146,9 @@ inline void copyModule(Module& in, Module& out) { for (auto& curr : in.globals) { copyGlobal(curr.get(), out); } + for (auto& curr : in.events) { + copyEvent(curr.get(), out); + } out.table = in.table; for (auto& segment : out.table.segments) { segment.offset = ExpressionManipulator::copy(segment.offset, out); @@ -243,6 +272,22 @@ template<typename T> inline void iterDefinedFunctions(Module& wasm, T visitor) { } } +template<typename T> inline void iterImportedEvents(Module& wasm, T visitor) { + for (auto& import : wasm.events) { + if (import->imported()) { + visitor(import.get()); + } + } +} + +template<typename T> inline void iterDefinedEvents(Module& wasm, T visitor) { + for (auto& import : wasm.events) { + if (!import->imported()) { + visitor(import.get()); + } + } +} + } // namespace ModuleUtils } // namespace wasm |