Skip to content

Commit 5c9dfac

Browse files
authored
[wasm-split] Support --emit-module-names and --emit-text for multi-split (#7781)
1 parent 62dae74 commit 5c9dfac

File tree

4 files changed

+107
-13
lines changed

4 files changed

+107
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ WasmSplitOptions::WasmSplitOptions()
318318
"removed once simpler ways of naming modules are widely available. See "
319319
"https://bugs.chromium.org/p/v8/issues/detail?id=11808.",
320320
WasmSplitOption,
321-
{Mode::Split, Mode::Instrument},
321+
{Mode::Split, Mode::MultiSplit, Mode::Instrument},
322322
Options::Arguments::Zero,
323323
[&](Options* o, const std::string& arguments) { emitModuleNames = true; })
324324
.add("--initial-table",
@@ -337,7 +337,7 @@ WasmSplitOptions::WasmSplitOptions()
337337
"-S",
338338
"Emit text instead of binary for the output file or files.",
339339
WasmSplitOption,
340-
{Mode::Split, Mode::Instrument},
340+
{Mode::Split, Mode::MultiSplit, Mode::Instrument},
341341
Options::Arguments::Zero,
342342
[&](Options* o, const std::string& argument) { emitBinary = false; })
343343
.add("--debuginfo",

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ void multiSplitModule(const WasmSplitOptions& options) {
418418
config.usePlaceholders = false;
419419
config.importNamespace = options.importNamespace;
420420
config.minimizeNewExportNames = !options.passOptions.debugInfo;
421+
if (options.emitModuleNames && !wasm.name) {
422+
wasm.name = Path::getBaseName(options.output);
423+
}
424+
421425
for (auto& [mod, funcs] : moduleFuncs) {
422426
if (options.verbose) {
423427
std::cerr << "Splitting module " << mod << '\n';
@@ -427,9 +431,12 @@ void multiSplitModule(const WasmSplitOptions& options) {
427431
}
428432
config.secondaryFuncs = std::set<Name>(funcs.begin(), funcs.end());
429433
auto splitResults = ModuleSplitting::splitFunctions(wasm, config);
430-
// TODO: symbolMap, placeholderMap, emitModuleNames
431-
// TODO: Support --emit-text and use .wast in that case.
432-
auto moduleName = options.outPrefix + mod + ".wasm";
434+
// TODO: symbolMap, placeholderMap
435+
auto moduleName =
436+
options.outPrefix + mod + (options.emitBinary ? ".wasm" : ".wast");
437+
if (options.emitModuleNames) {
438+
splitResults.secondary->name = Path::getBaseName(moduleName);
439+
}
433440
writeModule(*splitResults.secondary, moduleName, options);
434441
}
435442
writeModule(wasm, options.output, options);

test/lit/help/wasm-split.test

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@
122122
;; CHECK-NEXT: memory created to store profile
123123
;; CHECK-NEXT: information.
124124
;; CHECK-NEXT:
125-
;; CHECK-NEXT: --emit-module-names [split, instrument] Emit module names,
126-
;; CHECK-NEXT: even if not emitting the rest of the
127-
;; CHECK-NEXT: names section. Can help differentiate the
128-
;; CHECK-NEXT: modules in stack traces. This option will
129-
;; CHECK-NEXT: be removed once simpler ways of naming
130-
;; CHECK-NEXT: modules are widely available. See
125+
;; CHECK-NEXT: --emit-module-names [split, multi-split, instrument] Emit
126+
;; CHECK-NEXT: module names, even if not emitting the
127+
;; CHECK-NEXT: rest of the names section. Can help
128+
;; CHECK-NEXT: differentiate the modules in stack
129+
;; CHECK-NEXT: traces. This option will be removed once
130+
;; CHECK-NEXT: simpler ways of naming modules are widely
131+
;; CHECK-NEXT: available. See
131132
;; CHECK-NEXT: https://bugs.chromium.org/p/v8/issues/detail?id=11808.
132133
;; CHECK-NEXT:
133134
;; CHECK-NEXT: --initial-table [split, instrument] A hack to ensure the
@@ -137,8 +138,9 @@
137138
;; CHECK-NEXT: TODO: Figure out a more elegant solution
138139
;; CHECK-NEXT: for that use case and remove this.
139140
;; CHECK-NEXT:
140-
;; CHECK-NEXT: --emit-text,-S [split, instrument] Emit text instead of
141-
;; CHECK-NEXT: binary for the output file or files.
141+
;; CHECK-NEXT: --emit-text,-S [split, multi-split, instrument] Emit
142+
;; CHECK-NEXT: text instead of binary for the output
143+
;; CHECK-NEXT: file or files.
142144
;; CHECK-NEXT:
143145
;; CHECK-NEXT: --debuginfo,-g [split, multi-split, instrument] Emit
144146
;; CHECK-NEXT: names section in wasm binary (or full
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
;; RUN: wasm-split -all --multi-split %s --manifest %S/multi-split.wast.manifest --out-prefix=%t --emit-module-names -o %t.wasm
2+
;; RUN: wasm-dis %t.wasm | filecheck %s --check-prefix=PRIMARY-WASM
3+
;; RUN: wasm-dis %t1.wasm | filecheck %s --check-prefix=MOD1-WASM
4+
;; RUN: wasm-dis %t2.wasm | filecheck %s --check-prefix=MOD2-WASM
5+
;; RUN: wasm-dis %t3.wasm | filecheck %s --check-prefix=MOD3-WASM
6+
7+
;; Check if --emit-text with --emit-module-names works.
8+
;; RUN: wasm-split -all --multi-split %s --manifest %S/multi-split.wast.manifest --out-prefix=%t --emit-module-names -S -o %t.wast
9+
;; RUN: cat %t.wast | filecheck %s --check-prefix=PRIMARY-WAST
10+
;; RUN: cat %t1.wast | filecheck %s --check-prefix=MOD1-WAST
11+
;; RUN: cat %t2.wast | filecheck %s --check-prefix=MOD2-WAST
12+
;; RUN: cat %t3.wast | filecheck %s --check-prefix=MOD3-WAST
13+
14+
;; PRIMARY-WASM: (module $module-names-multi-split.wast.tmp.wasm
15+
;; MOD1-WASM: (module $module-names-multi-split.wast.tmp1.wasm
16+
;; MOD2-WASM: (module $module-names-multi-split.wast.tmp2.wasm
17+
;; MOD3-WASM: (module $module-names-multi-split.wast.tmp3.wasm
18+
19+
;; PRIMARY-WAST: (module $module-names-multi-split.wast.tmp.wast
20+
;; MOD1-WAST: (module $module-names-multi-split.wast.tmp1.wast
21+
;; MOD2-WAST: (module $module-names-multi-split.wast.tmp2.wast
22+
;; MOD3-WAST: (module $module-names-multi-split.wast.tmp3.wast
23+
24+
(module
25+
(type $ret-i32 (func (result i32)))
26+
(type $ret-i64 (func (result i64)))
27+
(type $ret-f32 (func (result f32)))
28+
29+
(func $A (type $ret-i32) (result i32)
30+
(drop
31+
(call_ref $ret-i32
32+
(ref.func $A)
33+
)
34+
)
35+
(drop
36+
(call_ref $ret-i64
37+
(ref.func $B)
38+
)
39+
)
40+
(drop
41+
(call_ref $ret-f32
42+
(ref.func $C)
43+
)
44+
)
45+
(i32.const 0)
46+
)
47+
48+
(func $B (type $ret-i64) (result i64)
49+
(drop
50+
(call_ref $ret-i32
51+
(ref.func $A)
52+
)
53+
)
54+
(drop
55+
(call_ref $ret-i64
56+
(ref.func $B)
57+
)
58+
)
59+
(drop
60+
(call_ref $ret-f32
61+
(ref.func $C)
62+
)
63+
)
64+
(i64.const 0)
65+
)
66+
67+
(func $C (type $ret-f32) (result f32)
68+
(drop
69+
(call_ref $ret-i32
70+
(ref.func $A)
71+
)
72+
)
73+
(drop
74+
(call_ref $ret-i64
75+
(ref.func $B)
76+
)
77+
)
78+
(drop
79+
(call_ref $ret-f32
80+
(ref.func $C)
81+
)
82+
)
83+
(f32.const 0)
84+
)
85+
)

0 commit comments

Comments
 (0)