summaryrefslogtreecommitdiff
path: root/src/wasm/wasm.cpp
diff options
context:
space:
mode:
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(); }