diff options
author | Yury Delendik <ydelendik@mozilla.com> | 2017-06-01 14:53:42 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2017-06-01 12:53:42 -0700 |
commit | 0dc07eaa7db35cf65edbbccebe5c89b995613745 (patch) | |
tree | 0718148a976b882c826c09189a3e779be311c69e /src/tools/wasm-dis.cpp | |
parent | fcbe14a64d082117d7aab9bbf479e941964cd0de (diff) | |
download | binaryen-0dc07eaa7db35cf65edbbccebe5c89b995613745.tar.gz binaryen-0dc07eaa7db35cf65edbbccebe5c89b995613745.tar.bz2 binaryen-0dc07eaa7db35cf65edbbccebe5c89b995613745.zip |
Exporting/importing debug location information from .wast/.asm.js/.s formats (#1017)
* Extends wasm-as, wasm-dis and s2wasm to consume debug locations.
* Exports source map from asm2wasm
Diffstat (limited to 'src/tools/wasm-dis.cpp')
-rw-r--r-- | src/tools/wasm-dis.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/tools/wasm-dis.cpp b/src/tools/wasm-dis.cpp index 93c286913..e6fd7badd 100644 --- a/src/tools/wasm-dis.cpp +++ b/src/tools/wasm-dis.cpp @@ -28,6 +28,7 @@ using namespace cashew; using namespace wasm; int main(int argc, const char *argv[]) { + std::string sourceMapFilename; Options options("wasm-dis", "Un-assemble a .wasm (WebAssembly binary format) into a .wast (WebAssembly text format)"); options.add("--output", "-o", "Output file (stdout if not specified)", Options::Arguments::One, @@ -35,6 +36,9 @@ int main(int argc, const char *argv[]) { o->extra["output"] = argument; Colors::disable(); }) + .add("--source-map", "-sm", "Consume source map from the specified file to add location information", + Options::Arguments::One, + [&sourceMapFilename](Options *o, const std::string &argument) { sourceMapFilename = argument; }) .add_positional("INFILE", Options::Arguments::One, [](Options *o, const std::string &argument) { o->extra["infile"] = argument; @@ -46,11 +50,23 @@ int main(int argc, const char *argv[]) { if (options.debug) std::cerr << "parsing binary..." << std::endl; Module wasm; try { + std::unique_ptr<std::ifstream> sourceMapStream; WasmBinaryBuilder parser(wasm, input, options.debug); + if (sourceMapFilename.size()) { + sourceMapStream = make_unique<std::ifstream>(); + sourceMapStream->open(sourceMapFilename); + parser.setDebugLocations(sourceMapStream.get()); + } parser.read(); + if (sourceMapStream) { + sourceMapStream->close(); + } } catch (ParseException& p) { p.dump(std::cerr); Fatal() << "error in parsing wasm binary"; + } catch (MapParseException& p) { + p.dump(std::cerr); + Fatal() << "error in parsing wasm source mapping"; } if (options.debug) std::cerr << "Printing..." << std::endl; |