summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/wasm2js.cpp8
-rw-r--r--src/wasm2js.h10
2 files changed, 18 insertions, 0 deletions
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp
index 8e6ab074f..cf2532c6c 100644
--- a/src/tools/wasm2js.cpp
+++ b/src/tools/wasm2js.cpp
@@ -838,6 +838,14 @@ int main(int argc, const char* argv[]) {
"form)",
Options::Arguments::Zero,
[&](Options* o, const std::string& argument) { flags.emscripten = true; })
+ .add(
+ "--symbols-file",
+ "",
+ "Emit a symbols file that maps function indexes to their original names",
+ Options::Arguments::One,
+ [&](Options* o, const std::string& argument) {
+ flags.symbolsFile = argument;
+ })
.add_positional("INFILE",
Options::Arguments::One,
[](Options* o, const std::string& argument) {
diff --git a/src/wasm2js.h b/src/wasm2js.h
index 9936f492e..a3447749c 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -42,6 +42,7 @@
#include "mixed_arena.h"
#include "passes/passes.h"
#include "support/base64.h"
+#include "support/file.h"
#include "wasm-builder.h"
#include "wasm-io.h"
#include "wasm-validator.h"
@@ -123,6 +124,7 @@ public:
bool pedantic = false;
bool allowAsserts = false;
bool emscripten = false;
+ std::string symbolsFile;
};
Wasm2JSBuilder(Flags f, PassOptions options_) : flags(f), options(options_) {
@@ -330,6 +332,14 @@ Ref Wasm2JSBuilder::processWasm(Module* wasm, Name funcName) {
runner.run();
}
+ if (flags.symbolsFile.size() > 0) {
+ Output out(flags.symbolsFile, wasm::Flags::Text, wasm::Flags::Release);
+ Index i = 0;
+ for (auto& func : wasm->functions) {
+ out.getStream() << i++ << ':' << func->name.str << '\n';
+ }
+ }
+
#ifndef NDEBUG
if (!WasmValidator().validate(*wasm)) {
WasmPrinter::printModule(wasm);