diff options
author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2024-10-01 23:39:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-01 14:39:34 -0700 |
commit | 347fc8a57dcfd9361b05f271a7f2badc929500cf (patch) | |
tree | 362a40ae7bc9bcb9e8c40967505d3414691f6af6 /src/parser | |
parent | cb53f0c6966fe7c8e5cc1a975eab9653b5914bde (diff) | |
download | binaryen-347fc8a57dcfd9361b05f271a7f2badc929500cf.tar.gz binaryen-347fc8a57dcfd9361b05f271a7f2badc929500cf.tar.bz2 binaryen-347fc8a57dcfd9361b05f271a7f2badc929500cf.zip |
Source Maps: Support 5 segment mappings (#6795)
Support 5-segment source mappings, which add a name.
Reference:
https://github.com/tc39/source-map/blob/main/source-map-rev3.md#proposed-format
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/contexts.h | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index 387cb146e..b0cd1458b 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -1398,6 +1398,7 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { typeNames; const std::unordered_map<Index, Index>& implicitElemIndices; + std::unordered_map<std::string_view, Index> debugSymbolNameIndices; std::unordered_map<std::string_view, Index> debugFileIndices; // The index of the current module element. @@ -1777,12 +1778,32 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { } contents = contents.substr(lineSize + 1); - lexer = Lexer(contents); + auto colSize = contents.find(':'); + if (colSize == contents.npos) { + colSize = contents.size(); + if (colSize == 0) { + return; + } + } + lexer = Lexer(contents.substr(0, colSize)); auto col = lexer.takeU32(); - if (!col || !lexer.empty()) { + if (!col) { return; } + std::optional<BinaryLocation> symbolNameIndex; + if (colSize != contents.size()) { + contents = contents.substr(colSize + 1); + auto symbolName = contents; + auto [it, inserted] = debugSymbolNameIndices.insert( + {symbolName, debugSymbolNameIndices.size()}); + if (inserted) { + assert(wasm.debugInfoSymbolNames.size() == it->second); + wasm.debugInfoSymbolNames.push_back(std::string(symbolName)); + } + symbolNameIndex = it->second; + } + // TODO: If we ever parallelize the parse, access to // `wasm.debugInfoFileNames` will have to be protected by a lock. auto [it, inserted] = @@ -1792,7 +1813,7 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { wasm.debugInfoFileNames.push_back(std::string(file)); } irBuilder.setDebugLocation( - Function::DebugLocation({it->second, *line, *col})); + Function::DebugLocation({it->second, *line, *col, symbolNameIndex})); } Result<> makeBlock(Index pos, |