summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-source-map.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-03-17 11:05:15 -0400
committerGitHub <noreply@github.com>2023-03-17 11:05:15 -0400
commit8a61b9dd0ca729df894dad4c89c6ce3bf39ef0be (patch)
treeb7f3da5d30772ba1497f14cdeb39935225183bbb /source/compiler-core/slang-source-map.cpp
parent9476d4543f4336a66308e55f722b0b0b2bd69dd2 (diff)
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.
Diffstat (limited to 'source/compiler-core/slang-source-map.cpp')
-rw-r--r--source/compiler-core/slang-source-map.cpp80
1 files changed, 80 insertions, 0 deletions
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();