summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-03-24 09:56:59 -0400
committerGitHub <noreply@github.com>2023-03-24 09:56:59 -0400
commite794de0d63e6de9be564c971fd40486ecf631293 (patch)
tree903bd4100fd9c259d68f2893c61a36880e182f14 /source/compiler-core
parent03c10833beb331e234554808c2a80d3cadecc7c0 (diff)
Obfuscated source map writing (#2727)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP produce obfuscated source map and write when container is specified. * Make the sourcemap generated name stable.
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-artifact-desc-util.cpp20
-rw-r--r--source/compiler-core/slang-source-map.cpp50
-rw-r--r--source/compiler-core/slang-source-map.h14
3 files changed, 47 insertions, 37 deletions
diff --git a/source/compiler-core/slang-artifact-desc-util.cpp b/source/compiler-core/slang-artifact-desc-util.cpp
index 08b7c8412..ca7dcb70f 100644
--- a/source/compiler-core/slang-artifact-desc-util.cpp
+++ b/source/compiler-core/slang-artifact-desc-util.cpp
@@ -710,6 +710,26 @@ SlangResult ArtifactDescUtil::appendDefaultExtension(const ArtifactDesc& desc, S
// Don't know the extension for that
return SLANG_E_NOT_FOUND;
}
+ case ArtifactKind::Json:
+ {
+ auto ext = _getPayloadExtension(desc.payload);
+ if (ext.begin() != nullptr)
+ {
+ // TODO(JS):
+ // Do we need to alter the extension or the name if it's an
+ // obfuscated map?
+ //if (isDerivedFrom(desc.style, ArtifactStyle::Obfuscated))
+ //{
+ //}
+
+ out << ext;
+ return SLANG_OK;
+ }
+
+ // Not really what kind of json, so just use 'generic' json extension
+ out << "json";
+ return SLANG_OK;
+ }
default: break;
}
diff --git a/source/compiler-core/slang-source-map.cpp b/source/compiler-core/slang-source-map.cpp
index 830314008..1dd0fe8a5 100644
--- a/source/compiler-core/slang-source-map.cpp
+++ b/source/compiler-core/slang-source-map.cpp
@@ -201,7 +201,7 @@ void SourceMap::clear()
void SourceMap::advanceToLine(Index nextLineIndex)
{
- const Count currentLineIndex = getGeneratedLineCount();
+ const Count currentLineIndex = getGeneratedLineCount() - 1;
SLANG_ASSERT(nextLineIndex >= currentLineIndex);
@@ -215,24 +215,13 @@ void SourceMap::advanceToLine(Index nextLineIndex)
// 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)
+ Index* starts = m_lineStarts.getBuffer();
+ for (Index i = currentLineIndex + 1; i < nextLineIndex + 1; ++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;
@@ -284,33 +273,30 @@ SlangResult SourceMap::decode(JSONContainer* container, JSONValue root, Diagnost
clear();
// Let's try and decode the JSON into native types to make this easier...
-
RttiTypeFuncsMap typeMap = JSONNativeUtil::getTypeFuncsMap();
// Convert to native
- JSONSourceMap src;
+ JSONSourceMap native;
{
JSONToNativeConverter converter(container, &typeMap, sink);
// Convert to the native type
- SLANG_RETURN_ON_FAIL(converter.convert(root, GetRttiInfo<JSONSourceMap>::get(), &src));
+ SLANG_RETURN_ON_FAIL(converter.convert(root, GetRttiInfo<JSONSourceMap>::get(), &native));
}
- m_slicePool.clear();
-
- m_file = src.file;
- m_sourceRoot = src.sourceRoot;
+ m_file = native.file;
+ m_sourceRoot = native.sourceRoot;
- const Count sourcesCount = src.sources.getCount();
+ const Count sourcesCount = native.sources.getCount();
// These should all be unique, but for simplicity, we build a table
m_sources.setCount(sourcesCount);
for (Index i = 0; i < sourcesCount; ++i)
{
- m_sources[i] = m_slicePool.add(src.sources[i]);
+ m_sources[i] = m_slicePool.add(native.sources[i]);
}
- Count sourcesContentCount = src.sourcesContent.getCount();
+ Count sourcesContentCount = native.sourcesContent.getCount();
sourcesContentCount = std::min(sourcesContentCount, sourcesCount);
m_sourcesContent.setCount(sourcesContentCount);
@@ -321,7 +307,7 @@ SlangResult SourceMap::decode(JSONContainer* container, JSONValue root, Diagnost
for (Index i = 0; i < sourcesContentCount; ++i)
{
- auto value = src.sourcesContent[i];
+ auto value = native.sourcesContent[i];
if (value.type != JSONValue::Type::Null)
{
@@ -334,7 +320,7 @@ SlangResult SourceMap::decode(JSONContainer* container, JSONValue root, Diagnost
}
List<UnownedStringSlice> lines;
- StringUtil::split(src.mappings, ';', lines);
+ StringUtil::split(native.mappings, ';', lines);
List<UnownedStringSlice> segments;
@@ -378,10 +364,10 @@ SlangResult SourceMap::decode(JSONContainer* container, JSONValue root, Diagnost
// It can be 4 or 5 parts
if (segment.getLength())
{
- /* If present, an zero-based index into the “sources” list. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented.
- If present, the zero-based starting line in the original source represented. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented. Always present if there is a source field.
- If present, the zero-based starting column of the line in the source represented. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented. Always present if there is a source field.
- */
+ /* If present, an zero-based index into the "sources" list. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented.
+ If present, the zero-based starting line in the original source represented. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented. Always present if there is a source field.
+ If present, the zero-based starting column of the line in the source represented. This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented. Always present if there is a source field.
+ */
Index sourceFileDelta;
Index sourceLineDelta;
@@ -402,7 +388,9 @@ SlangResult SourceMap::decode(JSONContainer* container, JSONValue root, Diagnost
// 5 parts
if (segment.getLength() > 0)
{
- /* If present, the zero - based index into the “names” list associated with this segment.This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence of this field, in which case the whole value is represented.
+ /* If present, the zero - based index into the "names" list associated with this segment.
+ This field is a base 64 VLQ relative to the previous occurrence of this field, unless this is the first occurrence
+ of this field, in which case the whole value is represented.
*/
Index nameDelta;
diff --git a/source/compiler-core/slang-source-map.h b/source/compiler-core/slang-source-map.h
index 739cf1992..accd2473f 100644
--- a/source/compiler-core/slang-source-map.h
+++ b/source/compiler-core/slang-source-map.h
@@ -43,7 +43,7 @@ struct SourceMap : public RefObject
SlangResult encode(JSONContainer* container, DiagnosticSink* sink, JSONValue& outValue);
/// Get the total number of generated lines
- Count getGeneratedLineCount() const { return m_lineStarts.getCount() - 1; }
+ Count getGeneratedLineCount() const { return m_lineStarts.getCount(); }
/// Get the entries on the line
SLANG_FORCE_INLINE ConstArrayView<Entry> getEntriesForLine(Index generatedLine) const;
@@ -53,7 +53,7 @@ struct SourceMap : public RefObject
void advanceToLine(Index lineIndex);
/// Add an entry to the current line
- void addEntry(const Entry& entry);
+ void addEntry(const Entry& entry) { m_lineEntries.add(entry); }
/// Given the slice returns the index
Index getSourceFileIndex(const UnownedStringSlice& slice);
@@ -91,18 +91,20 @@ struct SourceMap : public RefObject
// -------------------------------------------------------------
SLANG_FORCE_INLINE ConstArrayView<SourceMap::Entry> SourceMap::getEntriesForLine(Index generatedLine) const
{
+ SLANG_ASSERT(generatedLine >= 0 && generatedLine < m_lineStarts.getCount());
+
const Index start = m_lineStarts[generatedLine];
- const Index end = m_lineStarts[generatedLine + 1];
-
+
+ const Index end = (generatedLine + 1 >= m_lineStarts.getCount()) ? m_lineEntries.getCount() : m_lineStarts[generatedLine + 1];
+
const auto entries = m_lineEntries.begin();
- SLANG_ASSERT(start >= 0 && start < m_lineEntries.getCount());
+ SLANG_ASSERT(start >= 0 && start <= m_lineEntries.getCount());
SLANG_ASSERT(end >= start && end >= 0 && end <= m_lineEntries.getCount());
return ConstArrayView<SourceMap::Entry>(entries + start, end - start);
}
-
} // namespace Slang
#endif // SLANG_COMPILER_CORE_SOURCE_MAP_H