Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/tools/wasm-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ int main(int argc, const char* argv[]) {
std::string outputSourceMapFilename;
std::string outputSourceMapUrl;
bool emitExnref = false;
bool emitModuleNames = false;

const std::string WasmOptOption = "wasm-opt options";

Expand Down Expand Up @@ -269,6 +270,15 @@ For more on how to optimize effectively, see
[&outputSourceMapUrl](Options* o, const std::string& argument) {
outputSourceMapUrl = argument;
})
.add(
"--emit-module-names",
"",
"Emit module names, even if not emitting the rest of the names section",
WasmOptOption,
Options::Arguments::Zero,
[&emitModuleNames](Options*, const std::string&) {
emitModuleNames = true;
})
.add_positional("INFILE",
Options::Arguments::One,
[](Options* o, const std::string& argument) {
Expand Down Expand Up @@ -407,6 +417,9 @@ For more on how to optimize effectively, see
ModuleWriter writer(options.passOptions);
writer.setBinary(emitBinary);
writer.setDebugInfo(options.passOptions.debugInfo);
if (emitModuleNames) {
writer.setEmitModuleName(true);
}
writer.write(wasm, options.extra["output"]);
firstOutput = runCommand(extraFuzzCommand);
std::cout << "[extra-fuzz-command first output:]\n" << firstOutput << '\n';
Expand Down Expand Up @@ -496,6 +509,9 @@ For more on how to optimize effectively, see
ModuleWriter writer(options.passOptions);
writer.setBinary(emitBinary);
writer.setDebugInfo(options.passOptions.debugInfo);
if (emitModuleNames) {
writer.setEmitModuleName(true);
}
if (outputSourceMapFilename.size()) {
writer.setSourceMapFilename(outputSourceMapFilename);
writer.setSourceMapUrl(outputSourceMapUrl);
Expand Down
15 changes: 15 additions & 0 deletions test/lit/emit-module-names.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
;; Check that --emit-module-names without -g strips function names but generates
;; and keeps the module name.

;; RUN: wasm-opt %s --emit-module-names -o %t.wasm
;; RUN: wasm-dis %t.wasm -o - | filecheck %s

;; CHECK: (module $module-name
;; CHECK: (func $0
;; CHECK-NOT: $foo

(module $module-name
(func $foo
(nop)
)
)
4 changes: 4 additions & 0 deletions test/lit/help/wasm-opt.test
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
;; CHECK-NEXT: --output-source-map-url,-osu Emit specified string as source
;; CHECK-NEXT: map URL
;; CHECK-NEXT:
;; CHECK-NEXT: --emit-module-names Emit module names, even if not
;; CHECK-NEXT: emitting the rest of the names
;; CHECK-NEXT: section
;; CHECK-NEXT:
;; CHECK-NEXT: --experimental-new-eh Deprecated; same as
;; CHECK-NEXT: --emit-exnref
;; CHECK-NEXT:
Expand Down
Loading