summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-08-11 11:55:49 -0400
committerGitHub <noreply@github.com>2022-08-11 11:55:49 -0400
commitb5d84f60d36b81c7e8263048dda031a9be14a106 (patch)
tree8b64722cd66a7928942c84ca8c17a27459df17e4 /source/core
parenta083a37ee58dc48d92cf2b844466a295eb3e643e (diff)
Artifact closer to being able to replace CompileResult (#2354)
* #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.
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-blob.h7
-rw-r--r--source/core/slang-castable-list-impl.cpp17
-rw-r--r--source/core/slang-castable-list-impl.h1
-rw-r--r--source/core/slang-castable-list.h13
-rw-r--r--source/core/slang-lazy-castable-list.cpp14
-rw-r--r--source/core/slang-lazy-castable-list.h2
-rw-r--r--source/core/slang-shared-library.cpp14
-rw-r--r--source/core/slang-shared-library.h18
-rw-r--r--source/core/slang-smart-pointer.h7
-rw-r--r--source/core/slang-string.h5
10 files changed, 93 insertions, 5 deletions
diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h
index b1384bb2c..8a9ab5dea 100644
--- a/source/core/slang-blob.h
+++ b/source/core/slang-blob.h
@@ -45,11 +45,18 @@ public:
SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_string.getLength(); }
static ComPtr<ISlangBlob> create(const String& in) { return ComPtr<ISlangBlob>(new StringBlob(in)); }
+ static ComPtr<ISlangBlob> moveCreate(String& in)
+ {
+ auto blob = new StringBlob;
+ blob->m_string.swapWith(in);
+ return ComPtr<ISlangBlob>(blob);
+ }
protected:
explicit StringBlob(String const& string)
: m_string(string)
{}
+ StringBlob() {}
/// Get the contained string
SLANG_FORCE_INLINE const String& getString() const { return m_string; }
diff --git a/source/core/slang-castable-list-impl.cpp b/source/core/slang-castable-list-impl.cpp
index ee10ea995..56f8c7cae 100644
--- a/source/core/slang-castable-list-impl.cpp
+++ b/source/core/slang-castable-list-impl.cpp
@@ -36,9 +36,10 @@ void* UnknownCastableAdapter::castAs(const Guid& guid)
void* UnknownCastableAdapter::getInterface(const Guid& guid)
{
if (guid == ISlangUnknown::getTypeGuid() ||
- guid == ICastable::getTypeGuid())
+ guid == ICastable::getTypeGuid() ||
+ guid == IUnknownCastableAdapter::getTypeGuid())
{
- return static_cast<ICastable*>(this);
+ return static_cast<IUnknownCastableAdapter*>(this);
}
return nullptr;
}
@@ -97,6 +98,18 @@ void* CastableList::find(const Guid& guid)
return nullptr;
}
+ICastable* SLANG_MCALL CastableList::findWithPredicate(FindFunc func, void* data)
+{
+ for (ICastable* castable : m_list)
+ {
+ if (func(castable, data))
+ {
+ return castable;
+ }
+ }
+ return nullptr;
+}
+
Index CastableList::indexOf(ICastable* castable)
{
const Count count = m_list.getCount();
diff --git a/source/core/slang-castable-list-impl.h b/source/core/slang-castable-list-impl.h
index 6c03855f2..b578e8de4 100644
--- a/source/core/slang-castable-list-impl.h
+++ b/source/core/slang-castable-list-impl.h
@@ -66,6 +66,7 @@ public:
virtual Index SLANG_MCALL indexOf(ICastable* castable) SLANG_OVERRIDE;
virtual Index SLANG_MCALL indexOfUnknown(ISlangUnknown* unk) SLANG_OVERRIDE;
virtual void* SLANG_MCALL find(const Guid& guid) SLANG_OVERRIDE;
+ virtual ICastable* SLANG_MCALL findWithPredicate(FindFunc func, void* data) SLANG_OVERRIDE;
virtual ICastable*const* SLANG_MCALL getBuffer() SLANG_OVERRIDE { return m_list.getBuffer(); }
/// Dtor
diff --git a/source/core/slang-castable-list.h b/source/core/slang-castable-list.h
index 942f53376..b9c98d65a 100644
--- a/source/core/slang-castable-list.h
+++ b/source/core/slang-castable-list.h
@@ -9,11 +9,14 @@
namespace Slang
{
+
/* A useful interface for handling lists of castable interfaces. Cannot hold nullptr */
class ICastableList : public ICastable
{
SLANG_COM_INTERFACE(0x335f3d40, 0x934c, 0x40dc, { 0xb5, 0xe1, 0xf7, 0x6e, 0x40, 0x3, 0x62, 0x5 })
-
+
+ typedef bool (*FindFunc)(ICastable* castable, void* data);
+
/// Get the count of all interfaces held in the list
virtual Count SLANG_MCALL getCount() = 0;
/// Get the interface at the specified index
@@ -32,6 +35,8 @@ class ICastableList : public ICastable
virtual Index SLANG_MCALL indexOfUnknown(ISlangUnknown* unk) = 0;
/// Find the first item that casts to non null
virtual void* SLANG_MCALL find(const Guid& guid) = 0;
+ /// Find the fast castable that matches the predicate
+ virtual ICastable* SLANG_MCALL findWithPredicate(FindFunc func, void* data) = 0;
/// Access the internal buffer (any mutation can invalidate this value)
virtual ICastable*const* SLANG_MCALL getBuffer() = 0;
};
@@ -43,6 +48,12 @@ SLANG_FORCE_INLINE T* find(ICastableList* list)
return reinterpret_cast<T*>(list->find(T::getTypeGuid()));
}
+template <typename T>
+SLANG_FORCE_INLINE T* find(ICastableList* list, ICastableList::FindFunc func, void* data)
+{
+ return reinterpret_cast<T*>(list->findWithPredicate(T::getTypeGuid(), func, data));
+}
+
/* Adapter interface to make a non castable types work as ICastable */
class IUnknownCastableAdapter : public ICastable
{
diff --git a/source/core/slang-lazy-castable-list.cpp b/source/core/slang-lazy-castable-list.cpp
index d9f0090d5..1832a67f4 100644
--- a/source/core/slang-lazy-castable-list.cpp
+++ b/source/core/slang-lazy-castable-list.cpp
@@ -112,7 +112,19 @@ void* LazyCastableList::find(const Guid& guid)
}
return nullptr;
}
-
+
+ICastable* LazyCastableList::findWithPredicate(ICastableList::FindFunc func, void* data)
+{
+ for (auto castable : getView())
+ {
+ if (func(castable, data))
+ {
+ return castable;
+ }
+ }
+ return nullptr;
+}
+
ConstArrayView<ICastable*> LazyCastableList::getView() const
{
switch (m_state)
diff --git a/source/core/slang-lazy-castable-list.h b/source/core/slang-lazy-castable-list.h
index 4f73ce9ca..84bfd8c6d 100644
--- a/source/core/slang-lazy-castable-list.h
+++ b/source/core/slang-lazy-castable-list.h
@@ -35,6 +35,8 @@ public:
void clearAndDeallocate();
/// Find the first item that castAs(guid) produces a result
void* find(const Guid& guid);
+ /// Find first match using predicate function
+ ICastable* findWithPredicate(ICastableList::FindFunc func, void* data);
/// Get the contents of the list as a view
ConstArrayView<ICastable*> getView() const;
/// Get the index of castable in the list. Returns -1 if not found
diff --git a/source/core/slang-shared-library.cpp b/source/core/slang-shared-library.cpp
index 0e4f0ee73..35440ac9e 100644
--- a/source/core/slang-shared-library.cpp
+++ b/source/core/slang-shared-library.cpp
@@ -33,7 +33,7 @@ SlangResult DefaultSharedLibraryLoader::loadSharedLibrary(const char* path, ISla
{
*outSharedLibrary = nullptr;
// Try loading
- SharedLibrary::Handle handle = nullptr;
+ SharedLibrary::Handle handle;
SLANG_RETURN_ON_FAIL(SharedLibrary::load(path, handle));
*outSharedLibrary = ComPtr<ISlangSharedLibrary>(new DefaultSharedLibrary(handle)).detach();
return SLANG_OK;
@@ -74,6 +74,18 @@ TemporarySharedLibrary::~TemporarySharedLibrary()
}
}
+/* !!!!!!!!!!!!!!!!!!!!!!!!!! ScopeSharedLibrary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+
+ScopeSharedLibrary::~ScopeSharedLibrary()
+{
+ if (m_sharedLibraryHandle)
+ {
+ // We have to unload if we want to be able to remove
+ SharedLibrary::unload(m_sharedLibraryHandle);
+ m_sharedLibraryHandle = nullptr;
+ }
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!! DefaultSharedLibrary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
DefaultSharedLibrary::~DefaultSharedLibrary()
diff --git a/source/core/slang-shared-library.h b/source/core/slang-shared-library.h
index c0074bad3..0a63e570e 100644
--- a/source/core/slang-shared-library.h
+++ b/source/core/slang-shared-library.h
@@ -100,6 +100,24 @@ protected:
String m_path;
};
+class ScopeSharedLibrary : public DefaultSharedLibrary
+{
+public:
+ typedef DefaultSharedLibrary Super;
+
+ /// Ctor
+ ScopeSharedLibrary(const SharedLibrary::Handle sharedLibraryHandle, ISlangUnknown* scope) :
+ Super(sharedLibraryHandle),
+ m_scope(scope)
+ {
+ }
+
+ virtual ~ScopeSharedLibrary();
+
+protected:
+ ComPtr<ISlangUnknown> m_scope;
+};
+
class SharedLibraryUtils
{
public:
diff --git a/source/core/slang-smart-pointer.h b/source/core/slang-smart-pointer.h
index 45083c1eb..75c4398a5 100644
--- a/source/core/slang-smart-pointer.h
+++ b/source/core/slang-smart-pointer.h
@@ -236,6 +236,13 @@ namespace Slang
return rs;
}
+ void swapWith(RefPtr<T>& rhs)
+ {
+ auto rhsPtr = rhs.pointer;
+ rhs.pointer = pointer;
+ pointer = rhsPtr;
+ }
+
SLANG_FORCE_INLINE void setNull()
{
releaseReference(pointer);
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 69ca7e2c3..028eec3e4 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -765,6 +765,11 @@ namespace Slang
return indexOf(str.begin(), 0);
}
+ void swapWith(String& other)
+ {
+ m_buffer.swapWith(other.m_buffer);
+ }
+
Index indexOf(char ch, Index id) const
{
const Index length = getLength();