summaryrefslogtreecommitdiff
path: root/src/wasm/wasm.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-05-31 20:02:37 -0700
committerGitHub <noreply@github.com>2019-05-31 20:02:37 -0700
commitfe99e3458f11d1a01fa3ad5b68883dbcba3903af (patch)
tree6f5eda61c7c7cba9c3b16be5e361cdc148d8b315 /src/wasm/wasm.cpp
parent7306f60a4474ca1fa948bddee5c068e7c2f635f6 (diff)
downloadbinaryen-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/wasm/wasm.cpp')
-rw-r--r--src/wasm/wasm.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index c32ead836..c543686ed 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -82,6 +82,8 @@ Name SPECTEST("spectest");
Name PRINT("print");
Name EXIT("exit");
Name SHARED("shared");
+Name EVENT("event");
+Name ATTR("attr");
// Expressions
@@ -908,11 +910,20 @@ Function* Module::getFunction(Name name) {
Global* Module::getGlobal(Name name) {
auto iter = globalsMap.find(name);
if (iter == globalsMap.end()) {
+ assert(false);
Fatal() << "Module::getGlobal: " << name << " does not exist";
}
return iter->second;
}
+Event* Module::getEvent(Name name) {
+ auto iter = eventsMap.find(name);
+ if (iter == eventsMap.end()) {
+ Fatal() << "Module::getEvent: " << name << " does not exist";
+ }
+ return iter->second;
+}
+
FunctionType* Module::getFunctionTypeOrNull(Name name) {
auto iter = functionTypesMap.find(name);
if (iter == functionTypesMap.end()) {
@@ -945,6 +956,14 @@ Global* Module::getGlobalOrNull(Name name) {
return iter->second;
}
+Event* Module::getEventOrNull(Name name) {
+ auto iter = eventsMap.find(name);
+ if (iter == eventsMap.end()) {
+ return nullptr;
+ }
+ return iter->second;
+}
+
FunctionType* Module::addFunctionType(std::unique_ptr<FunctionType> curr) {
if (!curr->name.is()) {
Fatal() << "Module::addFunctionType: empty name";
@@ -1009,6 +1028,20 @@ Global* Module::addGlobal(Global* curr) {
return curr;
}
+Event* Module::addEvent(Event* curr) {
+ if (!curr->name.is()) {
+ Fatal() << "Module::addEvent: empty name";
+ }
+ if (getEventOrNull(curr->name)) {
+ Fatal() << "Module::addEvent: " << curr->name << " already exists";
+ }
+
+ events.emplace_back(curr);
+
+ eventsMap[curr->name] = curr;
+ return curr;
+}
+
void Module::addStart(const Name& s) { start = s; }
void Module::removeFunctionType(Name name) {
@@ -1051,6 +1084,16 @@ void Module::removeGlobal(Name name) {
globalsMap.erase(name);
}
+void Module::removeEvent(Name name) {
+ for (size_t i = 0; i < events.size(); i++) {
+ if (events[i]->name == name) {
+ events.erase(events.begin() + i);
+ break;
+ }
+ }
+ eventsMap.erase(name);
+}
+
// TODO: remove* for other elements
void Module::updateMaps() {
@@ -1070,6 +1113,10 @@ void Module::updateMaps() {
for (auto& curr : globals) {
globalsMap[curr->name] = curr.get();
}
+ eventsMap.clear();
+ for (auto& curr : events) {
+ eventsMap[curr->name] = curr.get();
+ }
}
void Module::clearDebugInfo() { debugInfoFileNames.clear(); }