diff options
| author | Yury Delendik <ydelendik@mozilla.com> | 2018-01-29 20:13:29 -0600 |
|---|---|---|
| committer | Yury Delendik <ydelendik@mozilla.com> | 2018-01-30 20:10:58 -0600 |
| commit | cfe53c066646857a19046ebaf0cdc410c3d9f034 (patch) | |
| tree | c2a4b883ac1861e17a244fe155e6501f9bab6f60 /src/librustc_binaryen/BinaryenWrapper.cpp | |
| parent | a0dcecff90c45ad5d4eb60859e22bb3f1b03842a (diff) | |
| download | rust-cfe53c066646857a19046ebaf0cdc410c3d9f034.tar.gz rust-cfe53c066646857a19046ebaf0cdc410c3d9f034.zip | |
Export wasm source map when debug information is enabled
We use binaryen's linker to produce a wasm file (via s2wasm). The wasm writer has capabilities to export source maps. The produced source map contains references to the original file, that might require additional source map file processing to include / package original files with it.
Diffstat (limited to 'src/librustc_binaryen/BinaryenWrapper.cpp')
| -rw-r--r-- | src/librustc_binaryen/BinaryenWrapper.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/librustc_binaryen/BinaryenWrapper.cpp b/src/librustc_binaryen/BinaryenWrapper.cpp index d1095a7819d..55f11665f6d 100644 --- a/src/librustc_binaryen/BinaryenWrapper.cpp +++ b/src/librustc_binaryen/BinaryenWrapper.cpp @@ -14,6 +14,7 @@ #include <stdint.h> #include <string> +#include <sstream> #include <stdlib.h> #include "s2wasm.h" @@ -24,6 +25,7 @@ using namespace wasm; struct BinaryenRustModule { BufferWithRandomAccess buffer; + std::string sourceMapJSON; }; struct BinaryenRustModuleOptions { @@ -36,6 +38,7 @@ struct BinaryenRustModuleOptions { bool ignoreUnknownSymbols; bool debugInfo; std::string startFunction; + std::string sourceMapUrl; BinaryenRustModuleOptions() : globalBase(0), @@ -46,7 +49,8 @@ struct BinaryenRustModuleOptions { importMemory(false), ignoreUnknownSymbols(false), debugInfo(false), - startFunction("") + startFunction(""), + sourceMapUrl("") {} }; @@ -74,6 +78,12 @@ BinaryenRustModuleOptionsSetStart(BinaryenRustModuleOptions *options, } extern "C" void +BinaryenRustModuleOptionsSetSourceMapUrl(BinaryenRustModuleOptions *options, + char *sourceMapUrl) { + options->sourceMapUrl = sourceMapUrl; +} + +extern "C" void BinaryenRustModuleOptionsSetStackAllocation(BinaryenRustModuleOptions *options, uint64_t stack) { options->stackAllocation = stack; @@ -106,12 +116,20 @@ BinaryenRustModuleCreate(const BinaryenRustModuleOptions *options, { WasmBinaryWriter writer(&linker.getOutput().wasm, ret->buffer, options->debug); writer.setNamesSection(options->debugInfo); - // FIXME: support source maps? - // writer.setSourceMap(sourceMapStream.get(), sourceMapUrl); + + std::unique_ptr<std::ostringstream> sourceMapStream = nullptr; + { + sourceMapStream = make_unique<std::ostringstream>(); + writer.setSourceMap(sourceMapStream.get(), options->sourceMapUrl); + } // FIXME: support symbol maps? // writer.setSymbolMap(symbolMap); writer.write(); + + if (sourceMapStream) { + ret->sourceMapJSON = sourceMapStream->str(); + } } return ret.release(); } @@ -126,6 +144,16 @@ BinaryenRustModuleLen(const BinaryenRustModule *M) { return M->buffer.size(); } +extern "C" const char* +BinaryenRustModuleSourceMapPtr(const BinaryenRustModule *M) { + return M->sourceMapJSON.data(); +} + +extern "C" size_t +BinaryenRustModuleSourceMapLen(const BinaryenRustModule *M) { + return M->sourceMapJSON.length(); +} + extern "C" void BinaryenRustModuleFree(BinaryenRustModule *M) { delete M; |
