From ac71724c03392b429e44641a3641b2bcf7cc55fc Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 16 Aug 2022 03:39:41 -0400 Subject: Remove CompileResult to use IArtifact (#2357) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP with hierarchical enums. * Some small fixes and improvements around artifact desc related types. * Improvements around hierarchical enum. * Fixes to get Artifact types refactor to be able to execute tests. * Attempt to better categorize PTX. * Work around for potentially unused function warning. * Typo fix. * Simplify Artifact header. * Small improvements around Artifact kind/payload/style. * Added IDestroyable/ICastable * Add IArtifactList. * First impl of IArtifactUtil. * Use the ICastable interface for IArtifactRepresentation. * Added IArtifactRepresentation & IArtifactAssociated. * Add SLANG_OVERRIDE to avoid gcc/clang warning. * Fix calling convention issue on win32. * Fix missing SLANG_OVERRIDE. * First attempt at file abstraction around Artifact. * Added creation of lock file. * Move functionality for determining file paths to the IArtifactUtil. Add casting to ICastable. * Added some casting/finding mechanisms. * Simplify IArtifact interface, and use Items for file reps. * Fix problem with libraries on DXIL. * Split out ArtifactRepresentation. * Move ArtifactDesc functionality to ArtifactDescUtil. ArtifactInfoUtil becomes ArtifactDescUtil. * Split implementations from the interfaces for Artifact. * Use TypeTextUtil for target name outputting. * Add artifact impls. * Add ICastableList * Added UnknownCastableAdapter * Make ISlangSharedLibrary derive from ICastable, and remain backwards compatible with slang-llvm. * Refactor Representation on Artifact. * Make our ISlangBlobs also derive from ICastable. Make ISlangBlob atomic ref counted. * Split out CastableList and related types, and placed in core. * Small fixes around IArtifact. Improve IArtifact docs. First impl of getChildren for IArtifact. * Documentation improvements for Artifact related types. * Fix typo. * Special case adding a ICastableList to a LazyCastableList. * Small simplification of LazyCastableList, by adding State member. * Removed the ILockFile interface because IFileArtifactRepresentation can be used. * Implement DiagnosticsArtifactRepresentation. * Added PostEmitMetadataArtifactRepresentation * Add searching by predicate. Added handling of accessing Artifact as ISharedLibrary * Fix typo. * Add find to IArtifacgtList. Fix some missing SLANG_NO_THROW. * Small improvements around ArtifactDesc types. * Another small change around ArtifactKind. * Some more shuffling of ArtifactDesc. * Make IArtifact castable Remove IArtifactList Made IArtifactContainer derive from IArtifact Made ModuleLibrary atomic ref counted/given IModuleLibrary interface. * Must call _requireChildren before any children access. * Fix missing SLANG_MCALL on castAs. * Fix missing SLANG_OVERRIDE. * Added IArtifactHandler * Use ICastable for basis of scope/lookup. * WIP first attempt to remove CompileResult. * Fix support for for downstream compiler shared library adapter. * Fix issues found when replacing CompileResult. * Fix typo. * Fix getting items form 'significant' member of an Artifact. * Split out ArtifactUtil & ArtifactHandler. * Work around for problem on Visual studio. * Improve searching. * Add missing files. --- source/compiler-core/slang-artifact-impl.cpp | 125 ++++++++++++++++++--------- 1 file changed, 84 insertions(+), 41 deletions(-) (limited to 'source/compiler-core/slang-artifact-impl.cpp') diff --git a/source/compiler-core/slang-artifact-impl.cpp b/source/compiler-core/slang-artifact-impl.cpp index 061aa9ee7..ed952e72c 100644 --- a/source/compiler-core/slang-artifact-impl.cpp +++ b/source/compiler-core/slang-artifact-impl.cpp @@ -6,10 +6,21 @@ #include "slang-artifact-util.h" #include "slang-artifact-desc-util.h" +#include "slang-artifact-handler-impl.h" + #include "../core/slang-castable-list-impl.h" namespace Slang { +static bool _checkSelf(IArtifact::FindStyle findStyle) +{ + return Index(findStyle) <= Index(IArtifact::FindStyle::SelfOrChildren); +} + +static bool _checkChildren(IArtifact::FindStyle findStyle) +{ + return Index(findStyle) >= Index(IArtifact::FindStyle::SelfOrChildren); +} /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Artifact !!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -187,6 +198,26 @@ ICastableList* Artifact::getRepresentationList() return m_representations.requireList(); } +IArtifact* Artifact::findArtifactByDerivedDesc(FindStyle findStyle, const ArtifactDesc& from) +{ + return (_checkSelf(findStyle) && ArtifactDescUtil::isDescDerivedFrom(m_desc, from)) ? this : nullptr; +} + +IArtifact* Artifact::findArtifactByPredicate(FindStyle findStyle, FindFunc func, void* data) +{ + return (_checkSelf(findStyle) && func(this, data)) ? this : nullptr; +} + +IArtifact* Artifact::findArtifactByName(FindStyle findStyle, const char* name) +{ + return (_checkSelf(findStyle) && m_name == name) ? this : nullptr; +} + +IArtifact* Artifact::findArtifactByDesc(FindStyle findStyle, const ArtifactDesc& desc) +{ + return (_checkSelf(findStyle) && m_desc == desc) ? this : nullptr; +} + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ArtifactContainer !!!!!!!!!!!!!!!!!!!!!!!!!!! */ void* ArtifactContainer::getInterface(const Guid& guid) @@ -267,67 +298,79 @@ void ArtifactContainer::clearChildren() m_children.clearAndDeallocate(); } -IArtifact* ArtifactContainer::findChildByDesc(const ArtifactDesc& desc) +static bool _isDerivedDesc(IArtifact* artifact, void* data) { - _requireChildren(); - - for (IArtifact* artifact : m_children) - { - if (artifact->getDesc() == desc) - { - return artifact; - } - } - return nullptr; + const ArtifactDesc& from = *(const ArtifactDesc*)data; + return ArtifactDescUtil::isDescDerivedFrom(artifact->getDesc(), from); } -IArtifact* ArtifactContainer::findChildByDerivedDesc(const ArtifactDesc& desc) +static bool _isDesc(IArtifact* artifact, void* data) { - _requireChildren(); + const ArtifactDesc& desc = *(const ArtifactDesc*)data; + return desc == artifact->getDesc(); +} - for (IArtifact* artifact : m_children) +static bool _isName(IArtifact* artifact, void* data) +{ + const char* name = (const char*)data; + const char* artifactName = artifact->getName(); + if (artifactName == nullptr) { - const ArtifactDesc artifactDesc = artifact->getDesc(); - // TODO(JS): Currently this ignores flags in desc. That may or may not be right - // long term. - if (isDerivedFrom(artifactDesc.kind, desc.kind) && - isDerivedFrom(artifactDesc.payload, desc.payload) && - isDerivedFrom(artifactDesc.style, desc.style)) - { - return artifact; - } + return false; } - return nullptr; + return ::strcmp(name, artifactName) == 0; } -IArtifact* ArtifactContainer::findChildByName(const char* name) + +IArtifact* ArtifactContainer::findArtifactByDerivedDesc(FindStyle findStyle, const ArtifactDesc& from) { - _requireChildren(); + return findArtifactByPredicate(findStyle, _isDerivedDesc, const_cast(&from)); +} - for (IArtifact* artifact : m_children) - { - const char* artifactName = artifact->getName(); +IArtifact* ArtifactContainer::findArtifactByName(FindStyle findStyle, const char* name) +{ + return findArtifactByPredicate(findStyle, _isName, const_cast(name)); +} - if (artifactName == name || - ::strcmp(artifactName, name) == 0) - { - return artifact; - } - } - return nullptr; +IArtifact* ArtifactContainer::findArtifactByDesc(FindStyle findStyle, const ArtifactDesc& desc) +{ + return findArtifactByPredicate(findStyle, _isDesc, const_cast(&desc)); } -IArtifact* ArtifactContainer::findChildByPredicate(FindFunc func, void* data) +IArtifact* ArtifactContainer::findArtifactByPredicate(FindStyle findStyle, FindFunc func, void* data) { - _requireChildren(); + if (_checkSelf(findStyle) && func(this, data)) + { + return this; + } - for (IArtifact* artifact : m_children) + if (_checkChildren(findStyle)) { - if (func(artifact, data)) + auto children = getChildren(); + + // First search the children + for (auto child : children) { - return artifact; + if (func(child, data)) + { + return child; + } + } + + // Then the childrens recursively + if (findStyle == FindStyle::Recursive || + findStyle == FindStyle::ChildrenRecursive) + { + for (auto child : children) + { + if (auto found = child->findArtifactByPredicate(FindStyle::ChildrenRecursive, func, data)) + { + return found; + } + } } } + return nullptr; } -- cgit v1.2.3