summaryrefslogtreecommitdiff
path: root/src/ir
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir')
-rw-r--r--src/ir/ReFinalize.cpp1
-rw-r--r--src/ir/import-utils.h24
-rw-r--r--src/ir/module-utils.h45
-rw-r--r--src/ir/utils.h2
4 files changed, 71 insertions, 1 deletions
diff --git a/src/ir/ReFinalize.cpp b/src/ir/ReFinalize.cpp
index 0bd8a7a0f..6723c5e4f 100644
--- a/src/ir/ReFinalize.cpp
+++ b/src/ir/ReFinalize.cpp
@@ -172,6 +172,7 @@ void ReFinalize::visitExport(Export* curr) { WASM_UNREACHABLE(); }
void ReFinalize::visitGlobal(Global* curr) { WASM_UNREACHABLE(); }
void ReFinalize::visitTable(Table* curr) { WASM_UNREACHABLE(); }
void ReFinalize::visitMemory(Memory* curr) { WASM_UNREACHABLE(); }
+void ReFinalize::visitEvent(Event* curr) { WASM_UNREACHABLE(); }
void ReFinalize::visitModule(Module* curr) { WASM_UNREACHABLE(); }
void ReFinalize::updateBreakValueType(Name name, Type type) {
diff --git a/src/ir/import-utils.h b/src/ir/import-utils.h
index 950b9bfcb..3f3d27f1b 100644
--- a/src/ir/import-utils.h
+++ b/src/ir/import-utils.h
@@ -29,6 +29,7 @@ struct ImportInfo {
std::vector<Global*> importedGlobals;
std::vector<Function*> importedFunctions;
+ std::vector<Event*> importedEvents;
ImportInfo(Module& wasm) : wasm(wasm) {
for (auto& import : wasm.globals) {
@@ -41,6 +42,11 @@ struct ImportInfo {
importedFunctions.push_back(import.get());
}
}
+ for (auto& import : wasm.events) {
+ if (import->imported()) {
+ importedEvents.push_back(import.get());
+ }
+ }
}
Global* getImportedGlobal(Name module, Name base) {
@@ -61,13 +67,25 @@ struct ImportInfo {
return nullptr;
}
+ Event* getImportedEvent(Name module, Name base) {
+ for (auto* import : importedEvents) {
+ if (import->module == module && import->base == base) {
+ return import;
+ }
+ }
+ return nullptr;
+ }
+
Index getNumImportedGlobals() { return importedGlobals.size(); }
Index getNumImportedFunctions() { return importedFunctions.size(); }
+ Index getNumImportedEvents() { return importedEvents.size(); }
+
Index getNumImports() {
return getNumImportedGlobals() + getNumImportedFunctions() +
- (wasm.memory.imported() ? 1 : 0) + (wasm.table.imported() ? 1 : 0);
+ getNumImportedEvents() + (wasm.memory.imported() ? 1 : 0) +
+ (wasm.table.imported() ? 1 : 0);
}
Index getNumDefinedGlobals() {
@@ -77,6 +95,10 @@ struct ImportInfo {
Index getNumDefinedFunctions() {
return wasm.functions.size() - getNumImportedFunctions();
}
+
+ Index getNumDefinedEvents() {
+ return wasm.events.size() - getNumImportedEvents();
+ }
};
} // namespace wasm
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
diff --git a/src/ir/utils.h b/src/ir/utils.h
index a8af3ed18..b8e8fe815 100644
--- a/src/ir/utils.h
+++ b/src/ir/utils.h
@@ -154,6 +154,7 @@ struct ReFinalize
void visitGlobal(Global* curr);
void visitTable(Table* curr);
void visitMemory(Memory* curr);
+ void visitEvent(Event* curr);
void visitModule(Module* curr);
private:
@@ -208,6 +209,7 @@ struct ReFinalizeNode : public OverriddenVisitor<ReFinalizeNode> {
void visitGlobal(Global* curr) { WASM_UNREACHABLE(); }
void visitTable(Table* curr) { WASM_UNREACHABLE(); }
void visitMemory(Memory* curr) { WASM_UNREACHABLE(); }
+ void visitEvent(Event* curr) { WASM_UNREACHABLE(); }
void visitModule(Module* curr) { WASM_UNREACHABLE(); }
// given a stack of nested expressions, update them all from child to parent