diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-07-18 18:45:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-18 15:45:38 -0700 |
| commit | 1fe5e83f3dcc8ef0efa2dd083ebdfab5d0f101a9 (patch) | |
| tree | 9ea88993d0b1f5cad76c21ae3a60ed561bdc3c83 /source/compiler-core/slang-source-loc.cpp | |
| parent | 4cb3eeb832b5fb29a61f2934b3daa5e42a3d6cde (diff) | |
nsight Aftermath crash example (#2984)
* Small fixes and improvements around reflection tool.
* Make PrettyWriter printing a class.
* Aftermath crash demo WIP.
* Enable aftermath in test project.
* Setting failCount.
* Dumping out of source maps.
* Improve comments.
Simplify handling of compile products.
* Other small fixes to aftermath example.
* Added Emit SourceLocType.
Track sourcemap association meaning.
Improved documentation.
* Small improvements.
* Capture debug information for D3D11/D3D12/Vulkan.
* Enable debug info.
* Small improvements.
* Improve aftermath example README.md.
Diffstat (limited to 'source/compiler-core/slang-source-loc.cpp')
| -rw-r--r-- | source/compiler-core/slang-source-loc.cpp | 100 |
1 files changed, 75 insertions, 25 deletions
diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp index 8710cf91f..f9014e0d8 100644 --- a/source/compiler-core/slang-source-loc.cpp +++ b/source/compiler-core/slang-source-loc.cpp @@ -190,12 +190,41 @@ void SourceView::addDefaultLineDirective(SourceLoc directiveLoc) m_entries.add(entry); } -SlangResult _findLocWithSourceMap(SourceManager* lookupSourceManager, SourceView* sourceView, SourceLoc loc, HandleSourceLoc& outLoc) +// Nominal-like types take into account line directives, and potentially source maps +static bool _isNominalLike(SourceLocType type) +{ + return type == SourceLocType::Nominal || type == SourceLocType::Emit; +} + +static bool _canFollowSourceMap(SourceFile* sourceFile, SourceLocType type) +{ + // If we don't have a source map we have nothing to follow + if (!sourceFile->getSourceMap()) + { + return false; + } + + // If it's obfuscated we can't follow if we are emitting + if (sourceFile->getSourceMapKind() == SourceMapKind::Obfuscated && + type == SourceLocType::Emit) + { + return false; + } + + return _isNominalLike(type); +} + +static SlangResult _findLocWithSourceMap(SourceManager* lookupSourceManager, SourceView* sourceView, SourceLoc loc, SourceLocType type, HandleSourceLoc& outLoc) { auto sourceFile = sourceView->getSourceFile(); + if (!_canFollowSourceMap(sourceFile, type)) + { + return SLANG_E_NOT_FOUND; + } + // Hold a list of sourceFiles visited so we can't end up in a loop of lookups - List<SourceFile*> sourceFiles; + ShortList<SourceFile*, 8> sourceFiles; sourceFiles.add(sourceFile); Index entryIndex = -1; @@ -240,8 +269,10 @@ SlangResult _findLocWithSourceMap(SourceManager* lookupSourceManager, SourceView sourceFiles.add(foundSourceFile); // If it has a source map, we try and look up the current location in it's source map - if (auto foundSourceMap = foundSourceFile->getSourceMap()) + if (_canFollowSourceMap(foundSourceFile, type)) { + auto foundSourceMap = foundSourceFile->getSourceMap(); + const auto foundEntryIndex = foundSourceMap->get().findEntry(entry.sourceLine, entry.sourceColumn); // If we found the entry repeat the lookup @@ -273,18 +304,30 @@ SlangResult _findLocWithSourceMap(SourceManager* lookupSourceManager, SourceView return SLANG_OK; } -HandleSourceLoc SourceView::getHandleLoc(SourceLoc loc, SourceLocType type) + +SlangResult SourceView::_findSourceMapLoc(SourceLoc loc, SourceLocType type, HandleSourceLoc& outLoc) { - // If it's nominal - if (type == SourceLocType::Nominal && m_sourceFile->getSourceMap()) + // We only do source map lookups with nominal + if (!_isNominalLike(type)) { - // TODO(JS): - // Ideally we'd do the lookup on the "current" source manager rather than the source manager on this - // view, which may be a parent to the current one. - auto lookupSourceManager = m_sourceFile->getSourceManager(); + return SLANG_E_NOT_FOUND; + } - HandleSourceLoc handleLoc; - if (SLANG_SUCCEEDED(_findLocWithSourceMap(lookupSourceManager, this, loc, handleLoc))) + // TODO(JS): + // Ideally we'd do the lookup on the "current" source manager rather than the source manager on this + // view, which may be a parent to the current one. + auto lookupSourceManager = m_sourceFile->getSourceManager(); + + HandleSourceLoc handleLoc; + SLANG_RETURN_ON_FAIL(_findLocWithSourceMap(lookupSourceManager, this, loc, type, outLoc)); + + return SLANG_OK; +} + +HandleSourceLoc SourceView::getHandleLoc(SourceLoc loc, SourceLocType type) +{ + { HandleSourceLoc handleLoc; + if (SLANG_SUCCEEDED(_findSourceMapLoc(loc, type, handleLoc))) { return handleLoc; } @@ -307,22 +350,21 @@ HandleSourceLoc SourceView::getHandleLoc(SourceLoc loc, SourceLocType type) HandleSourceLoc handleLoc; handleLoc.column = columnIndex + 1; handleLoc.line = lineIndex + 1; - - // Make up a default entry - StringSlicePool::Handle pathHandle = StringSlicePool::Handle(0); - - // Only bother looking up the entry information if we want a 'Normal' lookup - const int entryIndex = (type == SourceLocType::Nominal) ? findEntryIndex(loc) : -1; - if (entryIndex >= 0) + + // Only bother looking up the entry information if we want a 'Norminal'-like lookup + if (_isNominalLike(type)) { - const Entry& entry = m_entries[entryIndex]; - // Adjust the line - handleLoc.line += entry.m_lineAdjust; - // Get the pathHandle.. - pathHandle = entry.m_pathHandle; + const int entryIndex = findEntryIndex(loc); + if (entryIndex >= 0) + { + const Entry& entry = m_entries[entryIndex]; + // Adjust the line + handleLoc.line += entry.m_lineAdjust; + // Get the pathHandle.. + handleLoc.pathHandle = entry.m_pathHandle; + } } - handleLoc.pathHandle = pathHandle; return handleLoc; } @@ -371,6 +413,14 @@ PathInfo SourceView::getPathInfo(SourceLoc loc, SourceLocType type) return getViewPathInfo(); } + { + HandleSourceLoc handleLoc; + if (SLANG_SUCCEEDED(_findSourceMapLoc(loc, type, handleLoc))) + { + return _getPathInfoFromHandle(handleLoc.pathHandle); + } + } + const int entryIndex = findEntryIndex(loc); return _getPathInfoFromHandle((entryIndex >= 0) ? m_entries[entryIndex].m_pathHandle : StringSlicePool::Handle(0)); } |
