summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-downstream-dep1.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-09-01 17:41:26 -0400
committerGitHub <noreply@github.com>2022-09-01 17:41:26 -0400
commit2a869c105dcc23ede8f5e6e16b08261f45aa5aad (patch)
tree3c6d70683856608da8bc5774983786460b4f4e2d /source/compiler-core/slang-downstream-dep1.cpp
parentcc0b81350f6b681c794b4ac7c0f3b5fe73cb19eb (diff)
Upgrade slang-llvm (#2390)
* #include an absolute path didn't work - because paths were taken to always be relative. * Use IDownstreamCompiler inteface directly with updated slang-llvm. * Small tidy around includes in slang-llvm-compiler.cpp
Diffstat (limited to 'source/compiler-core/slang-downstream-dep1.cpp')
-rw-r--r--source/compiler-core/slang-downstream-dep1.cpp313
1 files changed, 0 insertions, 313 deletions
diff --git a/source/compiler-core/slang-downstream-dep1.cpp b/source/compiler-core/slang-downstream-dep1.cpp
deleted file mode 100644
index c62fc77fc..000000000
--- a/source/compiler-core/slang-downstream-dep1.cpp
+++ /dev/null
@@ -1,313 +0,0 @@
-// slang-downstream-dep1.cpp
-#include "slang-downstream-dep1.h"
-
-#include "slang-artifact-util.h"
-#include "slang-artifact-associated-impl.h"
-#include "slang-artifact-desc-util.h"
-
-#include "../core/slang-castable-util.h"
-#include "../core/slang-string-util.h"
-
-#include "slang-slice-allocator.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 == ISlangUnknown::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 !!!!!!!!!!!!!!!!!!!!!!!! */
-
-DownstreamCompilerAdapter_Dep1::DownstreamCompilerAdapter_Dep1(DownstreamCompiler_Dep1* dep, ArtifactPayload disassemblyPayload) :
- m_dep(dep),
- m_disassemblyPayload(disassemblyPayload)
-{
- auto desc = dep->getDesc();
- m_desc = DownstreamCompilerDesc(desc.type, desc.majorVersion, desc.minorVersion);
-}
-SlangResult DownstreamCompilerAdapter_Dep1::compile(const CompileOptions& inOptions, IArtifact** outArtifact)
-{
- // Currently this only for llvm, so we'll just ignore other scenarios
- if (inOptions.sourceArtifacts.count != 1)
- {
- return SLANG_FAIL;
- }
-
- IArtifact* sourceArtifact = inOptions.sourceArtifacts[0];
-
- typedef DownstreamCompileOptions_Dep1::SomeEnum SomeEnum;
-
- // Convert to the Deps1 compile options
-
- DownstreamCompileOptions_Dep1 options;
-
- options.optimizationLevel = SomeEnum(inOptions.optimizationLevel);
- options.debugInfoType = SomeEnum(inOptions.debugInfoType);
- options.targetType = inOptions.targetType;
- options.sourceLanguage = inOptions.sourceLanguage;
- options.floatingPointMode = SomeEnum(inOptions.floatingPointMode);
- options.pipelineType = SomeEnum(inOptions.pipelineType);
- options.matrixLayout = inOptions.matrixLayout;
-
- options.flags = inOptions.flags;
- options.platform = SomeEnum(inOptions.platform);
-
- options.modulePath = asString(inOptions.modulePath);
-
- for (auto& src : inOptions.defines)
- {
- DownstreamCompileOptions_Dep1::Define dst;
-
- dst.nameWithSig = asStringSlice(src.nameWithSig);
- dst.value = asStringSlice(src.value);
-
- options.defines.add(dst);
- }
-
- ComPtr<ISlangBlob> blob;
- SLANG_RETURN_ON_FAIL(sourceArtifact->loadBlob(ArtifactKeep::Yes, blob.writeRef()));
-
- options.sourceContents = StringUtil::getString(blob);
- options.sourceContentsPath = ArtifactUtil::findPath(sourceArtifact);
-
- options.includePaths = SliceUtil::toList(inOptions.includePaths);
- options.libraryPaths = SliceUtil::toList(inOptions.libraryPaths);
-
- options.libraries = SliceUtil::toComPtrList(inOptions.libraries);
-
- for (auto& src : inOptions.requiredCapabilityVersions)
- {
- DownstreamCompileOptions_Dep1::CapabilityVersion capVer;
- capVer.kind = SomeEnum(src.kind);
-
- auto& srcVer = src.version;
-
- capVer.version.m_major = srcVer.m_major;
- capVer.version.m_minor = srcVer.m_minor;
- capVer.version.m_patch = uint16_t(srcVer.m_patch);
-
- options.requiredCapabilityVersions.add(capVer);
- }
-
- options.entryPointName = asStringSlice(inOptions.entryPointName);
- options.profileName = asStringSlice(inOptions.profileName);
-
- options.stage = inOptions.stage;
-
- options.compilerSpecificArguments = SliceUtil::toList(inOptions.compilerSpecificArguments);
-
- options.fileSystemExt = inOptions.fileSystemExt;
- options.sourceManager = inOptions.sourceManager;
-
- RefPtr<DownstreamCompileResult_Dep1> result;
- SLANG_RETURN_ON_FAIL(m_dep->compile(options, result));
-
- 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(SliceUtil::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 = SliceUtil::asTerminatedCharSlice(srcDiagnostic.code);
- dstDiagnostic.text = SliceUtil::asTerminatedCharSlice(srcDiagnostic.text);
- dstDiagnostic.filePath = SliceUtil::asTerminatedCharSlice(srcDiagnostic.filePath);
-
- dstDiagnostic.location.line = srcDiagnostic.fileLine;
-
- // Add the diagnostic
- dstDiagnostics->add(dstDiagnostic);
- }
-
- 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;
-}
-
-bool DownstreamCompilerAdapter_Dep1::canConvert(const ArtifactDesc& from, const ArtifactDesc& to)
-{
- // Can only disassemble blobs that are DXBC
- return ArtifactDescUtil::isDissassembly(from, to) && from.payload == m_disassemblyPayload;
-}
-
-SlangResult DownstreamCompilerAdapter_Dep1::convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact)
-{
- if (!canConvert(from->getDesc(), to))
- {
- return SLANG_FAIL;
- }
-
- ComPtr<ISlangBlob> fromBlob;
- SLANG_RETURN_ON_FAIL(from->loadBlob(ArtifactKeep::No, fromBlob.writeRef()));
-
- const auto compileTarget = ArtifactDescUtil::getCompileTargetFromDesc(from->getDesc());
-
- // Do the disassembly
- ComPtr<ISlangBlob> dstBlob;
- SLANG_RETURN_ON_FAIL(m_dep->disassemble(compileTarget, fromBlob->getBufferPointer(), fromBlob->getBufferSize(), dstBlob.writeRef()));
-
- auto artifact = ArtifactUtil::createArtifact(to);
-
- artifact->addRepresentationUnknown(dstBlob);
-
- *outArtifact = artifact.detach();
- return SLANG_OK;
-}
-
-/* !!!!!!!!!!!!!!!!!!!!!!!!! SharedLibraryDep1Adapter !!!!!!!!!!!!!!!!!!!!!!!! */
-
-// A temporary class that adapts `ISlangSharedLibrary_Dep1` to ISlangSharedLibrary
-class SharedLibraryAdapter_Dep1 : public ComBaseObject, public ISlangSharedLibrary
-{
-public:
- SLANG_COM_BASE_IUNKNOWN_ALL
-
- // ICastable
- virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const SlangUUID& guid) SLANG_OVERRIDE;
-
- // ISlangSharedLibrary
- virtual SLANG_NO_THROW void* SLANG_MCALL findSymbolAddressByName(char const* name) SLANG_OVERRIDE { return m_contained->findSymbolAddressByName(name); }
-
- SharedLibraryAdapter_Dep1(ISlangSharedLibrary_Dep1* dep1) :
- m_contained(dep1)
- {
- }
-
-protected:
- void* getInterface(const Guid& guid)
- {
- if (guid == ISlangUnknown::getTypeGuid() ||
- guid == ICastable::getTypeGuid() ||
- guid == ISlangSharedLibrary::getTypeGuid())
- {
- return static_cast<ISlangSharedLibrary*>(this);
- }
- return nullptr;
- }
- void* getObject(const Guid& guid)
- {
- SLANG_UNUSED(guid);
- return nullptr;
- }
-
- ComPtr<ISlangSharedLibrary_Dep1> m_contained;
-};
-
-void* SharedLibraryAdapter_Dep1::castAs(const SlangUUID& guid)
-{
- if (auto intf = getInterface(guid))
- {
- return intf;
- }
- return getObject(guid);
-}
-
-/* Hack to take into account downstream compilers shared library interface might need an adapter */
-/* static */SlangResult DownstreamUtil_Dep1::getDownstreamSharedLibrary(DownstreamCompileResult_Dep1* downstreamResult, ComPtr<ISlangSharedLibrary>& outSharedLibrary)
-{
- ComPtr<ISlangSharedLibrary> lib;
- SLANG_RETURN_ON_FAIL(downstreamResult->getHostCallableSharedLibrary(lib));
-
- if (SLANG_SUCCEEDED(lib->queryInterface(ISlangSharedLibrary::getTypeGuid(), (void**)outSharedLibrary.writeRef())))
- {
- return SLANG_OK;
- }
-
- ComPtr<ISlangSharedLibrary_Dep1> libDep1;
- if (SLANG_SUCCEEDED(lib->queryInterface(ISlangSharedLibrary_Dep1::getTypeGuid(), (void**)libDep1.writeRef())))
- {
- // Okay, we need to adapt for now
- outSharedLibrary = new SharedLibraryAdapter_Dep1(libDep1);
- return SLANG_OK;
- }
- return SLANG_E_NOT_FOUND;
-}
-
-}