summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-artifact-container-util.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-04-17 15:09:37 -0400
committerGitHub <noreply@github.com>2023-04-17 15:09:37 -0400
commit90a9f43573ec0777c2ae4fa20c8fdc51a4ae7b3a (patch)
tree360750778be872a086674024a9ce5a68bf4e7cb3 /source/compiler-core/slang-artifact-container-util.cpp
parenta3f622ace1bdef1f1a4150ec85d1328d1a589333 (diff)
Round trip source map (#2810)
* #include an absolute path didn't work - because paths were taken to always be relative. * Make output of obfuscation locs work in a slang-module. * Tidy up detection for writing serialized source locs. * Support for .zip references. Handling of obfuscated source maps read from containers. A test to check obfuscated source map working on a module. * When using obfuscation, always obfuscate locs instead of stripping them. We keep a source map, so we can still produce reasonable errors. * Write out source locs if debug information is enabled. * Check output without sourcemap. * Small fixes. * Small improvements around hash calculation for source map name. * Disable test that fails on x86 gcc linux for now. * Fix issues around obfuscated source map using lines rather than columns. Fix some issues around encoding/decoding. * Make column calculation of source locs take into account utf8/tabs. Don't special case obfuscated source map for lookup for source loc. * Support following multiple source maps. * Small fixes/improvements around SourceMap lookup.
Diffstat (limited to 'source/compiler-core/slang-artifact-container-util.cpp')
-rw-r--r--source/compiler-core/slang-artifact-container-util.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/source/compiler-core/slang-artifact-container-util.cpp b/source/compiler-core/slang-artifact-container-util.cpp
index 29e2e736e..6121df964 100644
--- a/source/compiler-core/slang-artifact-container-util.cpp
+++ b/source/compiler-core/slang-artifact-container-util.cpp
@@ -626,7 +626,6 @@ SlangResult ArtifactContainerReader::read(ISlangFileSystemExt* fileSystem, ComPt
return _readArtifactDirectory(0, outArtifact);
}
-
SlangResult ArtifactContainerReader::_readFile(Index fileIndex, ComPtr<IArtifact>& outArtifact)
{
outArtifact.setNull();
@@ -655,6 +654,19 @@ SlangResult ArtifactContainerReader::_readFile(Index fileIndex, ComPtr<IArtifact
return SLANG_OK;
}
+ // We don't have manifest, so for now well assume if the name ends in "-obfuscated" and it's a source map
+ // it's an obfuscated one
+ if (desc.kind == ArtifactKind::Json &&
+ desc.payload == ArtifactPayload::SourceMap)
+ {
+ auto name = Path::getFileNameWithoutExt(entry.name);
+
+ if (name.endsWith(toSlice("-obfuscated")))
+ {
+ desc.style = ArtifactStyle::Obfuscated;
+ }
+ }
+
// I guess I can just make an artifact for this
auto artifact = ArtifactUtil::createArtifact(desc);
@@ -781,6 +793,40 @@ SlangResult ArtifactContainerReader::_readArtifactDirectory(Index directoryIndex
return SLANG_OK;
}
+SlangResult ArtifactContainerUtil::readContainer(IArtifact* artifact, ComPtr<IArtifact>& outArtifact)
+{
+ auto desc = artifact->getDesc();
+
+ ComPtr<ISlangMutableFileSystem> fileSystem;
+
+ switch (desc.kind)
+ {
+ case ArtifactKind::Zip:
+ {
+ SLANG_RETURN_ON_FAIL(ZipFileSystem::create(fileSystem));
+
+ ComPtr<ISlangBlob> blob;
+ SLANG_RETURN_ON_FAIL(artifact->loadBlob(ArtifactKeep::No, blob.writeRef()));
+
+ // Load into the zip
+
+ // Now write out to the output file
+ IArchiveFileSystem* archiveFileSystem = as<IArchiveFileSystem>(fileSystem);
+ SLANG_ASSERT(archiveFileSystem);
+
+ SLANG_RETURN_ON_FAIL(archiveFileSystem->loadArchive(blob->getBufferPointer(), blob->getBufferSize()));
+ break;
+ }
+ default:
+ {
+ return SLANG_FAIL;
+ }
+ }
+
+ SLANG_RETURN_ON_FAIL(readContainer(fileSystem, outArtifact));
+ return SLANG_OK;
+}
+
/* static */SlangResult ArtifactContainerUtil::readContainer(ISlangFileSystemExt* fileSystem, ComPtr<IArtifact>& outArtifact)
{
SLANG_UNUSED(outArtifact);