diff options
author | Alon Zakai <alonzakai@gmail.com> | 2019-07-11 16:30:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-11 16:30:18 -0700 |
commit | 6d47b7bf14da72489bac4f4637e797b854f317c8 (patch) | |
tree | 5b3a857ac3618135433b62cd7d82b1c2493079be /src | |
parent | 6f73ad6e22b6be458f91c5ebe1f72cbcd6641264 (diff) | |
download | binaryen-6d47b7bf14da72489bac4f4637e797b854f317c8.tar.gz binaryen-6d47b7bf14da72489bac4f4637e797b854f317c8.tar.bz2 binaryen-6d47b7bf14da72489bac4f4637e797b854f317c8.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm2js.cpp | 8 | ||||
-rw-r--r-- | src/wasm2js.h | 10 |
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); |