summaryrefslogtreecommitdiff
path: root/source/slang/slang-options.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-12-04 13:49:26 -0500
committerGitHub <noreply@github.com>2019-12-04 13:49:26 -0500
commit1e5ec5ca8c73e91c63b787e69c7286728f510b5e (patch)
tree033d61c6df3b3d9567918a34f56c0fdda23bba80 /source/slang/slang-options.cpp
parent0b4c1f63226eeff400eaa59be2331f0a480fd7b5 (diff)
Setting downstream compiler (#1144)
* WIP setting downstream compiler. * Setting default downstream compiler for a source type.
Diffstat (limited to 'source/slang/slang-options.cpp')
-rw-r--r--source/slang/slang-options.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 92310c1c1..1523170cf 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -65,6 +65,31 @@ static SlangResult _parsePassThrough(const UnownedStringSlice& name, SlangPassTh
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;
+ }
+ return SLANG_SOURCE_LANGUAGE_UNKNOWN;
+}
+
UnownedStringSlice getPassThroughName(SlangPassThrough passThru)
{
#define SLANG_PASS_THROUGH_TYPE_TO_NAME(x, y) \
@@ -962,6 +987,33 @@ struct OptionsParser
{
requestImpl->getBackEndReq()->shouldEmitSPIRVDirectly = true;
}
+ else if (argStr == "-default-downstream-compiler")
+ {
+ String sourceLanguageText;
+ SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, sourceLanguageText));
+ String compilerText;
+ SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, compilerText));
+
+ SlangSourceLanguage sourceLanguage = _findSourceLanguage(sourceLanguageText.getUnownedSlice());
+ if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN)
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::unknownSourceLanguage, sourceLanguageText);
+ return SLANG_FAIL;
+ }
+
+ SlangPassThrough compiler;
+ if (SLANG_FAILED(_parsePassThrough(compilerText.getUnownedSlice(), compiler)))
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::unknownPassThroughTarget, compilerText);
+ return SLANG_FAIL;
+ }
+
+ if (SLANG_FAILED(session->setDefaultDownstreamCompiler(sourceLanguage, compiler)))
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::unableToSetDefaultDownstreamCompiler, compilerText, sourceLanguageText, compilerText);
+ return SLANG_FAIL;
+ }
+ }
else if (argStr == "--")
{
// The `--` option causes us to stop trying to parse options,