Skip to content

Commit 6d47b7b

Browse files
authored
Add an option to emit a symbols file from wasm2js. (#2214)
This can't use the normal wasm-opt mechanism because we modify the discard the wasm as part of running wasm2js, so we need to emit it in the proper place in the middle.
1 parent 6f73ad6 commit 6d47b7b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/tools/wasm2js.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,14 @@ int main(int argc, const char* argv[]) {
838838
"form)",
839839
Options::Arguments::Zero,
840840
[&](Options* o, const std::string& argument) { flags.emscripten = true; })
841+
.add(
842+
"--symbols-file",
843+
"",
844+
"Emit a symbols file that maps function indexes to their original names",
845+
Options::Arguments::One,
846+
[&](Options* o, const std::string& argument) {
847+
flags.symbolsFile = argument;
848+
})
841849
.add_positional("INFILE",
842850
Options::Arguments::One,
843851
[](Options* o, const std::string& argument) {

src/wasm2js.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "mixed_arena.h"
4343
#include "passes/passes.h"
4444
#include "support/base64.h"
45+
#include "support/file.h"
4546
#include "wasm-builder.h"
4647
#include "wasm-io.h"
4748
#include "wasm-validator.h"
@@ -123,6 +124,7 @@ class Wasm2JSBuilder {
123124
bool pedantic = false;
124125
bool allowAsserts = false;
125126
bool emscripten = false;
127+
std::string symbolsFile;
126128
};
127129

128130
Wasm2JSBuilder(Flags f, PassOptions options_) : flags(f), options(options_) {
@@ -330,6 +332,14 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) {
330332
runner.run();
331333
}
332334

335+
if (flags.symbolsFile.size() > 0) {
336+
Output out(flags.symbolsFile, wasm::Flags::Text, wasm::Flags::Release);
337+
Index i = 0;
338+
for (auto& func : wasm->functions) {
339+
out.getStream() << i++ << ':' << func->name.str << '\n';
340+
}
341+
}
342+
333343
#ifndef NDEBUG
334344
if (!WasmValidator().validate(*wasm)) {
335345
WasmPrinter::printModule(wasm);

0 commit comments

Comments
 (0)