From 1e5ec5ca8c73e91c63b787e69c7286728f510b5e Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 4 Dec 2019 13:49:26 -0500 Subject: Setting downstream compiler (#1144) * WIP setting downstream compiler. * Setting default downstream compiler for a source type. --- source/slang/slang-options.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'source/slang/slang-options.cpp') 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, -- cgit v1.2.3