summaryrefslogtreecommitdiff
path: root/src/passes/ReorderFunctions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/ReorderFunctions.cpp')
-rw-r--r--src/passes/ReorderFunctions.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/passes/ReorderFunctions.cpp b/src/passes/ReorderFunctions.cpp
index 96ebfc048..cf3c8bb1f 100644
--- a/src/passes/ReorderFunctions.cpp
+++ b/src/passes/ReorderFunctions.cpp
@@ -97,4 +97,22 @@ struct ReorderFunctions : public Pass {
Pass* createReorderFunctionsPass() { return new ReorderFunctions(); }
+struct ReorderFunctionsByName : public Pass {
+ // Only reorders functions, does not change their contents.
+ bool requiresNonNullableLocalFixups() override { return false; }
+
+ void run(Module* module) override {
+ std::sort(module->functions.begin(),
+ module->functions.end(),
+ [](const std::unique_ptr<Function>& a,
+ const std::unique_ptr<Function>& b) -> bool {
+ return a->name < b->name;
+ });
+ }
+};
+
+Pass* createReorderFunctionsByNamePass() {
+ return new ReorderFunctionsByName();
+}
+
} // namespace wasm