From 31ae3467242995ab822a29c4148c2e86df2f1eb8 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 18 Jun 2020 08:10:47 -0400 Subject: Associate a downstream compiler for prelude lookup even if output is source. (#1395) Co-authored-by: Tim Foley --- source/slang/slang-emit.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 260a862ae..4af7b5989 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -731,17 +731,35 @@ SlangResult emitEntryPointSourceFromIR( Session* session = compileRequest->getSession(); // Get the downstream compiler needed for final target - PassThroughMode passThru = getDownstreamCompilerRequiredForTarget(targetRequest->target); + PassThroughMode passThru = getDownstreamCompilerRequiredForTarget(session, targetRequest->target); - // If generic CPP work out what compiler will actually be used - if (passThru == PassThroughMode::GenericCCpp) + // If nothing was *needed*, we still need some idea of which downstream compiler is going to be used for the + // prelude (the prelude is associated with each specific downstream compiler) + if (passThru == PassThroughMode::None) { - const SourceLanguage sourceLanguage = (sourceStyle == SourceStyle::C) ? SourceLanguage::C : SourceLanguage::CPP; - // Get the compiler used for the language - DownstreamCompiler* compiler = session->getDefaultDownstreamCompiler(sourceLanguage); - if (compiler) + // TODO(JS): + // NOTE! This makes the *assumption* that if we are outputting source, we don't want the + // prelude for a specific compiler, we are happy to just use the GenericCCpp + // If we didn't do this, we would have to do the work out what's available etc. + // + // This is all a bit unfortunate. The decision to associate preludes on compilers seemed like a good idea, but was perhaps a mistake. + // That it would be simpler if prelude was based on output source type. + passThru = getPreludeDownstreamCompilerForTarget(session, targetRequest->target); + } + else + { + // If a compiler was required that means a downstream compiler *will* be used + // so lookup which specific compiler is used, and use it's prelude + // Currently this distinction is only applicable to C++ + if (passThru == PassThroughMode::GenericCCpp) { - passThru = PassThroughMode(compiler->getDesc().type); + const SourceLanguage sourceLanguage = (sourceStyle == SourceStyle::C) ? SourceLanguage::C : SourceLanguage::CPP; + // Get the compiler used for the language + DownstreamCompiler* compiler = session->getDefaultDownstreamCompiler(sourceLanguage); + if (compiler) + { + passThru = PassThroughMode(compiler->getDesc().type); + } } } -- cgit v1.2.3