summaryrefslogtreecommitdiff
path: root/src/ir/table-utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/table-utils.cpp')
-rw-r--r--src/ir/table-utils.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir/table-utils.cpp b/src/ir/table-utils.cpp
index 80ef885f9..79b90d249 100644
--- a/src/ir/table-utils.cpp
+++ b/src/ir/table-utils.cpp
@@ -64,6 +64,25 @@ std::set<Name> getFunctionsNeedingElemDeclare(Module& wasm) {
return ret;
}
+bool usesExpressions(ElementSegment* curr, Module* module) {
+ // Binaryen IR always has ref.funcs for functions in tables for uniformity,
+ // so that by itself does not indicate if expressions should be used when
+ // emitting the table or not. But definitely anything that is not a ref.func
+ // implies we are post-MVP and must use expressions.
+ bool allElementsRefFunc =
+ std::all_of(curr->data.begin(), curr->data.end(), [](Expression* entry) {
+ return entry->is<RefFunc>();
+ });
+
+ // If the table has a specialized (non-MVP) type, then the segment must
+ // declare a type that is a subtype of that, so it must use the post-MVP form
+ // of using expressions.
+ bool hasTableOfSpecializedType =
+ curr->table.is() && module->getTable(curr->table)->type != Type::funcref;
+
+ return !allElementsRefFunc || hasTableOfSpecializedType;
+}
+
} // namespace TableUtils
} // namespace wasm