diff options
Diffstat (limited to 'source/compiler-core/slang-artifact-representation-impl.cpp')
| -rw-r--r-- | source/compiler-core/slang-artifact-representation-impl.cpp | 116 |
1 files changed, 13 insertions, 103 deletions
diff --git a/source/compiler-core/slang-artifact-representation-impl.cpp b/source/compiler-core/slang-artifact-representation-impl.cpp index 32ec055d8..802f2c1dd 100644 --- a/source/compiler-core/slang-artifact-representation-impl.cpp +++ b/source/compiler-core/slang-artifact-representation-impl.cpp @@ -9,6 +9,8 @@ #include "slang-artifact-util.h" +#include "../core/slang-castable-list-impl.h" + namespace Slang { /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FileArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -45,16 +47,23 @@ void* FileArtifactRepresentation::castAs(const Guid& guid) return getObject(guid); } -SlangResult FileArtifactRepresentation::writeToBlob(ISlangBlob** blob) +SlangResult FileArtifactRepresentation::createRepresentation(const Guid& typeGuid, ICastable** outCastable) { - if (m_kind == Kind::NameOnly) + // We can convert into a blob only, and only if we have a path + // If it's referenced by a name only, it's a file that *can't* be loaded as a blob in general. + if (typeGuid != ISlangBlob::getTypeGuid() || + m_kind == Kind::NameOnly) { - // If it's referenced by a name only, it's a file that *can't* be loaded as a blob in general. return SLANG_E_NOT_AVAILABLE; } + ComPtr<ISlangBlob> blob; + auto fileSystem = _getFileSystem(); - return fileSystem->loadFile(m_path.getBuffer(), blob); + SLANG_RETURN_ON_FAIL(fileSystem->loadFile(m_path.getBuffer(), blob.writeRef())); + + *outCastable = CastableUtil::getCastable(blob).detach(); + return SLANG_OK; } bool FileArtifactRepresentation::exists() @@ -94,105 +103,6 @@ FileArtifactRepresentation::~FileArtifactRepresentation() } } -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DiagnosticsArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */ - -void* DiagnosticsArtifactRepresentation::getInterface(const Guid& guid) -{ - if (guid == ISlangUnknown::getTypeGuid() || - guid == ICastable::getTypeGuid() || - guid == IArtifactRepresentation::getTypeGuid() || - guid == IDiagnosticsArtifactRepresentation::getTypeGuid()) - { - return static_cast<DiagnosticsArtifactRepresentation*>(this); - } - return nullptr; -} - -void* DiagnosticsArtifactRepresentation::getObject(const Guid& guid) -{ - SLANG_UNUSED(guid); - return nullptr; -} - -void* DiagnosticsArtifactRepresentation::castAs(const Guid& guid) -{ - if (auto intf = getInterface(guid)) - { - return intf; - } - return getObject(guid); -} - -SlangResult DiagnosticsArtifactRepresentation::writeToBlob(ISlangBlob** outBlob) -{ - *outBlob = nullptr; - return SLANG_E_NOT_IMPLEMENTED; -} - -bool DiagnosticsArtifactRepresentation::exists() -{ - return true; -} - -ZeroTerminatedCharSlice DiagnosticsArtifactRepresentation::_allocateSlice(const Slice<char>& in) -{ - if (in.count == 0) - { - return ZeroTerminatedCharSlice("", 0); - } - const char* dst = m_arena.allocateString(in.data, in.count); - return ZeroTerminatedCharSlice(dst, in.count); -} - -void DiagnosticsArtifactRepresentation::add(const Diagnostic& inDiagnostic) -{ - Diagnostic diagnostic(inDiagnostic); - - diagnostic.text = _allocateSlice(inDiagnostic.text); - diagnostic.code = _allocateSlice(inDiagnostic.code); - diagnostic.filePath = _allocateSlice(inDiagnostic.filePath); - - m_diagnostics.add(diagnostic); -} - -/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PostEmitMetadataArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */ - -void* PostEmitMetadataArtifactRepresentation::getInterface(const Guid& guid) -{ - if (guid == ISlangUnknown::getTypeGuid() || - guid == ICastable::getTypeGuid() || - guid == IArtifactRepresentation::getTypeGuid() || - guid == IPostEmitMetadataArtifactRepresentation::getTypeGuid()) - { - return static_cast<IPostEmitMetadataArtifactRepresentation*>(this); - } - return nullptr; -} - -void* PostEmitMetadataArtifactRepresentation::getObject(const Guid& uuid) -{ - if (uuid == getTypeGuid()) - { - return this; - } - return nullptr; -} - -void* PostEmitMetadataArtifactRepresentation::castAs(const Guid& guid) -{ - if (auto ptr = getInterface(guid)) - { - return ptr; - } - return getObject(guid); -} - - -Slice<ShaderBindingRange> PostEmitMetadataArtifactRepresentation::getBindingRanges() -{ - return Slice<ShaderBindingRange>(m_metadata.usedBindings.getBuffer(), m_metadata.usedBindings.getCount()); -} - /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PostEmitMetadataArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */ void* ObjectArtifactRepresentation::castAs(const Guid& guid) |
