diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-04-17 15:09:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-17 15:09:37 -0400 |
| commit | 90a9f43573ec0777c2ae4fa20c8fdc51a4ae7b3a (patch) | |
| tree | 360750778be872a086674024a9ce5a68bf4e7cb3 /source/slang/slang.cpp | |
| parent | a3f622ace1bdef1f1a4150ec85d1328d1a589333 (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/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 89 |
1 files changed, 82 insertions, 7 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 4904abe03..c8cda0dca 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -15,6 +15,8 @@ #include "../compiler-core/slang-artifact-associated-impl.h" #include "../compiler-core/slang-artifact-container-util.h" +#include "../compiler-core/slang-json-source-map-util.h" + #include "../core/slang-memory-file-system.h" #include "slang-module-library.h" @@ -4833,10 +4835,85 @@ void EndToEndCompileRequest::setDefaultModuleName(const char* defaultModuleName) frontEndReq->m_defaultModuleName = namePool->getName(defaultModuleName); } +SlangResult _addLibraryReference(EndToEndCompileRequest* req, IArtifact* artifact, ModuleLibrary* moduleLibrary) +{ + FrontEndCompileRequest* frontEndRequest = req->getFrontEndReq(); + frontEndRequest->m_extraEntryPoints.addRange(moduleLibrary->m_entryPoints.getBuffer(), moduleLibrary->m_entryPoints.getCount()); + + // Add to the m_libModules + auto linkage = req->getLinkage(); + linkage->m_libModules.add(ComPtr<IArtifact>(artifact)); + + return SLANG_OK; +} + SlangResult _addLibraryReference(EndToEndCompileRequest* req, IArtifact* artifact) { auto desc = artifact->getDesc(); + // TODO(JS): + // This isn't perhaps the best way to handle this scenario, as IArtifact can + // support lazy evaluation, with suitable hander. + // For now we just read in and strip out the bits we want. + if (isDerivedFrom(desc.kind, ArtifactKind::Container) && + isDerivedFrom(desc.payload, ArtifactPayload::CompileResults)) + { + // We want to read as a file system + ComPtr<IArtifact> container; + + SLANG_RETURN_ON_FAIL(ArtifactContainerUtil::readContainer(artifact, container)); + + // Find the payload... It should be linkable + if (!ArtifactDescUtil::isLinkable(container->getDesc())) + { + return SLANG_FAIL; + } + + ComPtr<IModuleLibrary> libraryIntf; + SLANG_RETURN_ON_FAIL(loadModuleLibrary(ArtifactKeep::Yes, container, req, libraryIntf)); + + auto library = as<ModuleLibrary>(libraryIntf); + + // Look for source maps + for (auto associated : container->getAssociated()) + { + auto assocDesc = associated->getDesc(); + + // If we find an obfuscated source map load it and associate + if (isDerivedFrom(assocDesc.kind, ArtifactKind::Json) && + isDerivedFrom(assocDesc.payload, ArtifactPayload::SourceMap) && + isDerivedFrom(assocDesc.style, ArtifactStyle::Obfuscated)) + { + ComPtr<ISlangBlob> sourceMapBlob; + SLANG_RETURN_ON_FAIL(associated->loadBlob(ArtifactKeep::No, sourceMapBlob.writeRef())); + + RefPtr<SourceMap> sourceMap; + SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::read(sourceMapBlob, nullptr, sourceMap)); + + // I guess we add to all ir modules? + + for (auto irModule : library->m_modules) + { + irModule->setObfuscatedSourceMap(sourceMap); + } + + // Look up the source file + auto sourceManager = req->getSink()->getSourceManager(); + + auto name = Path::getFileNameWithoutExt(associated->getName()); + + if (name.getLength()) + { + auto sourceFile = sourceManager->findSourceFileByPathRecursively(name); + sourceFile->setSourceMap(sourceMap); + } + } + } + + SLANG_RETURN_ON_FAIL(_addLibraryReference(req, container, library)); + return SLANG_OK; + } + if (desc.kind == ArtifactKind::Library && desc.payload == ArtifactPayload::SlangIR) { ComPtr<IModuleLibrary> libraryIntf; @@ -4849,15 +4926,13 @@ SlangResult _addLibraryReference(EndToEndCompileRequest* req, IArtifact* artifac return SLANG_FAIL; } - FrontEndCompileRequest* frontEndRequest = req->getFrontEndReq(); - frontEndRequest->m_extraEntryPoints.addRange(library->m_entryPoints.getBuffer(), library->m_entryPoints.getCount()); - } - else - { - // TODO(JS): - // Do we want to check the path exists? + SLANG_RETURN_ON_FAIL(_addLibraryReference(req, artifact, library)); + return SLANG_OK; } + // TODO(JS): + // Do we want to check the path exists? + // Add to the m_libModules auto linkage = req->getLinkage(); linkage->m_libModules.add(ComPtr<IArtifact>(artifact)); |
