From 347fc8a57dcfd9361b05f271a7f2badc929500cf Mon Sep 17 00:00:00 2001 From: Ömer Sinan Ağacan Date: Tue, 1 Oct 2024 23:39:34 +0200 Subject: 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 --- src/parser/contexts.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/parser/contexts.h') 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 { typeNames; const std::unordered_map& implicitElemIndices; + std::unordered_map debugSymbolNameIndices; std::unordered_map debugFileIndices; // The index of the current module element. @@ -1777,12 +1778,32 @@ struct ParseDefsCtx : TypeParserCtx { } 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 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 { 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, -- cgit v1.2.3