diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-03-10 12:24:51 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-10 12:24:51 -0500 |
| commit | e39893e8eb1a9411fca4e5f885456a27a770d3a2 (patch) | |
| tree | bcd2f6aa99b5e6425c17d31f5e4a89b98c854f34 /source/compiler-core/slang-llvm-compiler.cpp | |
| parent | e06cfb37eb099e45302dd015b0396bf26c913778 (diff) | |
Add struct version to DownstreamCompiler::CompileOptions interface (#2692)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add versioning to CompileOptions for DownstreamCompiler so we can add new options without breaking binary interface.
* Use builtin offset of directly.
Diffstat (limited to 'source/compiler-core/slang-llvm-compiler.cpp')
| -rw-r--r-- | source/compiler-core/slang-llvm-compiler.cpp | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/source/compiler-core/slang-llvm-compiler.cpp b/source/compiler-core/slang-llvm-compiler.cpp index 382dd0842..b34c05d42 100644 --- a/source/compiler-core/slang-llvm-compiler.cpp +++ b/source/compiler-core/slang-llvm-compiler.cpp @@ -6,6 +6,42 @@ namespace Slang { +class AliasDepreciatedDownstreamCompiler : public DownstreamCompilerBase +{ +public: + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL compile(const CompileOptions& options, IArtifact** outArtifact) SLANG_OVERRIDE; + virtual SLANG_NO_THROW bool SLANG_MCALL canConvert(const ArtifactDesc& from, const ArtifactDesc& to) SLANG_OVERRIDE { return m_inner->canConvert(from, to); } + virtual SLANG_NO_THROW SlangResult SLANG_MCALL convert(IArtifact* from, const ArtifactDesc& to, IArtifact** outArtifact) SLANG_OVERRIDE { return m_inner->convert(from, to, outArtifact); } + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getVersionString(slang::IBlob** outVersionString) { return m_inner->getVersionString(outVersionString); } + virtual SLANG_NO_THROW bool SLANG_MCALL isFileBased() { return m_inner->isFileBased(); } + + template <typename T> + void initCompileOptionsDepreciated() + { + m_compileOptionsOffset = T::kStart; + } + + AliasDepreciatedDownstreamCompiler(IDownstreamCompiler* inner) : + m_inner(inner) + { + m_desc = inner->getDesc(); + } + + ComPtr<IDownstreamCompiler> m_inner; + ptrdiff_t m_compileOptionsOffset = 0; +}; + +SlangResult AliasDepreciatedDownstreamCompiler::compile(const CompileOptions& options, IArtifact** outArtifact) +{ + if (m_compileOptionsOffset == 0) + { + return m_inner->compile(options, outArtifact); + } + const uint8_t* ptr = ((const uint8_t*)&options) + m_compileOptionsOffset; + return m_inner->compile(*(const CompileOptions*)ptr, outArtifact); +} + /* static */SlangResult LLVMDownstreamCompilerUtil::locateCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set) { ComPtr<ISlangSharedLibrary> library; @@ -20,15 +56,27 @@ namespace Slang typedef SlangResult(*CreateDownstreamCompilerFunc)(const Guid& intf, IDownstreamCompiler** outCompiler); - auto fn = (CreateDownstreamCompilerFunc)library->findFuncByName("createLLVMDownstreamCompiler_V2"); - if (!fn) + ComPtr<IDownstreamCompiler> downstreamCompiler; + + if (auto fnV2 = (CreateDownstreamCompilerFunc)library->findFuncByName("createLLVMDownstreamCompiler_V2")) { - return SLANG_FAIL; - } + ComPtr<IDownstreamCompiler> innerDownstreamCompiler; - ComPtr<IDownstreamCompiler> downstreamCompiler; + SLANG_RETURN_ON_FAIL(fnV2(IDownstreamCompiler::getTypeGuid(), innerDownstreamCompiler.writeRef())); - SLANG_RETURN_ON_FAIL(fn(IDownstreamCompiler::getTypeGuid(), downstreamCompiler.writeRef())); + // We then need to wrap + AliasDepreciatedDownstreamCompiler* fix = new AliasDepreciatedDownstreamCompiler(innerDownstreamCompiler); + downstreamCompiler = fix; + fix->initCompileOptionsDepreciated<DownstreamCompileOptions_AliasDepreciated1>(); + } + else if (auto fnV3 = (CreateDownstreamCompilerFunc)library->findFuncByName("createLLVMDownstreamCompiler_V3")) + { + SLANG_RETURN_ON_FAIL(fnV3(IDownstreamCompiler::getTypeGuid(), downstreamCompiler.writeRef())); + } + else + { + return SLANG_FAIL; + } set->addSharedLibrary(library); set->addCompiler(downstreamCompiler); |
