summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slang.h4
-rw-r--r--source/core/slang-downstream-compiler.cpp133
-rw-r--r--source/core/slang-downstream-compiler.h56
-rw-r--r--source/core/slang-gcc-compiler-util.cpp4
-rw-r--r--source/core/slang-visual-studio-compiler-util.cpp2
-rw-r--r--source/slang/slang-check.cpp13
-rw-r--r--source/slang/slang-compiler.cpp14
-rw-r--r--source/slang/slang-compiler.h5
-rw-r--r--source/slang/slang-options.cpp68
-rw-r--r--source/slang/slang-options.h1
-rw-r--r--source/slang/slang-profile.h2
-rw-r--r--source/slang/slang-state-serialize.cpp2
-rw-r--r--source/slang/slang.cpp39
-rw-r--r--tools/render-test/options.cpp33
-rw-r--r--tools/slang-test/slang-test-main.cpp50
-rw-r--r--tools/slang-test/test-context.cpp4
-rw-r--r--tools/slang-test/test-context.h2
17 files changed, 206 insertions, 226 deletions
diff --git a/slang.h b/slang.h
index 3fab11252..719ce5ee1 100644
--- a/slang.h
+++ b/slang.h
@@ -609,8 +609,8 @@ extern "C"
SLANG_LINE_DIRECTIVE_MODE_GLSL, /**< Emit GLSL-style directives with file *number* instead of name */
};
- typedef int SlangSourceLanguage;
- enum
+ typedef int SlangSourceLanguageIntegral;
+ enum SlangSourceLanguage : SlangSourceLanguageIntegral
{
SLANG_SOURCE_LANGUAGE_UNKNOWN,
SLANG_SOURCE_LANGUAGE_SLANG,
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));
}
}
diff --git a/source/core/slang-downstream-compiler.h b/source/core/slang-downstream-compiler.h
index 075f8f26a..57fb88a3c 100644
--- a/source/core/slang-downstream-compiler.h
+++ b/source/core/slang-downstream-compiler.h
@@ -120,12 +120,33 @@ public:
typedef DownstreamCompileResult CompileResult;
- enum class SourceType
+ typedef uint32_t SourceLanguageFlags;
+ struct SourceLanguageFlag
{
- C, ///< C source
- CPP, ///< C++ source
- CUDA, ///< The CUDA language
- CountOf,
+ enum Enum : SourceLanguageFlags
+ {
+ Unknown = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_UNKNOWN,
+ Slang = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_SLANG,
+ HLSL = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_HLSL,
+ GLSL = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_GLSL,
+ C = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_C,
+ CPP = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_CPP,
+ CUDA = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_CUDA,
+ };
+ };
+
+ struct Info
+ {
+ Info():sourceLanguageFlags(0) {}
+
+ Info(SourceLanguageFlags inSourceLanguageFlags):
+ sourceLanguageFlags(inSourceLanguageFlags)
+ {}
+ SourceLanguageFlags sourceLanguageFlags;
+ };
+ struct Infos
+ {
+ Info infos[int(SLANG_PASS_THROUGH_COUNT_OF)];
};
struct Desc
@@ -202,7 +223,7 @@ public:
OptimizationLevel optimizationLevel = OptimizationLevel::Default;
DebugInfoType debugInfoType = DebugInfoType::Standard;
TargetType targetType = TargetType::Executable;
- SourceType sourceType = SourceType::CPP;
+ SlangSourceLanguage sourceLanguage = SLANG_SOURCE_LANGUAGE_CPP;
FloatingPointMode floatingPointMode = FloatingPointMode::Default;
Flags flags = Flag::EnableExceptionHandling;
@@ -262,7 +283,21 @@ public:
/// Return the compiler type as name
static UnownedStringSlice getCompilerTypeAsText(SlangPassThrough type);
+ /// Get info for a compiler type
+ static const Info& getInfo(SlangPassThrough compiler) { return s_infos.infos[int(compiler)]; }
+ /// True if this compiler can compile the specified language
+ static bool canCompile(SlangPassThrough compiler, SlangSourceLanguage sourceLanguage);
+
+ /// Given a source language name returns a source language. Name here is distinct from extension
+ static SlangSourceLanguage getSourceLanguageFromName(const UnownedStringSlice& text);
+ /// Given a name returns the pass through
+ static SlangPassThrough getPassThroughFromName(const UnownedStringSlice& slice);
+ static SlangResult getPassThroughFromName(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough);
+ /// Get the compilers name
+ static UnownedStringSlice getPassThroughName(SlangPassThrough passThru);
+
protected:
+ static Infos s_infos;
DownstreamCompiler(const Desc& desc) :
m_desc(desc)
@@ -369,9 +404,9 @@ public:
void addCompiler(DownstreamCompiler* compiler);
/// Get a default compiler
- DownstreamCompiler* getDefaultCompiler(DownstreamCompiler::SourceType sourceType) const { return m_defaultCompilers[int(sourceType)]; }
+ DownstreamCompiler* getDefaultCompiler(SlangSourceLanguage sourceLanguage) const { return m_defaultCompilers[int(sourceLanguage)]; }
/// Set the default compiler
- void setDefaultCompiler(DownstreamCompiler::SourceType sourceType, DownstreamCompiler* compiler) { m_defaultCompilers[int(sourceType)] = compiler; }
+ void setDefaultCompiler(SlangSourceLanguage sourceLanguage, DownstreamCompiler* compiler) { m_defaultCompilers[int(sourceLanguage)] = compiler; }
/// True if has a compiler of the specified type
bool hasCompiler(SlangPassThrough compilerType) const;
@@ -384,7 +419,7 @@ protected:
Index _findIndex(const DownstreamCompiler::Desc& desc) const;
- RefPtr<DownstreamCompiler> m_defaultCompilers[int(DownstreamCompiler::SourceType::CountOf)];
+ RefPtr<DownstreamCompiler> m_defaultCompilers[int(SLANG_SOURCE_LANGUAGE_COUNT_OF)];
// This could be a dictionary/map - but doing a linear search is going to be fine and it makes
// somethings easier.
List<RefPtr<DownstreamCompiler>> m_compilers;
@@ -399,7 +434,6 @@ struct DownstreamCompilerBaseUtil
typedef DownstreamCompiler::OptimizationLevel OptimizationLevel;
typedef DownstreamCompiler::TargetType TargetType;
typedef DownstreamCompiler::DebugInfoType DebugInfoType;
- typedef DownstreamCompiler::SourceType SourceType;
typedef DownstreamDiagnostics::Diagnostic Diagnostic;
@@ -428,7 +462,7 @@ struct DownstreamCompilerUtil: public DownstreamCompilerBaseUtil
/// Get the information on the compiler used to compile this source
static const DownstreamCompiler::Desc& getCompiledWithDesc();
- static void updateDefault(DownstreamCompilerSet* set, DownstreamCompiler::SourceType type);
+ static void updateDefault(DownstreamCompilerSet* set, SlangSourceLanguage sourceLanguage);
static void updateDefaults(DownstreamCompilerSet* set);
static void setDefaultLocators(DownstreamCompilerLocatorFunc outFuncs[int(SLANG_PASS_THROUGH_COUNT_OF)]);
diff --git a/source/core/slang-gcc-compiler-util.cpp b/source/core/slang-gcc-compiler-util.cpp
index 7c2ec3775..833ae884e 100644
--- a/source/core/slang-gcc-compiler-util.cpp
+++ b/source/core/slang-gcc-compiler-util.cpp
@@ -406,7 +406,7 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse
PlatformKind platformKind = (options.platform == PlatformKind::Unknown) ? PlatformUtil::getPlatformKind() : options.platform;
- if (options.sourceType == SourceType::CPP)
+ if (options.sourceLanguage == SLANG_SOURCE_LANGUAGE_CPP)
{
cmdLine.addArg("-fvisibility=hidden");
@@ -570,7 +570,7 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse
cmdLine.addArg(libPath);
}
- if (options.sourceType == SourceType::CPP && !PlatformUtil::isFamily(PlatformFamily::Windows, platformKind))
+ if (options.sourceLanguage == SLANG_SOURCE_LANGUAGE_CPP && !PlatformUtil::isFamily(PlatformFamily::Windows, platformKind))
{
// Make STD libs available
cmdLine.addArg("-lstdc++");
diff --git a/source/core/slang-visual-studio-compiler-util.cpp b/source/core/slang-visual-studio-compiler-util.cpp
index 1a42e9b6e..8dcc97654 100644
--- a/source/core/slang-visual-studio-compiler-util.cpp
+++ b/source/core/slang-visual-studio-compiler-util.cpp
@@ -94,7 +94,7 @@ namespace Slang
if (options.flags & CompileOptions::Flag::EnableExceptionHandling)
{
- if (options.sourceType == SourceType::CPP)
+ if (options.sourceLanguage == SLANG_SOURCE_LANGUAGE_CPP)
{
// https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=vs-2019
// Assumes c functions cannot throw
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index 50de73f07..b04b1c9f1 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -114,7 +114,7 @@ namespace Slang
if (type == PassThroughMode::GenericCCpp)
{
- // try loading all C/C++ compilers
+ // try testing for availablilty on all C/C++ compilers
getOrLoadDownstreamCompiler(PassThroughMode::Clang, sink);
getOrLoadDownstreamCompiler(PassThroughMode::Gcc, sink);
getOrLoadDownstreamCompiler(PassThroughMode::VisualStudio, sink);
@@ -138,19 +138,20 @@ namespace Slang
DownstreamCompilerUtil::updateDefaults(m_downstreamCompilerSet);
+ DownstreamCompiler* compiler = nullptr;
+
if (type == PassThroughMode::GenericCCpp)
{
- m_downstreamCompilers[int(type)] = m_downstreamCompilerSet->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
+ compiler = m_downstreamCompilerSet->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP);
}
else
{
DownstreamCompiler::Desc desc;
desc.type = SlangPassThrough(type);
-
- m_downstreamCompilers[int(type)] = DownstreamCompilerUtil::findCompiler(m_downstreamCompilerSet, DownstreamCompilerUtil::MatchType::Newest, desc);
+ compiler = DownstreamCompilerUtil::findCompiler(m_downstreamCompilerSet, DownstreamCompilerUtil::MatchType::Newest, desc);
}
-
- return m_downstreamCompilers[int(type)];
+ m_downstreamCompilers[int(type)] = compiler;
+ return compiler;
}
SlangFuncPtr Session::getSharedLibraryFunc(SharedLibraryFuncType type, DiagnosticSink* sink)
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 16d9a5546..07bfaacc9 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -1395,18 +1395,8 @@ SlangResult dissassembleDXILUsingDXC(
}
// Set the source type
- switch (rawSourceLanguage)
- {
- case SourceLanguage::C: options.sourceType = DownstreamCompiler::SourceType::C; break;
- case SourceLanguage::CPP: options.sourceType = DownstreamCompiler::SourceType::CPP; break;
- case SourceLanguage::CUDA: options.sourceType = DownstreamCompiler::SourceType::CUDA; break;
- default:
- {
- SLANG_ASSERT(!"Unhandled source language");
- return SLANG_FAIL;
- }
- }
-
+ options.sourceLanguage = SlangSourceLanguage(rawSourceLanguage);
+
// Disable exceptions and security checks
options.flags &= ~(CompileOptions::Flag::EnableExceptionHandling | CompileOptions::Flag::EnableSecurityChecks);
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 884c1acbc..1a385ab23 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1975,12 +1975,13 @@ namespace Slang
~Session();
ComPtr<ISlangSharedLibraryLoader> m_sharedLibraryLoader; ///< The shared library loader (never null)
+
SlangFuncPtr m_sharedLibraryFunctions[int(SharedLibraryFuncType::CountOf)]; ///< Functions from shared libraries
int m_downstreamCompilerInitialized = 0;
- RefPtr<DownstreamCompilerSet> m_downstreamCompilerSet; ///< Information about all available downstream compilers.
- RefPtr<DownstreamCompiler> m_downstreamCompilers[int(PassThroughMode::CountOf)]; ///< A downstream compiler for a pass through
+ RefPtr<DownstreamCompilerSet> m_downstreamCompilerSet; ///< Information about all available downstream compilers.
+ RefPtr<DownstreamCompiler> m_downstreamCompilers[int(PassThroughMode::CountOf)]; ///< A downstream compiler for a pass through
DownstreamCompilerLocatorFunc m_downstreamCompilerLocators[int(PassThroughMode::CountOf)];
private:
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 310042b8b..f9f8db0e2 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -45,66 +45,6 @@ SlangResult tryReadCommandLineArgument(DiagnosticSink* sink, char const* option,
return SLANG_OK;
}
-#define SLANG_PASS_THROUGH_TYPES(x) \
- x(none, NONE) \
- x(fxc, FXC) \
- x(dxc, DXC) \
- x(glslang, GLSLANG) \
- x(vs, VISUAL_STUDIO) \
- x(visualstudio, VISUAL_STUDIO) \
- x(clang, CLANG) \
- x(gcc, GCC) \
- x(c, GENERIC_C_CPP) \
- x(cpp, GENERIC_C_CPP) \
- x(nvrtc, NVRTC)
-
-static SlangResult _parsePassThrough(const UnownedStringSlice& name, SlangPassThrough& outPassThrough)
-{
-#define SLANG_PASS_THROUGH_TYPE_CHECK(x, y) \
- if (name == #x) { outPassThrough = SLANG_PASS_THROUGH_##y; return SLANG_OK; }
- SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_CHECK)
- return SLANG_FAIL;
-}
-
-static SlangSourceLanguage _findSourceLanguage(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;
-}
-
-UnownedStringSlice getPassThroughName(SlangPassThrough passThru)
-{
-#define SLANG_PASS_THROUGH_TYPE_TO_NAME(x, y) \
- if (passThru == SLANG_PASS_THROUGH_##y) return UnownedStringSlice::fromLiteral(#x);
-
- SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_TO_NAME)
-
- return UnownedStringSlice::fromLiteral("unknown");
-}
-
struct OptionsParser
{
SlangSession* session = nullptr;
@@ -768,7 +708,7 @@ struct OptionsParser
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_FAILED(_parsePassThrough(name.getUnownedSlice(), passThrough)))
+ if (SLANG_FAILED(DownstreamCompiler::getPassThroughFromName(name.getUnownedSlice(), passThrough)))
{
sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, name);
return SLANG_FAIL;
@@ -1003,7 +943,7 @@ struct OptionsParser
String compilerText;
SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, compilerText));
- SlangSourceLanguage sourceLanguage = _findSourceLanguage(sourceLanguageText.getUnownedSlice());
+ SlangSourceLanguage sourceLanguage = DownstreamCompiler::getSourceLanguageFromName(sourceLanguageText.getUnownedSlice());
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
sink->diagnose(SourceLoc(), Diagnostics::unknownSourceLanguage, sourceLanguageText);
@@ -1011,7 +951,7 @@ struct OptionsParser
}
SlangPassThrough compiler;
- if (SLANG_FAILED(_parsePassThrough(compilerText.getUnownedSlice(), compiler)))
+ if (SLANG_FAILED(DownstreamCompiler::getPassThroughFromName(compilerText.getUnownedSlice(), compiler)))
{
sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, compilerText);
return SLANG_FAIL;
@@ -1045,7 +985,7 @@ struct OptionsParser
String slice = argStr.subString(1, index - 1);
SlangPassThrough passThrough = SLANG_PASS_THROUGH_NONE;
- if (SLANG_SUCCEEDED(_parsePassThrough(slice.getUnownedSlice(), passThrough)))
+ if (SLANG_SUCCEEDED(DownstreamCompiler::getPassThroughFromName(slice.getUnownedSlice(), passThrough)))
{
session->setDownstreamCompilerPath(passThrough, name.getBuffer());
continue;
diff --git a/source/slang/slang-options.h b/source/slang/slang-options.h
index bb65c937b..517975d29 100644
--- a/source/slang/slang-options.h
+++ b/source/slang/slang-options.h
@@ -7,7 +7,6 @@
namespace Slang
{
-UnownedStringSlice getPassThroughName(SlangPassThrough passThru);
UnownedStringSlice getCodeGenTargetName(SlangCompileTarget target);
diff --git a/source/slang/slang-profile.h b/source/slang/slang-profile.h
index 2996c7040..9bc8197dc 100644
--- a/source/slang/slang-profile.h
+++ b/source/slang/slang-profile.h
@@ -7,7 +7,7 @@
namespace Slang
{
// Flavors of translation unit
- enum class SourceLanguage : SlangSourceLanguage
+ enum class SourceLanguage : SlangSourceLanguageIntegral
{
Unknown = SLANG_SOURCE_LANGUAGE_UNKNOWN, // should not occur
Slang = SLANG_SOURCE_LANGUAGE_SLANG,
diff --git a/source/slang/slang-state-serialize.cpp b/source/slang/slang-state-serialize.cpp
index 113a422fa..b97756965 100644
--- a/source/slang/slang-state-serialize.cpp
+++ b/source/slang/slang-state-serialize.cpp
@@ -1228,7 +1228,7 @@ static SlangResult _calcCommandLine(OffsetBase& base, StateSerializeUtil::Reques
default:
{
cmd.addArg("-pass-through");
- cmd.addArg(getPassThroughName(SlangPassThrough(requestState->passThroughMode)));
+ cmd.addArg(DownstreamCompiler::getPassThroughName(SlangPassThrough(requestState->passThroughMode)));
break;
}
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index de3c6b0a6..fce90d612 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -205,46 +205,13 @@ SLANG_NO_THROW const char* SLANG_MCALL Session::getBuildTagString()
return SLANG_TAG_VERSION;
}
-static bool _canCompile(PassThroughMode compiler, SourceLanguage sourceLanguage)
+SLANG_NO_THROW SlangResult SLANG_MCALL Session::setDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler)
{
- switch (compiler)
+ if (DownstreamCompiler::canCompile(defaultCompiler, sourceLanguage))
{
- 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;
- }
- case PassThroughMode::NVRTC:
- {
- return sourceLanguage == SourceLanguage::CUDA;
- }
- 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 (_canCompile(compiler, sourceLanguage))
- {
- m_defaultDownstreamCompilers[int(sourceLanguage)] = compiler;
+ m_defaultDownstreamCompilers[int(sourceLanguage)] = PassThroughMode(defaultCompiler);
return SLANG_OK;
}
-
return SLANG_FAIL;
}
diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp
index 7d3fd27b5..a614336e7 100644
--- a/tools/render-test/options.cpp
+++ b/tools/render-test/options.cpp
@@ -11,6 +11,7 @@
#include "../../source/core/slang-list.h"
#include "../../source/core/slang-string-util.h"
+#include "../../source/core/slang-downstream-compiler.h"
namespace renderer_test {
using namespace Slang;
@@ -44,36 +45,6 @@ static SlangResult _setRendererType(RendererType type, const char* arg, Slang::W
return SLANG_OK;
}
-static SlangSourceLanguage _findSourceLanguage(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;
-}
-
-
SlangResult parseOptions(int argc, const char*const* argv, Slang::WriterHelper stdError)
{
using namespace Slang;
@@ -250,7 +221,7 @@ SlangResult parseOptions(int argc, const char*const* argv, Slang::WriterHelper s
}
UnownedStringSlice sourceLanguageText(*argCursor++);
- SlangSourceLanguage sourceLanguage = _findSourceLanguage(sourceLanguageText);
+ SlangSourceLanguage sourceLanguage = DownstreamCompiler::getSourceLanguageFromName(sourceLanguageText);
if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
{
stdError.print("error: expecting unknown source language name '%s' for '%s'\n", String(sourceLanguageText).getBuffer(), arg);
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 44cc73b4e..cdfe6a1a7 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -495,44 +495,6 @@ static bool _hasOption(const List<String>& args, const String& argName)
return args.indexOf(argName) != Index(-1);
}
-static SlangPassThrough _toPassThroughType(const UnownedStringSlice& slice)
-{
- if (slice == "dxc")
- {
- return SLANG_PASS_THROUGH_DXC;
- }
- else if (slice == "fxc")
- {
- return SLANG_PASS_THROUGH_FXC;
- }
- else if (slice == "glslang")
- {
- return SLANG_PASS_THROUGH_GLSLANG;
- }
- else if (slice == "c" || slice == "cpp")
- {
- return SLANG_PASS_THROUGH_GENERIC_C_CPP;
- }
- else if (slice == "clang")
- {
- return SLANG_PASS_THROUGH_CLANG;
- }
- else if (slice == "gcc")
- {
- return SLANG_PASS_THROUGH_GCC;
- }
- else if (slice == "vs" || slice == "visualstudio")
- {
- return SLANG_PASS_THROUGH_VISUAL_STUDIO;
- }
- else if (slice == "nvrtc")
- {
- return SLANG_PASS_THROUGH_NVRTC;
- }
-
- return SLANG_PASS_THROUGH_NONE;
-}
-
static PassThroughFlags _getPassThroughFlagsForTarget(SlangCompileTarget target)
{
switch (target)
@@ -740,7 +702,7 @@ static SlangResult _extractSlangCTestRequirements(const CommandLine& cmdLine, Te
String passThrough;
if (SLANG_SUCCEEDED(_extractArg(cmdLine, "-pass-through", passThrough)))
{
- ioRequirements->addUsedBackEnd(_toPassThroughType(passThrough.getUnownedSlice()));
+ ioRequirements->addUsedBackEnd(DownstreamCompiler::getPassThroughFromName(passThrough.getUnownedSlice()));
}
}
@@ -1293,7 +1255,7 @@ static String _calcModulePath(const TestInput& input)
static TestResult runCPPCompilerCompile(TestContext* context, TestInput& input)
{
- DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
+ DownstreamCompiler* compiler = context->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP);
if (!compiler)
{
return TestResult::Ignored;
@@ -1335,7 +1297,7 @@ static TestResult runCPPCompilerCompile(TestContext* context, TestInput& input)
static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& input)
{
- DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
+ DownstreamCompiler* compiler = context->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP);
if (!compiler)
{
return TestResult::Ignored;
@@ -1365,7 +1327,7 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i
// Set up the compilation options
DownstreamCompiler::CompileOptions options;
- options.sourceType = (ext == "c") ? DownstreamCompiler::SourceType::C : DownstreamCompiler::SourceType::CPP;
+ options.sourceLanguage = (ext == "c") ? SLANG_SOURCE_LANGUAGE_C : SLANG_SOURCE_LANGUAGE_CPP;
// Build a shared library
options.targetType = DownstreamCompiler::TargetType::SharedLibrary;
@@ -1453,7 +1415,7 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i
static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
{
- DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP);
+ DownstreamCompiler* compiler = context->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP);
if (!compiler)
{
return TestResult::Ignored;
@@ -1487,7 +1449,7 @@ static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
// Set up the compilation options
DownstreamCompiler::CompileOptions options;
- options.sourceType = (ext == "c") ? DownstreamCompiler::SourceType::C : DownstreamCompiler::SourceType::CPP;
+ options.sourceLanguage = (ext == "c") ? SLANG_SOURCE_LANGUAGE_C : SLANG_SOURCE_LANGUAGE_CPP;
// Compile this source
options.sourceFiles.add(filePath);
diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp
index ee5629900..0a0931596 100644
--- a/tools/slang-test/test-context.cpp
+++ b/tools/slang-test/test-context.cpp
@@ -104,9 +104,9 @@ DownstreamCompilerSet* TestContext::getCompilerSet()
return compilerSet;
}
-Slang::DownstreamCompiler* TestContext::getDefaultCompiler(DownstreamCompiler::SourceType sourceType)
+Slang::DownstreamCompiler* TestContext::getDefaultCompiler(SlangSourceLanguage sourceLanguage)
{
DownstreamCompilerSet* set = getCompilerSet();
- return set ? set->getDefaultCompiler(sourceType) : nullptr;
+ return set ? set->getDefaultCompiler(sourceLanguage) : nullptr;
}
diff --git a/tools/slang-test/test-context.h b/tools/slang-test/test-context.h
index 520e0bf1d..e10b8d60b 100644
--- a/tools/slang-test/test-context.h
+++ b/tools/slang-test/test-context.h
@@ -97,7 +97,7 @@ class TestContext
/// Get compiler set
Slang::DownstreamCompilerSet* getCompilerSet();
- Slang::DownstreamCompiler* getDefaultCompiler(Slang::DownstreamCompiler::SourceType sourceType);
+ Slang::DownstreamCompiler* getDefaultCompiler(SlangSourceLanguage sourceLanguage);
/// Ctor
TestContext();