summaryrefslogtreecommitdiff
path: root/src/tools/wasm-as.cpp
diff options
context:
space:
mode:
authorYury Delendik <ydelendik@mozilla.com>2017-06-01 14:53:42 -0500
committerAlon Zakai <alonzakai@gmail.com>2017-06-01 12:53:42 -0700
commit0dc07eaa7db35cf65edbbccebe5c89b995613745 (patch)
tree0718148a976b882c826c09189a3e779be311c69e /src/tools/wasm-as.cpp
parentfcbe14a64d082117d7aab9bbf479e941964cd0de (diff)
downloadbinaryen-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-as.cpp')
-rw-r--r--src/tools/wasm-as.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp
index 067c0f28d..e8003a5ca 100644
--- a/src/tools/wasm-as.cpp
+++ b/src/tools/wasm-as.cpp
@@ -30,6 +30,8 @@ using namespace wasm;
int main(int argc, const char *argv[]) {
bool debugInfo = false;
std::string symbolMap;
+ std::string sourceMapFilename;
+ std::string sourceMapUrl;
Options options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)");
options.extra["validate"] = "wasm";
options
@@ -51,6 +53,12 @@ int main(int argc, const char *argv[]) {
.add("--debuginfo", "-g", "Emit names section and debug info",
Options::Arguments::Zero,
[&](Options *o, const std::string &arguments) { debugInfo = true; })
+ .add("--source-map", "-sm", "Emit source map to the specified file",
+ Options::Arguments::One,
+ [&sourceMapFilename](Options *o, const std::string &argument) { sourceMapFilename = argument; })
+ .add("--source-map-url", "-su", "Use specified string as source map URL",
+ Options::Arguments::One,
+ [&sourceMapUrl](Options *o, const std::string &argument) { sourceMapUrl = argument; })
.add("--symbolmap", "-s", "Emit a symbol map (indexes => names)",
Options::Arguments::One,
[&](Options *o, const std::string &argument) { symbolMap = argument; })
@@ -86,13 +94,23 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "binarification..." << std::endl;
BufferWithRandomAccess buffer(options.debug);
WasmBinaryWriter writer(&wasm, buffer, options.debug);
- writer.setDebugInfo(debugInfo);
+ // if debug info is used, then we want to emit the names section
+ writer.setNamesSection(debugInfo);
+ std::unique_ptr<std::ofstream> sourceMapStream = nullptr;
+ if (sourceMapFilename.size()) {
+ sourceMapStream = make_unique<std::ofstream>();
+ sourceMapStream->open(sourceMapFilename);
+ writer.setSourceMap(sourceMapStream.get(), sourceMapUrl);
+ }
if (symbolMap.size() > 0) writer.setSymbolMap(symbolMap);
writer.write();
if (options.debug) std::cerr << "writing to output..." << std::endl;
Output output(options.extra["output"], Flags::Binary, options.debug ? Flags::Debug : Flags::Release);
buffer.writeTo(output);
+ if (sourceMapStream) {
+ sourceMapStream->close();
+ }
if (options.debug) std::cerr << "Done." << std::endl;
}