From 2dcf466fb857538b2f5e06a399e68642a07938da Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 23 May 2017 16:33:37 -0500 Subject: [PATCH] Renames paramenters from binarymap to sourcemap. --- check.py | 6 ++-- src/tools/asm2wasm.cpp | 18 +++++----- src/tools/wasm-as.cpp | 26 +++++++------- src/tools/wasm-dis.cpp | 20 +++++------ src/wasm-binary.h | 28 +++++++-------- src/wasm-io.h | 8 ++--- src/wasm/wasm-binary.cpp | 73 ++++++++++++++++++++-------------------- src/wasm/wasm-io.cpp | 14 ++++---- 8 files changed, 97 insertions(+), 96 deletions(-) diff --git a/check.py b/check.py index 384ccfc30d0..f5d7012ad4e 100755 --- a/check.py +++ b/check.py @@ -178,8 +178,8 @@ def do_asm2wasm_test(): # verify debug info if 'debugInfo' in asm: jsmap = 'a.wasm.map' - cmd += ['--binarymap-file', jsmap, - '--binarymap-url', 'http://example.org/' + jsmap, + cmd += ['--source-map', jsmap, + '--source-map-url', 'http://example.org/' + jsmap, '-o', 'a.wasm'] run_command(cmd) if not os.path.isfile(jsmap): @@ -252,7 +252,7 @@ def do_asm2wasm_test(): print '..', t t = os.path.join(options.binaryen_test, t) cmd = WASM_DIS + [t] - if os.path.isfile(t + '.map'): cmd += ['-bm', t + '.map'] + if os.path.isfile(t + '.map'): cmd += ['--source-map', t + '.map'] actual = run_command(cmd) diff --git a/src/tools/asm2wasm.cpp b/src/tools/asm2wasm.cpp index f404d9f6698..c2d68a7e5a9 100644 --- a/src/tools/asm2wasm.cpp +++ b/src/tools/asm2wasm.cpp @@ -37,8 +37,8 @@ int main(int argc, const char *argv[]) { bool runOptimizationPasses = false; Asm2WasmBuilder::TrapMode trapMode = Asm2WasmBuilder::TrapMode::JS; bool wasmOnly = false; - std::string binaryMapFile; - std::string binaryMapUrl; + std::string sourceMapFilename; + std::string sourceMapUrl; std::string symbolMap; bool emitBinary = true; @@ -106,12 +106,12 @@ int main(int argc, const char *argv[]) { .add("--debuginfo", "-g", "Emit names section in wasm binary (or full debuginfo in wast)", Options::Arguments::Zero, [&](Options *o, const std::string &arguments) { passOptions.debugInfo = true; }) - .add("--binarymap-file", "-bm", "Emit binary map (if using binary output) to the specified file", + .add("--source-map", "-sm", "Emit source map (if using binary output) to the specified file", Options::Arguments::One, - [&binaryMapFile](Options *o, const std::string &argument) { binaryMapFile = argument; }) - .add("--binarymap-url", "-bu", "Use specified string as binary map URL", + [&sourceMapFilename](Options *o, const std::string &argument) { sourceMapFilename = argument; }) + .add("--source-map-url", "-su", "Use specified string as source map URL", Options::Arguments::One, - [&binaryMapUrl](Options *o, const std::string &argument) { binaryMapUrl = argument; }) + [&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; }) @@ -142,7 +142,7 @@ int main(int argc, const char *argv[]) { Asm2WasmPreProcessor pre; // wasm binaries can contain a names section, but not full debug info -- // debug info is disabled if a map file is not specified with wasm binary - pre.debugInfo = passOptions.debugInfo && (!emitBinary || binaryMapFile.size()); + pre.debugInfo = passOptions.debugInfo && (!emitBinary || sourceMapFilename.size()); auto input( read_file>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); char *start = pre.process(input.data()); @@ -210,8 +210,8 @@ int main(int argc, const char *argv[]) { writer.setSymbolMap(symbolMap); writer.setBinary(emitBinary); if (emitBinary) { - writer.setBinaryMapFilename(binaryMapFile); - writer.setBinaryMapUrl(binaryMapUrl); + writer.setSourceMapFilename(sourceMapFilename); + writer.setSourceMapUrl(sourceMapUrl); } writer.write(wasm, options.extra["output"]); diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp index c289accfd18..e8003a5ca16 100644 --- a/src/tools/wasm-as.cpp +++ b/src/tools/wasm-as.cpp @@ -30,8 +30,8 @@ using namespace wasm; int main(int argc, const char *argv[]) { bool debugInfo = false; std::string symbolMap; - std::string binaryMapFilename; - std::string binaryMapUrl; + 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 @@ -53,12 +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("--binarymap-file", "-bm", "Emit binary map to the specified file", + .add("--source-map", "-sm", "Emit source map to the specified file", Options::Arguments::One, - [&binaryMapFilename](Options *o, const std::string &argument) { binaryMapFilename = argument; }) - .add("--binarymap-url", "-bu", "Use specified string as binary map URL", + [&sourceMapFilename](Options *o, const std::string &argument) { sourceMapFilename = argument; }) + .add("--source-map-url", "-su", "Use specified string as source map URL", Options::Arguments::One, - [&binaryMapUrl](Options *o, const std::string &argument) { binaryMapUrl = argument; }) + [&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; }) @@ -96,11 +96,11 @@ int main(int argc, const char *argv[]) { WasmBinaryWriter writer(&wasm, buffer, options.debug); // if debug info is used, then we want to emit the names section writer.setNamesSection(debugInfo); - std::unique_ptr binaryMapStream = nullptr; - if (binaryMapFilename.size()) { - binaryMapStream = make_unique(); - binaryMapStream->open(binaryMapFilename); - writer.setBinaryMap(binaryMapStream.get(), binaryMapUrl); + std::unique_ptr sourceMapStream = nullptr; + if (sourceMapFilename.size()) { + sourceMapStream = make_unique(); + sourceMapStream->open(sourceMapFilename); + writer.setSourceMap(sourceMapStream.get(), sourceMapUrl); } if (symbolMap.size() > 0) writer.setSymbolMap(symbolMap); writer.write(); @@ -108,8 +108,8 @@ int main(int argc, const char *argv[]) { 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 (binaryMapStream) { - binaryMapStream->close(); + if (sourceMapStream) { + sourceMapStream->close(); } if (options.debug) std::cerr << "Done." << std::endl; diff --git a/src/tools/wasm-dis.cpp b/src/tools/wasm-dis.cpp index 2e5aa4ea2ec..e6fd7baddf9 100644 --- a/src/tools/wasm-dis.cpp +++ b/src/tools/wasm-dis.cpp @@ -28,7 +28,7 @@ using namespace cashew; using namespace wasm; int main(int argc, const char *argv[]) { - std::string binaryMapFilename; + 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, @@ -36,9 +36,9 @@ int main(int argc, const char *argv[]) { o->extra["output"] = argument; Colors::disable(); }) - .add("--binarymap-file", "-bm", "Consume binary map from the specified file to add location information", + .add("--source-map", "-sm", "Consume source map from the specified file to add location information", Options::Arguments::One, - [&binaryMapFilename](Options *o, const std::string &argument) { binaryMapFilename = argument; }) + [&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; @@ -50,16 +50,16 @@ int main(int argc, const char *argv[]) { if (options.debug) std::cerr << "parsing binary..." << std::endl; Module wasm; try { - std::unique_ptr binaryMapStream; + std::unique_ptr sourceMapStream; WasmBinaryBuilder parser(wasm, input, options.debug); - if (binaryMapFilename.size()) { - binaryMapStream = make_unique(); - binaryMapStream->open(binaryMapFilename); - parser.setDebugLocations(binaryMapStream.get()); + if (sourceMapFilename.size()) { + sourceMapStream = make_unique(); + sourceMapStream->open(sourceMapFilename); + parser.setDebugLocations(sourceMapStream.get()); } parser.read(); - if (binaryMapStream) { - binaryMapStream->close(); + if (sourceMapStream) { + sourceMapStream->close(); } } catch (ParseException& p) { p.dump(std::cerr); diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b6189c548a7..889a3aa6c90 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -538,8 +538,8 @@ class WasmBinaryWriter : public Visitor { Function* currFunction = nullptr; bool debug; bool debugInfo = true; - std::ostream* binaryMap = nullptr; - std::string binaryMapUrl; + std::ostream* sourceMap = nullptr; + std::string sourceMapUrl; std::string symbolMap; MixedArena allocator; @@ -551,9 +551,9 @@ class WasmBinaryWriter : public Visitor { } void setNamesSection(bool set) { debugInfo = set; } - void setBinaryMap(std::ostream* set, std::string url) { - binaryMap = set; - binaryMapUrl = url; + void setSourceMap(std::ostream* set, std::string url) { + sourceMap = set; + sourceMapUrl = url; } void setSymbolMap(std::string set) { symbolMap = set; } @@ -593,8 +593,8 @@ class WasmBinaryWriter : public Visitor { void writeSourceMapUrl(); void writeSymbolMap(); - void writeBinaryMapProlog(); - void writeBinaryMapEpilog(); + void writeSourceMapProlog(); + void writeSourceMapEpilog(); void writeDebugLocation(size_t offset, const Function::DebugLocation& loc); // helpers @@ -623,8 +623,8 @@ class WasmBinaryWriter : public Visitor { size_t lastBytecodeOffset; void visit(Expression* curr) { - if (binaryMap && currFunction) { - // Dump the binaryMap debug info + if (sourceMap && currFunction) { + // Dump the sourceMap debug info auto& debugLocations = currFunction->debugLocations; auto iter = debugLocations.find(curr); if (iter != debugLocations.end() && iter->second != lastDebugLocation) { @@ -668,7 +668,7 @@ class WasmBinaryBuilder { MixedArena& allocator; std::vector& input; bool debug; - std::istream* binaryMap; + std::istream* sourceMap; std::pair nextDebugLocation; size_t pos = 0; @@ -678,7 +678,7 @@ class WasmBinaryBuilder { std::set seenSections; public: - WasmBinaryBuilder(Module& wasm, std::vector& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug), binaryMap(nullptr), nextDebugLocation(0, { 0, 0, 0 }), useDebugLocation(false) {} + WasmBinaryBuilder(Module& wasm, std::vector& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug), sourceMap(nullptr), nextDebugLocation(0, { 0, 0, 0 }), useDebugLocation(false) {} void read(); void readUserSection(size_t payloadLen); @@ -768,13 +768,13 @@ class WasmBinaryBuilder { void readNames(size_t); // Debug information reading helpers - void setDebugLocations(std::istream* binaryMap_) { - binaryMap = binaryMap_; + void setDebugLocations(std::istream* sourceMap_) { + sourceMap = sourceMap_; } Function::DebugLocation debugLocation; std::unordered_map debugInfoFileIndices; void readNextDebugLocation(); - void readBinaryMapHeader(); + void readSourceMapHeader(); // AST reading int depth = 0; // only for debugging diff --git a/src/wasm-io.h b/src/wasm-io.h index 3a9d1c9959c..afdc4503ce2 100644 --- a/src/wasm-io.h +++ b/src/wasm-io.h @@ -48,15 +48,15 @@ class ModuleWriter : public ModuleIO { bool binary = true; bool debugInfo = false; std::string symbolMap; - std::string binaryMapFilename; - std::string binaryMapUrl; + std::string sourceMapFilename; + std::string sourceMapUrl; public: void setBinary(bool binary_) { binary = binary_; } void setDebugInfo(bool debugInfo_) { debugInfo = debugInfo_; } void setSymbolMap(std::string symbolMap_) { symbolMap = symbolMap_; } - void setBinaryMapFilename(std::string binaryMapFilename_) { binaryMapFilename = binaryMapFilename_; } - void setBinaryMapUrl(std::string binaryMapUrl_) { binaryMapUrl = binaryMapUrl_; } + void setSourceMapFilename(std::string sourceMapFilename_) { sourceMapFilename = sourceMapFilename_; } + void setSourceMapUrl(std::string sourceMapUrl_) { sourceMapUrl = sourceMapUrl_; } // write text void writeText(Module& wasm, std::string filename); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 1f3fa5bd6f7..3e9c549ce53 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -33,8 +33,8 @@ void WasmBinaryWriter::prepare() { void WasmBinaryWriter::write() { writeHeader(); - if (binaryMap) { - writeBinaryMapProlog(); + if (sourceMap) { + writeSourceMapProlog(); } writeTypes(); @@ -49,11 +49,11 @@ void WasmBinaryWriter::write() { writeFunctions(); writeDataSegments(); if (debugInfo) writeNames(); - if (binaryMap) writeSourceMapUrl(); + if (sourceMap) writeSourceMapUrl(); if (symbolMap.size() > 0) writeSymbolMap(); - if (binaryMap) { - writeBinaryMapEpilog(); + if (sourceMap) { + writeSourceMapEpilog(); } finishUp(); } @@ -433,7 +433,7 @@ void WasmBinaryWriter::writeSourceMapUrl() { if (debug) std::cerr << "== writeSourceMapUrl" << std::endl; auto start = startSection(BinaryConsts::Section::User); writeInlineString(BinaryConsts::UserSections::SourceMapUrl); - writeInlineString(binaryMapUrl.c_str()); + writeInlineString(sourceMapUrl.c_str()); finishSection(start); } @@ -450,20 +450,20 @@ void WasmBinaryWriter::writeSymbolMap() { file.close(); } -void WasmBinaryWriter::writeBinaryMapProlog() { +void WasmBinaryWriter::writeSourceMapProlog() { lastDebugLocation = { 0, /* lineNumber = */ 1, 0 }; lastBytecodeOffset = 0; - *binaryMap << "{\"version\":3,\"sources\":["; + *sourceMap << "{\"version\":3,\"sources\":["; for (size_t i = 0; i < wasm->debugInfoFileNames.size(); i++) { - if (i > 0) *binaryMap << ","; + if (i > 0) *sourceMap << ","; // TODO respect JSON string encoding, e.g. quotes and control chars. - *binaryMap << "\"" << wasm->debugInfoFileNames[i] << "\""; + *sourceMap << "\"" << wasm->debugInfoFileNames[i] << "\""; } - *binaryMap << "],\"names\":[],\"mappings\":\""; + *sourceMap << "],\"names\":[],\"mappings\":\""; } -void WasmBinaryWriter::writeBinaryMapEpilog() { - *binaryMap << "\"}"; +void WasmBinaryWriter::writeSourceMapEpilog() { + *sourceMap << "\"}"; } static void writeBase64VLQ(std::ostream& out, int32_t n) { @@ -484,12 +484,12 @@ static void writeBase64VLQ(std::ostream& out, int32_t n) { void WasmBinaryWriter::writeDebugLocation(size_t offset, const Function::DebugLocation& loc) { if (lastBytecodeOffset > 0) { - *binaryMap << ","; + *sourceMap << ","; } - writeBase64VLQ(*binaryMap, int32_t(offset - lastBytecodeOffset)); - writeBase64VLQ(*binaryMap, int32_t(loc.fileIndex - lastDebugLocation.fileIndex)); - writeBase64VLQ(*binaryMap, int32_t(loc.lineNumber - lastDebugLocation.lineNumber)); - writeBase64VLQ(*binaryMap, int32_t(loc.columnNumber - lastDebugLocation.columnNumber)); + writeBase64VLQ(*sourceMap, int32_t(offset - lastBytecodeOffset)); + writeBase64VLQ(*sourceMap, int32_t(loc.fileIndex - lastDebugLocation.fileIndex)); + writeBase64VLQ(*sourceMap, int32_t(loc.lineNumber - lastDebugLocation.lineNumber)); + writeBase64VLQ(*sourceMap, int32_t(loc.columnNumber - lastDebugLocation.columnNumber)); lastDebugLocation = loc; lastBytecodeOffset = offset; } @@ -998,7 +998,7 @@ static Name RETURN_BREAK("binaryen|break-to-return"); void WasmBinaryBuilder::read() { readHeader(); - readBinaryMapHeader(); + readSourceMapHeader(); // read sections until the end while (more()) { @@ -1476,16 +1476,16 @@ static int32_t readBase64VLQ(std::istream& in) { return value & 1 ? -int32_t(value >> 1) : int32_t(value >> 1); } -void WasmBinaryBuilder::readBinaryMapHeader() { - if (!binaryMap) return; +void WasmBinaryBuilder::readSourceMapHeader() { + if (!sourceMap) return; auto maybeReadChar = [&](char expected) { - if (binaryMap->peek() != expected) return false; - binaryMap->get(); + if (sourceMap->peek() != expected) return false; + sourceMap->get(); return true; }; auto mustReadChar = [&](char expected) { - if (binaryMap->get() != expected) { + if (sourceMap->get() != expected) { throw MapParseException("Unexpected char"); } }; @@ -1493,7 +1493,7 @@ void WasmBinaryBuilder::readBinaryMapHeader() { bool matching = false; size_t pos; while (1) { - int ch = binaryMap->get(); + int ch = sourceMap->get(); if (ch == EOF) return false; if (ch == '\"') { matching = true; @@ -1515,7 +1515,7 @@ void WasmBinaryBuilder::readBinaryMapHeader() { mustReadChar('\"'); if (!maybeReadChar('\"')) { while (1) { - int ch = binaryMap->get(); + int ch = sourceMap->get(); if (ch == EOF) { throw MapParseException("unexpected EOF in the middle of string"); } @@ -1550,18 +1550,18 @@ void WasmBinaryBuilder::readBinaryMapHeader() { return; } // read first debug location - uint32_t position = readBase64VLQ(*binaryMap); - uint32_t fileIndex = readBase64VLQ(*binaryMap); - uint32_t lineNumber = readBase64VLQ(*binaryMap) + 1; // adjust zero-based line number - uint32_t columnNumber = readBase64VLQ(*binaryMap); + uint32_t position = readBase64VLQ(*sourceMap); + uint32_t fileIndex = readBase64VLQ(*sourceMap); + uint32_t lineNumber = readBase64VLQ(*sourceMap) + 1; // adjust zero-based line number + uint32_t columnNumber = readBase64VLQ(*sourceMap); nextDebugLocation = { position, { fileIndex, lineNumber, columnNumber } }; } void WasmBinaryBuilder::readNextDebugLocation() { - if (!binaryMap) return; + if (!sourceMap) return; char ch; - *binaryMap >> ch; + *sourceMap >> ch; if (ch == '\"') { // end of records nextDebugLocation.first = 0; return; @@ -1569,13 +1569,14 @@ void WasmBinaryBuilder::readNextDebugLocation() { if (ch != ',') { throw MapParseException("Unexpected delimiter"); } - int32_t positionDelta = readBase64VLQ(*binaryMap); + + int32_t positionDelta = readBase64VLQ(*sourceMap); uint32_t position = nextDebugLocation.first + positionDelta; - int32_t fileIndexDelta = readBase64VLQ(*binaryMap); + int32_t fileIndexDelta = readBase64VLQ(*sourceMap); uint32_t fileIndex = nextDebugLocation.second.fileIndex + fileIndexDelta; - int32_t lineNumberDelta = readBase64VLQ(*binaryMap); + int32_t lineNumberDelta = readBase64VLQ(*sourceMap); uint32_t lineNumber = nextDebugLocation.second.lineNumber + lineNumberDelta; - int32_t columnNumberDelta = readBase64VLQ(*binaryMap); + int32_t columnNumberDelta = readBase64VLQ(*sourceMap); uint32_t columnNumber = nextDebugLocation.second.columnNumber + columnNumberDelta; nextDebugLocation = { position, { fileIndex, lineNumber, columnNumber } }; diff --git a/src/wasm/wasm-io.cpp b/src/wasm/wasm-io.cpp index 9d2ce29a356..ebc9af8deba 100644 --- a/src/wasm/wasm-io.cpp +++ b/src/wasm/wasm-io.cpp @@ -74,18 +74,18 @@ void ModuleWriter::writeBinary(Module& wasm, std::string filename) { WasmBinaryWriter writer(&wasm, buffer, debug); // if debug info is used, then we want to emit the names section writer.setNamesSection(debugInfo); - std::unique_ptr binaryMapStream; - if (binaryMapFilename.size()) { - binaryMapStream = make_unique(); - binaryMapStream->open(binaryMapFilename); - writer.setBinaryMap(binaryMapStream.get(), binaryMapUrl); + std::unique_ptr sourceMapStream; + if (sourceMapFilename.size()) { + sourceMapStream = make_unique(); + sourceMapStream->open(sourceMapFilename); + writer.setSourceMap(sourceMapStream.get(), sourceMapUrl); } if (symbolMap.size() > 0) writer.setSymbolMap(symbolMap); writer.write(); Output output(filename, Flags::Binary, debug ? Flags::Debug : Flags::Release); buffer.writeTo(output); - if (binaryMapStream) { - binaryMapStream->close(); + if (sourceMapStream) { + sourceMapStream->close(); } }