diff options
Diffstat (limited to 'test/example/module-splitting.cpp')
-rw-r--r-- | test/example/module-splitting.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/example/module-splitting.cpp b/test/example/module-splitting.cpp index 5391fe584..2aa67d6d5 100644 --- a/test/example/module-splitting.cpp +++ b/test/example/module-splitting.cpp @@ -64,6 +64,8 @@ void do_test(const std::set<Name>& keptFuncs, std::string&& module) { assert(valid && "secondary invalid!"); } +void test_minimized_exports(); + int main() { // Trivial module do_test({}, "(module)"); @@ -437,4 +439,46 @@ int main() { (export "foo2" (func $foo)) (func $foo) ))"); + + test_minimized_exports(); +} + +void test_minimized_exports() { + Module primary; + primary.features = FeatureSet::All; + + std::set<Name> keep; + Expression* callBody = nullptr; + + Builder builder(primary); + + for (size_t i = 0; i < 10; ++i) { + Name name = std::to_string(i); + primary.addFunction(Builder::makeFunction(name, {}, {}, builder.makeNop())); + keep.insert(name); + callBody = + builder.blockify(callBody, builder.makeCall(name, {}, Type::none)); + + if (i == 3) { + primary.addExport( + Builder::makeExport("already_exported", name, ExternalKind::Function)); + } + if (i == 7) { + primary.addExport( + Builder::makeExport("%b", name, ExternalKind::Function)); + } + } + + primary.addFunction(Builder::makeFunction("call", {}, {}, callBody)); + + ModuleSplitting::Config config; + config.primaryFuncs = std::move(keep); + config.newExportPrefix = "%"; + config.minimizeNewExportNames = true; + + auto secondary = splitFunctions(primary, config); + std::cout << "Minimized names primary:\n"; + std::cout << primary << "\n"; + std::cout << "Minimized names secondary:\n"; + std::cout << *secondary << "\n"; } |