summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-artifact-impl.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-08-09 11:23:40 -0400
committerGitHub <noreply@github.com>2022-08-09 11:23:40 -0400
commit9df7fcb023bd5a22f35ecd609b7a50cc6634976c (patch)
tree69692c36e664eafa2a37b5fa13ca7142f62b1844 /source/compiler-core/slang-artifact-impl.cpp
parentc0733be56dc24ef0eb67b26fe0c49d3419e75773 (diff)
Artifact split interface and implementation (#2349)
* #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.
Diffstat (limited to 'source/compiler-core/slang-artifact-impl.cpp')
-rw-r--r--source/compiler-core/slang-artifact-impl.cpp224
1 files changed, 224 insertions, 0 deletions
diff --git a/source/compiler-core/slang-artifact-impl.cpp b/source/compiler-core/slang-artifact-impl.cpp
new file mode 100644
index 000000000..8dbae063b
--- /dev/null
+++ b/source/compiler-core/slang-artifact-impl.cpp
@@ -0,0 +1,224 @@
+// slang-artifact-impl.cpp
+#include "slang-artifact-impl.h"
+
+#include "slang-artifact-representation.h"
+
+#include "slang-artifact-util.h"
+
+namespace Slang {
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ArtifactList !!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+void* ArtifactList::getInterface(const Guid& guid)
+{
+ if (guid == ISlangUnknown::getTypeGuid() ||
+ guid == ICastable::getTypeGuid() ||
+ guid == IArtifactList::getTypeGuid())
+ {
+ return static_cast<IArtifactList*>(this);
+ }
+ return nullptr;
+}
+
+void* ArtifactList::getObject(const Guid& guid)
+{
+ // For now we can't cast to an object
+ SLANG_UNUSED(guid);
+ return nullptr;
+}
+
+void* ArtifactList::castAs(const Guid& guid)
+{
+ if (auto intf = getInterface(guid))
+ {
+ return intf;
+ }
+ return getObject(guid);
+}
+
+void ArtifactList::add(IArtifact* artifact)
+{
+ // Must be set
+ SLANG_ASSERT(artifact);
+ // Can't already be in the list
+ SLANG_ASSERT(m_artifacts.indexOf(artifact) < 0);
+ // Can't have another owner
+ SLANG_ASSERT(artifact->getParent() == nullptr);
+
+ // Set the parent
+ artifact->setParent(m_parent);
+
+ // Add
+ m_artifacts.add(ComPtr<IArtifact>(artifact));
+}
+
+void ArtifactList::removeAt(Index index)
+{
+ IArtifact* artifact = m_artifacts[index];
+ artifact->setParent(nullptr);
+ m_artifacts.removeAt(index);
+}
+
+void ArtifactList::clear()
+{
+ _setParent(nullptr);
+ m_artifacts.clear();
+}
+
+void ArtifactList::_setParent(IArtifact* parent)
+{
+ if (m_parent == parent)
+ {
+ return;
+ }
+
+ for (IArtifact* artifact : m_artifacts)
+ {
+ artifact->setParent(artifact);
+ }
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Artifact !!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+void* Artifact::getInterface(const Guid& uuid)
+{
+ if (uuid == ISlangUnknown::getTypeGuid() || uuid == IArtifact::getTypeGuid())
+ {
+ return static_cast<IArtifact*>(this);
+ }
+ return nullptr;
+}
+
+bool Artifact::exists()
+{
+ for (ISlangUnknown* item : m_items)
+ {
+ ComPtr<ICastable> castable;
+
+ if (SLANG_SUCCEEDED(item->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef())) && castable)
+ {
+ auto rep = as<IArtifactRepresentation>(castable);
+ if (rep)
+ {
+ // It is a rep and it exists
+ if (rep->exists())
+ {
+ return true;
+ }
+ continue;
+ }
+ // Associated types don't encapsulate an artifact representation, so don't signal existance
+ if (as<IArtifactAssociated>(castable))
+ {
+ continue;
+ }
+ }
+
+ // It can't be IArtifactRepresentation or IArtifactAssociated, so we assume means it exists
+ return true;
+ }
+
+ return false;
+}
+
+void Artifact::addItem(ISlangUnknown* intf)
+{
+ SLANG_ASSERT(intf);
+ // Can't already be in there
+ SLANG_ASSERT(m_items.indexOf(intf) < 0);
+ // Add it
+ m_items.add(ComPtr<ISlangUnknown>(intf));
+}
+
+void Artifact::removeItemAt(Index i)
+{
+ m_items.removeAt(i);
+}
+
+void* Artifact::findItemInterface(const Guid& guid)
+{
+ for (ISlangUnknown* intf : m_items)
+ {
+ ISlangUnknown* cast = nullptr;
+ if (SLANG_SUCCEEDED(intf->queryInterface(guid, (void**)&cast)) && cast)
+ {
+ // NOTE! This assumes we *DONT* need to ref count to keep an interface in scope
+ // (as strict COM requires so as to allow on demand interfaces).
+ cast->release();
+ return cast;
+ }
+ }
+ return nullptr;
+}
+
+void* Artifact::findItemObject(const Guid& classGuid)
+{
+ for (ISlangUnknown* intf : m_items)
+ {
+ ComPtr<ICastable> castable;
+ if (SLANG_SUCCEEDED(intf->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef())) && castable)
+ {
+ void* obj = castable->castAs(classGuid);
+
+ // NOTE! This assumes we *DONT* need to ref count to keep an interface in scope
+ // (as strict COM requires so as to allow on demand interfaces).
+
+ // If could cast return the result
+ if (obj)
+ {
+ return obj;
+ }
+ }
+ }
+ return nullptr;
+}
+
+SlangResult Artifact::requireFile(Keep keep, IFileArtifactRepresentation** outFileRep)
+{
+ auto util = ArtifactUtilImpl::getSingleton();
+ return util->requireFileDefaultImpl(this, keep, outFileRep);
+}
+
+SlangResult Artifact::loadBlob(Keep keep, ISlangBlob** outBlob)
+{
+ // If we have a blob just return it
+ if (auto blob = findItem<ISlangBlob>(this))
+ {
+ blob->addRef();
+ *outBlob = blob;
+ return SLANG_OK;
+ }
+
+ ComPtr<ISlangBlob> blob;
+
+ // Look for a representation that we can serialize into a blob
+ for (ISlangUnknown* intf : m_items)
+ {
+ ComPtr<IArtifactRepresentation> rep;
+ if (SLANG_SUCCEEDED(intf->queryInterface(IArtifactRepresentation::getTypeGuid(), (void**)rep.writeRef())) && rep)
+ {
+ SlangResult res = rep->writeToBlob(blob.writeRef());
+ if (SLANG_SUCCEEDED(res) && blob)
+ {
+ break;
+ }
+ }
+ }
+
+ // Wasn't able to construct
+ if (!blob)
+ {
+ return SLANG_E_NOT_FOUND;
+ }
+
+ // Put in cache
+ if (canKeep(keep))
+ {
+ addItem(blob);
+ }
+
+ *outBlob = blob.detach();
+ return SLANG_OK;
+}
+
+} // namespace Slang