summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
Diffstat (limited to 'test/example')
-rw-r--r--test/example/module-splitting.cpp44
-rw-r--r--test/example/module-splitting.txt72
2 files changed, 116 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";
}
diff --git a/test/example/module-splitting.txt b/test/example/module-splitting.txt
index 5c3728cde..2b92e9dd6 100644
--- a/test/example/module-splitting.txt
+++ b/test/example/module-splitting.txt
@@ -1107,3 +1107,75 @@ Secondary:
)
+Minimized names primary:
+(module
+ (type $none_=>_none (func))
+ (export "already_exported" (func $3))
+ (export "%b" (func $7))
+ (export "%a" (func $0))
+ (export "%c" (func $1))
+ (export "%d" (func $2))
+ (export "%e" (func $4))
+ (export "%f" (func $5))
+ (export "%g" (func $6))
+ (export "%h" (func $8))
+ (export "%i" (func $9))
+ (func $0
+ (nop)
+ )
+ (func $1
+ (nop)
+ )
+ (func $2
+ (nop)
+ )
+ (func $3
+ (nop)
+ )
+ (func $4
+ (nop)
+ )
+ (func $5
+ (nop)
+ )
+ (func $6
+ (nop)
+ )
+ (func $7
+ (nop)
+ )
+ (func $8
+ (nop)
+ )
+ (func $9
+ (nop)
+ )
+)
+
+Minimized names secondary:
+(module
+ (type $none_=>_none (func))
+ (import "primary" "%a" (func $0))
+ (import "primary" "%c" (func $1))
+ (import "primary" "%d" (func $2))
+ (import "primary" "already_exported" (func $3))
+ (import "primary" "%e" (func $4))
+ (import "primary" "%f" (func $5))
+ (import "primary" "%g" (func $6))
+ (import "primary" "%b" (func $7))
+ (import "primary" "%h" (func $8))
+ (import "primary" "%i" (func $9))
+ (func $call
+ (call $0)
+ (call $1)
+ (call $2)
+ (call $3)
+ (call $4)
+ (call $5)
+ (call $6)
+ (call $7)
+ (call $8)
+ (call $9)
+ )
+)
+