diff options
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 7a0a08885..51325e7dd 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1638,8 +1638,8 @@ void WasmBinaryWriter::writeField(const Field& field) { WasmBinaryReader::WasmBinaryReader(Module& wasm, FeatureSet features, const std::vector<char>& input) - : wasm(wasm), allocator(wasm.allocator), input(input), - sourceMap(nullptr), nextDebugLocation{0, 0, {0, 0, 0}}, + : wasm(wasm), allocator(wasm.allocator), input(input), sourceMap(nullptr), + nextDebugPos(0), nextDebugLocation{0, 0, 0}, nextDebugLocationHasDebugInfo(false), debugLocation() { wasm.features = features; } @@ -2796,7 +2796,7 @@ void WasmBinaryReader::readSourceMapHeader() { mustReadChar('\"'); if (maybeReadChar('\"')) { // empty mappings - nextDebugLocation.availablePos = 0; + nextDebugPos = 0; return; } // read first debug location @@ -2809,8 +2809,8 @@ void WasmBinaryReader::readSourceMapHeader() { uint32_t lineNumber = readBase64VLQ(*sourceMap) + 1; // adjust zero-based line number uint32_t columnNumber = readBase64VLQ(*sourceMap); - nextDebugLocation = { - position, position, {fileIndex, lineNumber, columnNumber}}; + nextDebugPos = position; + nextDebugLocation = {fileIndex, lineNumber, columnNumber}; nextDebugLocationHasDebugInfo = true; } @@ -2819,21 +2819,18 @@ void WasmBinaryReader::readNextDebugLocation() { return; } - if (nextDebugLocation.availablePos == 0 && - nextDebugLocation.previousPos <= pos) { - // if source map file had already reached the end and cache position also - // cannot cover the pos clear the debug location + if (nextDebugPos == 0) { + // We reached the end of the source map; nothing left to read. debugLocation.clear(); return; } - while (nextDebugLocation.availablePos && - nextDebugLocation.availablePos <= pos) { + while (nextDebugPos && nextDebugPos <= pos) { debugLocation.clear(); // use debugLocation only for function expressions if (currFunction) { if (nextDebugLocationHasDebugInfo) { - debugLocation.insert(nextDebugLocation.next); + debugLocation.insert(nextDebugLocation); } else { debugLocation.clear(); } @@ -2842,7 +2839,7 @@ void WasmBinaryReader::readNextDebugLocation() { char ch; *sourceMap >> ch; if (ch == '\"') { // end of records - nextDebugLocation.availablePos = 0; + nextDebugPos = 0; break; } if (ch != ',') { @@ -2850,10 +2847,9 @@ void WasmBinaryReader::readNextDebugLocation() { } int32_t positionDelta = readBase64VLQ(*sourceMap); - uint32_t position = nextDebugLocation.availablePos + positionDelta; + uint32_t position = nextDebugPos + positionDelta; - nextDebugLocation.previousPos = nextDebugLocation.availablePos; - nextDebugLocation.availablePos = position; + nextDebugPos = position; auto peek = sourceMap->peek(); if (peek == ',' || peek == '\"') { @@ -2863,14 +2859,13 @@ void WasmBinaryReader::readNextDebugLocation() { } int32_t fileIndexDelta = readBase64VLQ(*sourceMap); - uint32_t fileIndex = nextDebugLocation.next.fileIndex + fileIndexDelta; + uint32_t fileIndex = nextDebugLocation.fileIndex + fileIndexDelta; int32_t lineNumberDelta = readBase64VLQ(*sourceMap); - uint32_t lineNumber = nextDebugLocation.next.lineNumber + lineNumberDelta; + uint32_t lineNumber = nextDebugLocation.lineNumber + lineNumberDelta; int32_t columnNumberDelta = readBase64VLQ(*sourceMap); - uint32_t columnNumber = - nextDebugLocation.next.columnNumber + columnNumberDelta; + uint32_t columnNumber = nextDebugLocation.columnNumber + columnNumberDelta; - nextDebugLocation.next = {fileIndex, lineNumber, columnNumber}; + nextDebugLocation = {fileIndex, lineNumber, columnNumber}; nextDebugLocationHasDebugInfo = true; } } |