diff options
Diffstat (limited to 'source/compiler-core/slang-downstream-dep1.cpp')
| -rw-r--r-- | source/compiler-core/slang-downstream-dep1.cpp | 134 |
1 files changed, 129 insertions, 5 deletions
diff --git a/source/compiler-core/slang-downstream-dep1.cpp b/source/compiler-core/slang-downstream-dep1.cpp index e5eb4ac24..25964964f 100644 --- a/source/compiler-core/slang-downstream-dep1.cpp +++ b/source/compiler-core/slang-downstream-dep1.cpp @@ -1,12 +1,136 @@ // slang-downstream-dep1.cpp #include "slang-downstream-dep1.h" +#include "slang-artifact-util.h" +#include "slang-artifact-associated-impl.h" + +#include "../core/slang-castable-list-impl.h" namespace Slang { +/* !!!!!!!!!!!!!!!!!!!!!!!!! DownstreamArtifactRepresentation_Dep1 !!!!!!!!!!!!!!!!!!!!!!!! */ + +class DownstreamResultArtifactRepresentationAdapater_Dep1 : public ComBaseObject, public IArtifactRepresentation +{ +public: + SLANG_COM_BASE_IUNKNOWN_ALL + + // ICastable + virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const SlangUUID& guid) SLANG_OVERRIDE; + + // IArtifactRepresentation + virtual SLANG_NO_THROW SlangResult SLANG_MCALL createRepresentation(const Guid& typeGuid, ICastable** outCastable) SLANG_OVERRIDE; + virtual SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE { return true; } + + DownstreamResultArtifactRepresentationAdapater_Dep1(DownstreamCompileResult_Dep1* result): + m_result(result) + { + } + + void* getInterface(const Guid& guid); + void* getObject(const Guid& guid); + + RefPtr<DownstreamCompileResult_Dep1> m_result; +}; + +void* DownstreamResultArtifactRepresentationAdapater_Dep1::castAs(const SlangUUID& guid) +{ + if (auto ptr = getInterface(guid)) + { + return ptr; + } + return getObject(guid); +} + +void* DownstreamResultArtifactRepresentationAdapater_Dep1::getInterface(const Guid& guid) +{ + if (guid == ISlangBlob::getTypeGuid() || + guid == ICastable::getTypeGuid() || + guid == IArtifactRepresentation::getTypeGuid()) + { + IArtifactRepresentation* rep = this; + return rep; + } + return nullptr; +} + +void* DownstreamResultArtifactRepresentationAdapater_Dep1::getObject(const Guid& guid) +{ + SLANG_UNUSED(guid); + return nullptr; +} + +SlangResult DownstreamResultArtifactRepresentationAdapater_Dep1::createRepresentation(const Guid& typeGuid, ICastable** outCastable) +{ + if (typeGuid == ISlangSharedLibrary::getTypeGuid()) + { + ComPtr<ISlangSharedLibrary> lib; + SLANG_RETURN_ON_FAIL(DownstreamUtil_Dep1::getDownstreamSharedLibrary(m_result, lib)); + + *outCastable = lib.detach(); + return SLANG_OK; + } + else if (typeGuid == ISlangBlob::getTypeGuid()) + { + ComPtr<ISlangBlob> blob; + SLANG_RETURN_ON_FAIL(m_result->getBinary(blob)); + + *outCastable = CastableUtil::getCastable(blob).detach(); + return SLANG_OK; + } + + return SLANG_E_NOT_AVAILABLE; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!! DownstreamCompilerAdapter_Dep1 !!!!!!!!!!!!!!!!!!!!!!!! */ + +SlangResult DownstreamCompilerAdapter_Dep1::compile(const CompileOptions& options, IArtifact** outArtifact) +{ + RefPtr<DownstreamCompileResult_Dep1> result; + SLANG_RETURN_ON_FAIL(m_dep->compile(options, result)); + + typedef CharSliceCaster Caster; + + ComPtr<IArtifact> artifact = ArtifactUtil::createArtifactForCompileTarget(options.targetType); + + // Convert the diagnostics + + auto dstDiagnostics = ArtifactDiagnostics::create(); + const DownstreamDiagnostics_Dep1* srcDiagnostics = &result->getDiagnostics(); + + dstDiagnostics->setResult(srcDiagnostics->result); + dstDiagnostics->setRaw(Caster::asCharSlice(srcDiagnostics->rawDiagnostics)); + + for (const auto& srcDiagnostic : srcDiagnostics->diagnostics) + { + IArtifactDiagnostics::Diagnostic dstDiagnostic; + + dstDiagnostic.severity = ArtifactDiagnostic::Severity(srcDiagnostic.severity); + dstDiagnostic.stage = ArtifactDiagnostic::Stage(srcDiagnostic.stage); + + dstDiagnostic.code = Caster::asTerminatedCharSlice(srcDiagnostic.code); + dstDiagnostic.text = Caster::asTerminatedCharSlice(srcDiagnostic.text); + dstDiagnostic.filePath = Caster::asTerminatedCharSlice(srcDiagnostic.filePath); + + dstDiagnostic.location.line = srcDiagnostic.fileLine; + } + + artifact->addAssociated(dstDiagnostics); + + // We need to add a representation that can produce shared libraries/blobs on demand + + auto rep = new DownstreamResultArtifactRepresentationAdapater_Dep1(result); + artifact->addRepresentation(rep); + + *outArtifact = artifact.detach(); + return SLANG_OK; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!! SharedLibraryDep1Adapter !!!!!!!!!!!!!!!!!!!!!!!! */ + // A temporary class that adapts `ISlangSharedLibrary_Dep1` to ISlangSharedLibrary -class SharedLibraryDep1Adapter : public ComBaseObject, public ISlangSharedLibrary +class SharedLibraryAdapter_Dep1 : public ComBaseObject, public ISlangSharedLibrary { public: SLANG_COM_BASE_IUNKNOWN_ALL @@ -17,7 +141,7 @@ public: // ISlangSharedLibrary virtual SLANG_NO_THROW void* SLANG_MCALL findSymbolAddressByName(char const* name) SLANG_OVERRIDE { return m_contained->findSymbolAddressByName(name); } - SharedLibraryDep1Adapter(ISlangSharedLibrary_Dep1* dep1) : + SharedLibraryAdapter_Dep1(ISlangSharedLibrary_Dep1* dep1) : m_contained(dep1) { } @@ -42,7 +166,7 @@ protected: ComPtr<ISlangSharedLibrary_Dep1> m_contained; }; -void* SharedLibraryDep1Adapter::castAs(const SlangUUID& guid) +void* SharedLibraryAdapter_Dep1::castAs(const SlangUUID& guid) { if (auto intf = getInterface(guid)) { @@ -52,7 +176,7 @@ void* SharedLibraryDep1Adapter::castAs(const SlangUUID& guid) } /* Hack to take into account downstream compilers shared library interface might need an adapter */ -/* static */SlangResult DownstreamUtil_Dep1::getDownstreamSharedLibrary(DownstreamCompileResult* downstreamResult, ComPtr<ISlangSharedLibrary>& outSharedLibrary) +/* static */SlangResult DownstreamUtil_Dep1::getDownstreamSharedLibrary(DownstreamCompileResult_Dep1* downstreamResult, ComPtr<ISlangSharedLibrary>& outSharedLibrary) { ComPtr<ISlangSharedLibrary> lib; SLANG_RETURN_ON_FAIL(downstreamResult->getHostCallableSharedLibrary(lib)); @@ -66,7 +190,7 @@ void* SharedLibraryDep1Adapter::castAs(const SlangUUID& guid) if (SLANG_SUCCEEDED(lib->queryInterface(ISlangSharedLibrary_Dep1::getTypeGuid(), (void**)libDep1.writeRef()))) { // Okay, we need to adapt for now - outSharedLibrary = new SharedLibraryDep1Adapter(libDep1); + outSharedLibrary = new SharedLibraryAdapter_Dep1(libDep1); return SLANG_OK; } return SLANG_E_NOT_FOUND; |
