From 8a61b9dd0ca729df894dad4c89c6ce3bf39ef0be Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 17 Mar 2023 11:05:15 -0400 Subject: Support for producing SourceMap on emit (#2707) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP source map. * Split out handling of RttiTypeFuncs to a map type. * Make RttiTypeFuncsMap hold default impls. * Slightly more sophisticated RttiTypeFuncsMap * Source map decoding. * Fix tabs. * Fix asserts due to negative values. * Use less obscure mechanisms in SourceMap. * Source map decoding. Simplifying SourceMap usage. * First attempt at ouputting a source map as part of emit. * Added support for -source-map option. SourceMap is added to the artifact. --- source/compiler-core/slang-source-map.cpp | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'source/compiler-core/slang-source-map.cpp') diff --git a/source/compiler-core/slang-source-map.cpp b/source/compiler-core/slang-source-map.cpp index 413c32108..830314008 100644 --- a/source/compiler-core/slang-source-map.cpp +++ b/source/compiler-core/slang-source-map.cpp @@ -199,6 +199,86 @@ void SourceMap::clear() m_slicePool.clear(); } +void SourceMap::advanceToLine(Index nextLineIndex) +{ + const Count currentLineIndex = getGeneratedLineCount(); + + SLANG_ASSERT(nextLineIndex >= currentLineIndex); + + if (nextLineIndex <= currentLineIndex) + { + return; + } + + const auto lastEntryIndex = m_lineEntries.getCount(); + + // For all the new entries they will need to point to the end + m_lineStarts.setCount(nextLineIndex + 1); + + Index* starts = m_lineStarts.getBuffer() + currentLineIndex; + const Count startsCount = nextLineIndex + 1 - currentLineIndex; + + for (Index i = 0; i < startsCount; ++i) + { + starts[i] = lastEntryIndex; + } +} + +void SourceMap::addEntry(const Entry& entry) +{ + m_lineEntries.add(entry); + ++m_lineStarts.getLast(); + + // Check things seem normal... + SLANG_ASSERT(m_lineStarts.getLast() == m_lineEntries.getCount()); +} + +Index SourceMap::getNameIndex(const UnownedStringSlice& slice) +{ + StringSlicePool::Handle handle; + + if (!m_slicePool.findOrAdd(slice, handle)) + { + // We know it can't possibly be used, so must be new (!) + + m_names.add(handle); + return m_names.getCount() - 1; + } + + // Okay, could already be in the list + const auto index = m_names.indexOf(handle); + if (index >= 0) + { + return index; + } + + m_names.add(handle); + return m_names.getCount() - 1; +} + +Index SourceMap::getSourceFileIndex(const UnownedStringSlice& slice) +{ + StringSlicePool::Handle handle; + + if (!m_slicePool.findOrAdd(slice, handle)) + { + // We know it can't possibly be used, so must be new (!) + + m_sources.add(handle); + return m_sources.getCount() - 1; + } + + // Okay, could already be in the list + const auto index = m_sources.indexOf(handle); + if (index >= 0) + { + return index; + } + + m_sources.add(handle); + return m_sources.getCount() - 1; +} + SlangResult SourceMap::decode(JSONContainer* container, JSONValue root, DiagnosticSink* sink) { clear(); -- cgit v1.2.3