summaryrefslogtreecommitdiffstats
path: root/source/core/slang-downstream-compiler.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-12-12 16:14:27 -0500
committerGitHub <noreply@github.com>2019-12-12 16:14:27 -0500
commita2d4d447639a1860f9de4ba9e2435f1d40ff3669 (patch)
tree028e8ddc77ccd08bcb189204de8a1469535d2507 /source/core/slang-downstream-compiler.cpp
parent15335549340c54fd7b89b28104ddc907e9c64638 (diff)
Feature/source downstream compiler (#1153)
* CPPCompiler -> DownstreamCompiler * Added DownstreamCompileResult to start abstraction such that we don't need files. * * Split out slang-blob.cpp * Made CompileResult hold a DownstreamCompileResult - for access to binary or ISlangSharedLibrary * Keep temporary files in scope. * Add a hash to the hex dump stream. * Move all file tracking into DownstreamCompiler. * WIP support for nvrtc. * WIP: Adding support for nvrtc compiler. Adding enum types, wiring up the nvrtc into slang. * Fix remaining CPPCompiler references. * Fix order issue on target string matching. * Use ISlangSharedLibrary for nvrtc. * Use DownstreamCompiler for nvrtc. * WIP first pass at compilation win nvrtc. * Added testing if file is on file system into CommandLineDownstreamCompiler. Added sourceContentsPath. * Make test cuda-compile.cu work by just compiling not comparing output. * Genearlize DownstreamCompiler usage. * Fix warning on clang. * Remove CompilerType from DownstreamCompiler. * Use DownstreamCompiler interface for all compilers. NOTE for FXC, DXC and GLSLANG this doesn't mean using 'compile' - it's still extracting functions from shared library. * Replace DownstreamCompiler::SourceType -> SlangSourceLanguage * Replace _canCompile with something data driven. * Fix compiling on gcc/clang for DownstreamCompiler. * Moved some text conversions into DownstreamCompiler. * Fix problem on non-vc builds with not having return on locateCompilers for VS. * Change so no warning for code not reachable on locateCompilers for vs.
Diffstat (limited to 'source/core/slang-downstream-compiler.cpp')
-rw-r--r--source/core/slang-downstream-compiler.cpp133
1 files changed, 124 insertions, 9 deletions
diff --git a/source/core/slang-downstream-compiler.cpp b/source/core/slang-downstream-compiler.cpp
index 6ce526ef0..2e78ea22b 100644
--- a/source/core/slang-downstream-compiler.cpp
+++ b/source/core/slang-downstream-compiler.cpp
@@ -20,6 +20,29 @@
namespace Slang
{
+static DownstreamCompiler::Infos _calcInfos()
+{
+ typedef DownstreamCompiler::Info Info;
+ typedef DownstreamCompiler::SourceLanguageFlag SourceLanguageFlag;
+ typedef DownstreamCompiler::SourceLanguageFlags SourceLanguageFlags;
+
+ DownstreamCompiler::Infos infos;
+
+ infos.infos[int(SLANG_PASS_THROUGH_CLANG)] = Info(SourceLanguageFlag::CPP | SourceLanguageFlag::C);
+ infos.infos[int(SLANG_PASS_THROUGH_VISUAL_STUDIO)] = Info(SourceLanguageFlag::CPP | SourceLanguageFlag::C);
+ infos.infos[int(SLANG_PASS_THROUGH_GCC)] = Info(SourceLanguageFlag::CPP | SourceLanguageFlag::C);
+
+ infos.infos[int(SLANG_PASS_THROUGH_NVRTC)] = Info(SourceLanguageFlag::CUDA);
+
+ infos.infos[int(SLANG_PASS_THROUGH_DXC)] = Info(SourceLanguageFlag::HLSL);
+ infos.infos[int(SLANG_PASS_THROUGH_FXC)] = Info(SourceLanguageFlag::HLSL);
+ infos.infos[int(SLANG_PASS_THROUGH_GLSLANG)] = Info(SourceLanguageFlag::GLSL);
+
+ return infos;
+}
+
+/* static */DownstreamCompiler::Infos DownstreamCompiler::s_infos = _calcInfos();
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DownstreamCompiler::Desc !!!!!!!!!!!!!!!!!!!!!!*/
void DownstreamCompiler::Desc::appendAsText(StringBuilder& out) const
@@ -67,6 +90,98 @@ void DownstreamCompiler::Desc::appendAsText(StringBuilder& out) const
}
}
+/* static */bool DownstreamCompiler::canCompile(SlangPassThrough compiler, SlangSourceLanguage sourceLanguage)
+{
+ const auto& info = getInfo(compiler);
+ return (info.sourceLanguageFlags & (SourceLanguageFlags(1) << int(sourceLanguage))) != 0;
+}
+
+/* static */SlangSourceLanguage DownstreamCompiler::getSourceLanguageFromName(const UnownedStringSlice& text)
+{
+ if (text == "c" || text == "C")
+ {
+ return SLANG_SOURCE_LANGUAGE_C;
+ }
+ else if (text == "cpp" || text == "c++" || text == "C++" || text == "cxx")
+ {
+ return SLANG_SOURCE_LANGUAGE_CPP;
+ }
+ else if (text == "slang")
+ {
+ return SLANG_SOURCE_LANGUAGE_SLANG;
+ }
+ else if (text == "glsl")
+ {
+ return SLANG_SOURCE_LANGUAGE_GLSL;
+ }
+ else if (text == "hlsl")
+ {
+ return SLANG_SOURCE_LANGUAGE_HLSL;
+ }
+ else if (text == "cu" || text == "cuda")
+ {
+ return SLANG_SOURCE_LANGUAGE_CUDA;
+ }
+ return SLANG_SOURCE_LANGUAGE_UNKNOWN;
+}
+
+#define SLANG_PASS_THROUGH_TYPES(x) \
+ x(none, NONE) \
+ x(fxc, FXC) \
+ x(dxc, DXC) \
+ x(glslang, GLSLANG) \
+ x(visualstudio, VISUAL_STUDIO) \
+ x(clang, CLANG) \
+ x(gcc, GCC) \
+ x(genericcpp, GENERIC_C_CPP) \
+ x(nvrtc, NVRTC)
+
+
+
+/* static */SlangPassThrough DownstreamCompiler::getPassThroughFromName(const UnownedStringSlice& slice)
+{
+#define SLANG_PASS_THROUGH_NAME_TO_TYPE(x, y) \
+ if (slice == UnownedStringSlice::fromLiteral(#x)) return SLANG_PASS_THROUGH_##y;
+
+ SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_NAME_TO_TYPE)
+
+ // Other options
+ if (slice == "c" || slice == "cpp")
+ {
+ return SLANG_PASS_THROUGH_GENERIC_C_CPP;
+ }
+ else if (slice == "vs")
+ {
+ return SLANG_PASS_THROUGH_VISUAL_STUDIO;
+ }
+
+ return SLANG_PASS_THROUGH_NONE;
+}
+
+/* static */SlangResult DownstreamCompiler::getPassThroughFromName(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough)
+{
+ outPassThrough = getPassThroughFromName(slice);
+ // It could be none on error - if it's not equal to "none" then it msut be an error
+ if (outPassThrough == SLANG_PASS_THROUGH_NONE && slice != UnownedStringSlice::fromLiteral("none"))
+ {
+ return SLANG_FAIL;
+ }
+ return SLANG_OK;
+}
+
+/* static */UnownedStringSlice DownstreamCompiler::getPassThroughName(SlangPassThrough passThru)
+{
+#define SLANG_PASS_THROUGH_TYPE_TO_NAME(x, y) \
+ case SLANG_PASS_THROUGH_##y: return UnownedStringSlice::fromLiteral(#x);
+
+ switch (passThru)
+ {
+ SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_TO_NAME)
+ default: break;
+ }
+ return UnownedStringSlice::fromLiteral("unknown");
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DownstreamDiagnostics !!!!!!!!!!!!!!!!!!!!!!*/
Index DownstreamDiagnostics::getCountByType(Diagnostic::Type type) const
@@ -284,7 +399,7 @@ SlangResult CommandLineDownstreamCompiler::compile(const CompileOptions& inOptio
compileSourcePath.append("-src");
// Make the temporary filename have the appropriate extension.
- if (options.sourceType == DownstreamCompiler::SourceType::C)
+ if (options.sourceLanguage == SLANG_SOURCE_LANGUAGE_C)
{
compileSourcePath.append(".c");
}
@@ -515,19 +630,19 @@ const DownstreamCompiler::Desc& DownstreamCompilerUtil::getCompiledWithDesc()
return findClosestCompiler(compilers, desc);
}
-/* static */void DownstreamCompilerUtil::updateDefault(DownstreamCompilerSet* set, DownstreamCompiler::SourceType type)
+/* static */void DownstreamCompilerUtil::updateDefault(DownstreamCompilerSet* set, SlangSourceLanguage sourceLanguage)
{
DownstreamCompiler* compiler = nullptr;
- switch (type)
+ switch (sourceLanguage)
{
- case DownstreamCompiler::SourceType::CPP:
- case DownstreamCompiler::SourceType::C:
+ case SLANG_SOURCE_LANGUAGE_CPP:
+ case SLANG_SOURCE_LANGUAGE_C:
{
compiler = findClosestCompiler(set, getCompiledWithDesc());
break;
}
- case DownstreamCompiler::SourceType::CUDA:
+ case SLANG_SOURCE_LANGUAGE_CUDA:
{
DownstreamCompiler::Desc desc;
desc.type = SLANG_PASS_THROUGH_NVRTC;
@@ -537,14 +652,14 @@ const DownstreamCompiler::Desc& DownstreamCompilerUtil::getCompiledWithDesc()
default: break;
}
- set->setDefaultCompiler(type, compiler);
+ set->setDefaultCompiler(sourceLanguage, compiler);
}
/* static */void DownstreamCompilerUtil::updateDefaults(DownstreamCompilerSet* set)
{
- for (Index i = 0; i < Index(DownstreamCompiler::SourceType::CountOf); ++i)
+ for (Index i = 0; i < Index(SLANG_SOURCE_LANGUAGE_COUNT_OF); ++i)
{
- updateDefault(set, DownstreamCompiler::SourceType(i));
+ updateDefault(set, SlangSourceLanguage(i));
}
}