Skip to content

Commit 4dcade8

Browse files
authored
[wasm-split] Support --export-prefix for multi-split (WebAssembly#7967)
1 parent 253ed6c commit 4dcade8

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

src/tools/wasm-split/split-options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ WasmSplitOptions::WasmSplitOptions()
260260
"An identifying prefix to prepend to new export names created "
261261
"by module splitting.",
262262
WasmSplitOption,
263-
{Mode::Split},
263+
{Mode::Split, Mode::MultiSplit},
264264
Options::Arguments::One,
265265
[&](Options* o, const std::string& argument) { exportPrefix = argument; })
266266
.add("--profile-export",

src/tools/wasm-split/wasm-split.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ void setCommonSplitConfigs(ModuleSplitting::Config& config,
229229
if (options.importNamespace.size()) {
230230
config.importNamespace = options.importNamespace;
231231
}
232+
if (options.exportPrefix.size()) {
233+
config.newExportPrefix = options.exportPrefix;
234+
}
232235
// TODO Add more configs here
233236
}
234237

@@ -344,9 +347,6 @@ void splitModule(const WasmSplitOptions& options) {
344347
if (options.placeholderNamespace.size()) {
345348
config.placeholderNamespace = options.placeholderNamespace;
346349
}
347-
if (options.exportPrefix.size()) {
348-
config.newExportPrefix = options.exportPrefix;
349-
}
350350
config.jspi = options.jspi;
351351
auto splitResults = ModuleSplitting::splitFunctions(wasm, config);
352352
auto& secondary = *splitResults.secondaries.begin();

test/lit/help/wasm-split.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@
9393
;; CHECK-NEXT: module before any placeholder functions
9494
;; CHECK-NEXT: have been called.
9595
;; CHECK-NEXT:
96-
;; CHECK-NEXT: --export-prefix [split] An identifying prefix to prepend
97-
;; CHECK-NEXT: to new export names created by module
98-
;; CHECK-NEXT: splitting.
96+
;; CHECK-NEXT: --export-prefix [split, multi-split] An identifying
97+
;; CHECK-NEXT: prefix to prepend to new export names
98+
;; CHECK-NEXT: created by module splitting.
9999
;; CHECK-NEXT:
100100
;; CHECK-NEXT: --profile-export [instrument] The export name of the
101101
;; CHECK-NEXT: function the embedder calls to write the

test/lit/wasm-split/multi-split.wast

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=MOD2
77
;; RUN: wasm-dis %t3.wasm | filecheck %s --check-prefix=MOD3
88

9-
;; Check if --import-namespace and --no-placeholders options work.
10-
;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t --import-namespace=custom_env --no-placeholders -o %t.wasm
9+
;; Check if --import-namespace, --export-prefix, and --no-placeholders options
10+
;; work.
11+
;; RUN: wasm-split -all -g --multi-split %s --manifest %s.manifest --out-prefix=%t --import-namespace=custom_env --export-prefix='%' --no-placeholders -o %t.wasm
1112
;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=PRIMARY-OPTIONS
1213
;; RUN: wasm-dis %t1.wasm | filecheck %s --check-prefix=MOD1-OPTIONS
1314
;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=MOD2-OPTIONS
@@ -66,11 +67,11 @@
6667

6768
;; MOD1-OPTIONS: (type $2 (func (result i32)))
6869

69-
;; MOD1-OPTIONS: (import "custom_env" "table" (table $timport$0 3 funcref))
70+
;; MOD1-OPTIONS: (import "custom_env" "%table" (table $timport$0 3 funcref))
7071

71-
;; MOD1-OPTIONS: (import "custom_env" "trampoline_B" (func $trampoline_B (result i64)))
72+
;; MOD1-OPTIONS: (import "custom_env" "%trampoline_B" (func $trampoline_B (result i64)))
7273

73-
;; MOD1-OPTIONS: (import "custom_env" "trampoline_C" (func $trampoline_C (result f32)))
74+
;; MOD1-OPTIONS: (import "custom_env" "%trampoline_C" (func $trampoline_C (result f32)))
7475

7576
;; MOD1-OPTIONS: (elem $0 (i32.const 2) $A)
7677

@@ -149,11 +150,11 @@
149150

150151
;; MOD2-OPTIONS: (type $2 (func (result i64)))
151152

152-
;; MOD2-OPTIONS: (import "custom_env" "table" (table $timport$0 3 funcref))
153+
;; MOD2-OPTIONS: (import "custom_env" "%table" (table $timport$0 3 funcref))
153154

154-
;; MOD2-OPTIONS: (import "custom_env" "trampoline_A" (func $trampoline_A (result i32)))
155+
;; MOD2-OPTIONS: (import "custom_env" "%trampoline_A" (func $trampoline_A (result i32)))
155156

156-
;; MOD2-OPTIONS: (import "custom_env" "trampoline_C" (func $trampoline_C (result f32)))
157+
;; MOD2-OPTIONS: (import "custom_env" "%trampoline_C" (func $trampoline_C (result f32)))
157158

158159
;; MOD2-OPTIONS: (elem $0 (i32.const 0) $B)
159160

@@ -232,11 +233,11 @@
232233

233234
;; MOD3-OPTIONS: (type $2 (func (result f32)))
234235

235-
;; MOD3-OPTIONS: (import "custom_env" "table" (table $timport$0 3 funcref))
236+
;; MOD3-OPTIONS: (import "custom_env" "%table" (table $timport$0 3 funcref))
236237

237-
;; MOD3-OPTIONS: (import "custom_env" "trampoline_A" (func $trampoline_A (result i32)))
238+
;; MOD3-OPTIONS: (import "custom_env" "%trampoline_A" (func $trampoline_A (result i32)))
238239

239-
;; MOD3-OPTIONS: (import "custom_env" "trampoline_B" (func $trampoline_B (result i64)))
240+
;; MOD3-OPTIONS: (import "custom_env" "%trampoline_B" (func $trampoline_B (result i64)))
240241

241242
;; MOD3-OPTIONS: (elem $0 (i32.const 1) $C)
242243

@@ -317,13 +318,13 @@
317318

318319
;; PRIMARY-OPTIONS: (elem $0 (table $0) (i32.const 0) funcref (item (ref.null nofunc)) (item (ref.null nofunc)) (item (ref.null nofunc)))
319320

320-
;; PRIMARY-OPTIONS: (export "trampoline_B" (func $trampoline_B))
321+
;; PRIMARY-OPTIONS: (export "%trampoline_B" (func $trampoline_B))
321322

322-
;; PRIMARY-OPTIONS: (export "trampoline_C" (func $trampoline_C))
323+
;; PRIMARY-OPTIONS: (export "%trampoline_C" (func $trampoline_C))
323324

324-
;; PRIMARY-OPTIONS: (export "trampoline_A" (func $trampoline_A))
325+
;; PRIMARY-OPTIONS: (export "%trampoline_A" (func $trampoline_A))
325326

326-
;; PRIMARY-OPTIONS: (export "table" (table $0))
327+
;; PRIMARY-OPTIONS: (export "%table" (table $0))
327328

328329
;; PRIMARY-OPTIONS: (func $trampoline_B (result i64)
329330
;; PRIMARY-OPTIONS-NEXT: (call_indirect (type $ret-i64)

0 commit comments

Comments
 (0)