diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-04-20 11:55:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-20 11:55:26 -0400 |
| commit | 467fa3a5dcdd36e310b084747d6f4fcd6ca81249 (patch) | |
| tree | 193104aad3da77fffddb4b9be3edad4bcfdf76ac /source/compiler-core | |
| parent | 4d24f55226870055c8dcbb3409efc5355da134d7 (diff) | |
Improvements outputting containers (#2815)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Moved JSON source map writing logic to JSONSourceMapUtil.
* Use ArtifactHandler to read/write SourceMaps.
Use ObjectCastableAdapter to hold SourceMap
Only serialize SourceMap <-> JSON on demand.
* Make some types swappable.
* BoxValue impl.
* Added asBoxValue.
* Remove const get funcs.
* Fix typo in asBoxValue.
* Fix another typo in asBoxValue.
* Slightly simplify conversion to blob of SourceMap.
* WIP Api improvements around sourcemap/artifact/line-directive.
* Small fix for asBoxValue
* WIP outputting container with multiple artifacts.
* Added ArtifactContailerUtil::filter to produce an artifact hierarchy that only contains "signficant" and "blobable" artifacts.
* Make emitting IR disjoint to using a container.
Added -emit-ir option.
Simplfiy output.
* Fix typo in options parsing.
* Add a test that ouputs with an emit source map.
* Enable emitting our SlangIR module if no targets are specified.
* Fix issues constructing container.
* Extra checks getting obfuscated source map from a translation unit.
* Fix typo.
Diffstat (limited to 'source/compiler-core')
| -rw-r--r-- | source/compiler-core/slang-artifact-container-util.cpp | 100 | ||||
| -rw-r--r-- | source/compiler-core/slang-artifact-container-util.h | 8 | ||||
| -rw-r--r-- | source/compiler-core/slang-artifact-desc-util.cpp | 10 | ||||
| -rw-r--r-- | source/compiler-core/slang-artifact-util.cpp | 6 |
4 files changed, 105 insertions, 19 deletions
diff --git a/source/compiler-core/slang-artifact-container-util.cpp b/source/compiler-core/slang-artifact-container-util.cpp index 6121df964..dfc385f9a 100644 --- a/source/compiler-core/slang-artifact-container-util.cpp +++ b/source/compiler-core/slang-artifact-container-util.cpp @@ -191,34 +191,24 @@ SlangResult ArtifactContainerWriter::getBaseName(IArtifact* artifact, String& ou SlangResult ArtifactContainerWriter::writeInDirectory(IArtifact* artifact, const String& baseName) { - // TODO(JS): // We could now output information about the desc/artifact, say as some json. // For now we assume the extension is good enough for most purposes. + // If it's an "arbitrary" container, we don't need to write it + if (artifact->getDesc().kind != ArtifactKind::Container) { // We can't write it without a blob ComPtr<ISlangBlob> blob; - const auto res = artifact->loadBlob(ArtifactKeep::No, blob.writeRef()); + SLANG_RETURN_ON_FAIL(artifact->loadBlob(ArtifactKeep::No, blob.writeRef())); - if (SLANG_FAILED(res)) - { - // If it failed and it's significant the whole write fails - if (ArtifactUtil::isSignificant(artifact)) - { - return res; - } - } - - { - // Get the name of the artifact - StringBuilder artifactName; - SLANG_RETURN_ON_FAIL(ArtifactDescUtil::calcNameForDesc(artifact->getDesc(), baseName.getUnownedSlice(), artifactName)); + // Get the name of the artifact + StringBuilder artifactName; + SLANG_RETURN_ON_FAIL(ArtifactDescUtil::calcNameForDesc(artifact->getDesc(), baseName.getUnownedSlice(), artifactName)); - const auto combinedPath = Path::combine(m_entry.path, artifactName); - // Write out the blob - SLANG_RETURN_ON_FAIL(m_fileSystem->saveFileBlob(combinedPath.getBuffer(), blob)); - } + const auto combinedPath = Path::combine(m_entry.path, artifactName); + // Write out the blob + SLANG_RETURN_ON_FAIL(m_fileSystem->saveFileBlob(combinedPath.getBuffer(), blob)); } { @@ -837,4 +827,76 @@ SlangResult ArtifactContainerUtil::readContainer(IArtifact* artifact, ComPtr<IAr return SLANG_OK; } +/* static */SlangResult ArtifactContainerUtil::filter(IArtifact* artifact, ComPtr<IArtifact>& outArtifact) +{ + outArtifact.setNull(); + + // Copy the artifact + auto dstArtifact = ArtifactUtil::createArtifact(artifact->getDesc(), artifact->getName()); + + ComPtr<ISlangBlob> blob; + + if (artifact->getDesc().kind != ArtifactKind::Container) + { + // We can't write it without a blob + const auto res = artifact->loadBlob(ArtifactKeep::No, blob.writeRef()); + + if (SLANG_FAILED(res)) + { + // If it failed and it's significant the whole write fails + if (ArtifactUtil::isSignificant(artifact)) + { + return res; + } + } + else + { + // Add the blob to the destination + dstArtifact->addRepresentationUnknown(blob); + } + } + + // Copy the children after filtering + { + for (IArtifact* child : artifact->getChildren()) + { + ComPtr<IArtifact> dstChild; + SLANG_RETURN_ON_FAIL(filter(child, dstChild)); + + if (dstChild) + { + dstArtifact->addChild(dstChild); + } + } + } + + // Copy the associated after filtering + { + for (IArtifact* assoc : artifact->getAssociated()) + { + ComPtr<IArtifact> dstAssoc; + SLANG_RETURN_ON_FAIL(filter(assoc, dstAssoc)); + + if (dstAssoc) + { + dstArtifact->addAssociated(dstAssoc); + } + } + } + + // We only return the artifact if any of the following are true + // 1) It has a blob representation + // 2) It contains children or associated artifacts + + if (blob || + dstArtifact->getChildren().count || + dstArtifact->getAssociated().count) + { + outArtifact = dstArtifact; + } + + // If we return an artifact or not, this was successful + return SLANG_OK; +} + } // namespace Slang diff --git a/source/compiler-core/slang-artifact-container-util.h b/source/compiler-core/slang-artifact-container-util.h index c6e836245..0ee99de26 100644 --- a/source/compiler-core/slang-artifact-container-util.h +++ b/source/compiler-core/slang-artifact-container-util.h @@ -36,6 +36,14 @@ struct ArtifactContainerUtil /// Read an artifact that represents a container as an artifact hierarchy static SlangResult readContainer(IArtifact* artifact, ComPtr<IArtifact>& outArtifact); + + /// Creates a copy of artifact where + /// * All artifacts are blobs + /// * Any generic containers that are empty are dropped + /// * Any sub artifact that can't be blobed and isn't significant is ignored + /// + /// A future improvement would be to take a function to also control what makes it to the output + static SlangResult filter(IArtifact* artifact, ComPtr<IArtifact>& outArtifact); }; } // namespace Slang diff --git a/source/compiler-core/slang-artifact-desc-util.cpp b/source/compiler-core/slang-artifact-desc-util.cpp index 67501782a..e10ceee07 100644 --- a/source/compiler-core/slang-artifact-desc-util.cpp +++ b/source/compiler-core/slang-artifact-desc-util.cpp @@ -753,6 +753,16 @@ SlangResult ArtifactDescUtil::appendDefaultExtension(const ArtifactDesc& desc, S default: break; } + if (ArtifactDescUtil::isGpuUsable(desc)) + { + auto ext = _getPayloadExtension(desc.payload); + if (ext.getLength()) + { + out << ext; + return SLANG_OK; + } + } + if (ArtifactDescUtil::isCpuLikeTarget(desc) && !isDerivedFrom(desc.payload, ArtifactPayload::Source)) { return appendCpuExtensionForKind(desc.kind, out); diff --git a/source/compiler-core/slang-artifact-util.cpp b/source/compiler-core/slang-artifact-util.cpp index 00884c96f..7420f6843 100644 --- a/source/compiler-core/slang-artifact-util.cpp +++ b/source/compiler-core/slang-artifact-util.cpp @@ -83,6 +83,12 @@ static bool _checkRecursive(ArtifactUtil::FindStyle findStyle) return false; } + /* We currently can't write out diagnostics, so for now we'll say they are insignificant */ + if (isDerivedFrom(desc.payload, ArtifactPayload::Diagnostics)) + { + return false; + } + return true; } |
