diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-12-04 13:49:26 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-04 13:49:26 -0500 |
| commit | 1e5ec5ca8c73e91c63b787e69c7286728f510b5e (patch) | |
| tree | 033d61c6df3b3d9567918a34f56c0fdda23bba80 /source/slang/slang.cpp | |
| parent | 0b4c1f63226eeff400eaa59be2331f0a480fd7b5 (diff) | |
Setting downstream compiler (#1144)
* WIP setting downstream compiler.
* Setting default downstream compiler for a source type.
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 98ef7400e..72014ef77 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -99,6 +99,15 @@ Session::Session() addBuiltinSource(coreLanguageScope, "core", getCoreLibraryCode()); addBuiltinSource(hlslLanguageScope, "hlsl", getHLSLLibraryCode()); + + { + for (Index i = 0; i < Index(SourceLanguage::CountOf); ++i) + { + m_defaultDownstreamCompilers[i] = PassThroughMode::None; + } + m_defaultDownstreamCompilers[Index(SourceLanguage::C)] = PassThroughMode::GenericCCpp; + m_defaultDownstreamCompilers[Index(SourceLanguage::CPP)] = PassThroughMode::GenericCCpp; + } } ISlangUnknown* Session::getInterface(const Guid& guid) @@ -220,6 +229,74 @@ SLANG_NO_THROW const char* SLANG_MCALL Session::getBuildTagString() return SLANG_TAG_VERSION; } +static bool _canCompile(PassThroughMode compiler, SourceLanguage sourceLanguage) +{ + switch (compiler) + { + case PassThroughMode::Fxc: + case PassThroughMode::Dxc: + { + return sourceLanguage == SourceLanguage::HLSL; + } + case PassThroughMode::Glslang: + { + return sourceLanguage == SourceLanguage::GLSL; + } + case PassThroughMode::Clang: + case PassThroughMode::VisualStudio: + case PassThroughMode::Gcc: + case PassThroughMode::GenericCCpp: + { + return sourceLanguage == SourceLanguage::C || sourceLanguage == SourceLanguage::CPP; + } + default: break; + } + return false; +} + +SLANG_NO_THROW SlangResult SLANG_MCALL Session::setDefaultDownstreamCompiler(SlangSourceLanguage inSourceLanguage, SlangPassThrough defaultCompiler) +{ + auto sourceLanguage = SourceLanguage(inSourceLanguage); + auto compiler = PassThroughMode(defaultCompiler); + + if (sourceLanguage == SourceLanguage::C || sourceLanguage == SourceLanguage::CPP) + { + if (_canCompile(compiler, sourceLanguage)) + { + m_defaultDownstreamCompilers[int(sourceLanguage)] = compiler; + return SLANG_OK; + } + } + + return SLANG_FAIL; +} + +SlangPassThrough SLANG_MCALL Session::getDefaultDownstreamCompiler(SlangSourceLanguage inSourceLanguage) +{ + SLANG_ASSERT(inSourceLanguage >= 0 && inSourceLanguage < SLANG_SOURCE_LANGUAGE_COUNT_OF); + auto sourceLanguage = SourceLanguage(inSourceLanguage); + return SlangPassThrough(m_defaultDownstreamCompilers[int(sourceLanguage)]); +} + +CPPCompiler* Session::getCPPCompiler(PassThroughMode compiler) +{ + CPPCompilerSet* compilerSet = requireCPPCompilerSet(); + switch (compiler) + { + case PassThroughMode::GenericCCpp: return compilerSet->getDefaultCompiler(); + case PassThroughMode::Clang: return CPPCompilerUtil::findCompiler(compilerSet, CPPCompilerUtil::MatchType::Newest, CPPCompiler::Desc(CPPCompiler::CompilerType::Clang)); + case PassThroughMode::VisualStudio: return CPPCompilerUtil::findCompiler(compilerSet, CPPCompilerUtil::MatchType::Newest, CPPCompiler::Desc(CPPCompiler::CompilerType::VisualStudio)); + case PassThroughMode::Gcc: return CPPCompilerUtil::findCompiler(compilerSet, CPPCompilerUtil::MatchType::Newest, CPPCompiler::Desc(CPPCompiler::CompilerType::GCC)); + default: break; + } + return nullptr; +} + +CPPCompiler* Session::getDefaultCPPCompiler(SourceLanguage sourceLanguage) +{ + return getCPPCompiler(m_defaultDownstreamCompilers[int(sourceLanguage)]); +} + struct IncludeHandlerImpl : IncludeHandler { Linkage* linkage; |
