summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-06-18 16:39:06 -0400
committerGitHub <noreply@github.com>2020-06-18 13:39:06 -0700
commit5952e3b3d7f505a7e6d71ecd0793911224f5bac3 (patch)
treeaa2fe85ae3ac6af4db98654489592120ab1a1f17 /source
parentdfbe3cfcdb308cdb0f89cb2844fb3aba96cfcaec (diff)
Prelude is associated with SourceLanguage (#1398)
* Associate a downstream compiler for prelude lookup even if output is source. * Remove LanguageStyle and just use SourceLanguage instread. * Added set/getPrelude. Made prelude work on source language. * Fix typo in method name replacement. get/SetPrelude get/setLanguagePrelude * Fix issue because of method name change. * Remove getPreludeDownstreamCompilerForTarget
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-test-tool-util.cpp21
-rw-r--r--source/slang/slang-compiler.cpp89
-rw-r--r--source/slang/slang-compiler.h18
-rw-r--r--source/slang/slang-emit-c-like.cpp64
-rw-r--r--source/slang/slang-emit-c-like.h23
-rw-r--r--source/slang/slang-emit-glsl.cpp6
-rw-r--r--source/slang/slang-emit-hlsl.cpp4
-rw-r--r--source/slang/slang-emit.cpp61
-rw-r--r--source/slang/slang.cpp45
9 files changed, 148 insertions, 183 deletions
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp
index 3b89321a1..f8e163758 100644
--- a/source/core/slang-test-tool-util.cpp
+++ b/source/core/slang-test-tool-util.cpp
@@ -59,19 +59,9 @@ static SlangResult _addCPPPrelude(const String& parentPath, slang::IGlobalSessio
{
String includePath;
SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cpp-prelude.h", includePath));
-
StringBuilder prelude;
prelude << "#include \"" << includePath << "\"\n\n";
- const SlangPassThrough downstreamCompilers[] = {
- SLANG_PASS_THROUGH_CLANG, ///< Clang C/C++ compiler
- SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio C/C++ compiler
- SLANG_PASS_THROUGH_GCC, ///< GCC C/C++ compiler
- SLANG_PASS_THROUGH_GENERIC_C_CPP,
- };
- for (auto downstreamCompiler : downstreamCompilers)
- {
- session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
- }
+ session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CPP, prelude.getBuffer());
return SLANG_OK;
}
@@ -79,16 +69,9 @@ static SlangResult _addCUDAPrelude(const String& parentPath, slang::IGlobalSessi
{
String includePath;
SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cuda-prelude.h", includePath));
-
StringBuilder prelude;
prelude << "#include \"" << includePath << "\"\n\n";
- const SlangPassThrough downstreamCompilers[] = {
- SLANG_PASS_THROUGH_NVRTC, ///< nvrtc CUDA compiler
- };
- for (auto downstreamCompiler : downstreamCompilers)
- {
- session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
- }
+ session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CUDA, prelude.getBuffer());
return SLANG_OK;
}
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index b64169db4..fe0f7d69c 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -408,36 +408,58 @@ namespace Slang
return session->getOrLoadDownstreamCompiler(passThrough, nullptr) ? SLANG_OK: SLANG_E_NOT_FOUND;
}
- PassThroughMode getPreludeDownstreamCompilerForTarget(Session* session, CodeGenTarget target)
+ SourceLanguage getDefaultSourceLanguageForDownstreamCompiler(PassThroughMode compiler)
{
- switch (target)
+ switch (compiler)
{
- case CodeGenTarget::None:
+ case PassThroughMode::None:
{
- return PassThroughMode::None;
+ return SourceLanguage::Unknown;
}
- case CodeGenTarget::GLSL:
+ case PassThroughMode::Fxc:
+ case PassThroughMode::Dxc:
{
- // For the prelude we'll use Glslang
- return PassThroughMode::Glslang;
+ return SourceLanguage::HLSL;
}
- case CodeGenTarget::HLSL:
+ case PassThroughMode::Glslang:
{
- // Use the default compiler for the source language if set,
- DownstreamCompiler* downstreamCompiler = session->getDefaultDownstreamCompiler(SourceLanguage::HLSL);
- if (downstreamCompiler)
- {
- return PassThroughMode(downstreamCompiler->getDesc().type);
- }
- else
- {
- // This is ambiguous, because we could use dxc or fxc. For now we'll go with Dxc.
- return PassThroughMode::Dxc;
- }
+ return SourceLanguage::GLSL;
+ }
+ case PassThroughMode::Clang:
+ case PassThroughMode::VisualStudio:
+ case PassThroughMode::Gcc:
+ case PassThroughMode::GenericCCpp:
+ {
+ // These could ingest C, but we only have this function to work out a
+ // 'default' language to ingest.
+ return SourceLanguage::CPP;
}
+ case PassThroughMode::NVRTC:
+ {
+ return SourceLanguage::CUDA;
+ }
+ default: break;
+ }
+ SLANG_ASSERT(!"Unknown compiler");
+ return SourceLanguage::Unknown;
+ }
+
+ PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target)
+ {
+ switch (target)
+ {
+ // Don't *require* a downstream compiler for source output
+ case CodeGenTarget::GLSL:
+ case CodeGenTarget::HLSL:
case CodeGenTarget::CUDASource:
+ case CodeGenTarget::CPPSource:
+ case CodeGenTarget::CSource:
{
- return PassThroughMode::NVRTC;
+ return PassThroughMode::None;
+ }
+ case CodeGenTarget::None:
+ {
+ return PassThroughMode::None;
}
case CodeGenTarget::SPIRVAssembly:
case CodeGenTarget::SPIRV:
@@ -459,12 +481,6 @@ namespace Slang
{
return PassThroughMode::Glslang;
}
- case CodeGenTarget::CPPSource:
- case CodeGenTarget::CSource:
- {
- // We'll just use the generic C/C++ compiler
- return PassThroughMode::GenericCCpp;
- }
case CodeGenTarget::HostCallable:
case CodeGenTarget::SharedLibrary:
case CodeGenTarget::Executable:
@@ -484,28 +500,9 @@ namespace Slang
return PassThroughMode::None;
}
- PassThroughMode getDownstreamCompilerRequiredForTarget(Session* session, CodeGenTarget target)
- {
- switch (target)
- {
- // Don't *require* a downstream compiler for source output
- case CodeGenTarget::GLSL:
- case CodeGenTarget::HLSL:
- case CodeGenTarget::CUDASource:
- case CodeGenTarget::CPPSource:
- case CodeGenTarget::CSource:
- {
- return PassThroughMode::None;
- }
- default: break;
- }
-
- return getPreludeDownstreamCompilerForTarget(session, target);
- }
-
SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target)
{
- const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(session, target);
+ const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target);
return (mode != PassThroughMode::None) ?
checkExternalCompilerSupport(session, mode) :
SLANG_OK;
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index ba0c94e99..e4b537e19 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1191,9 +1191,9 @@ namespace Slang
};
/// Given a target returns the required downstream compiler
- PassThroughMode getDownstreamCompilerRequiredForTarget(Session* session, CodeGenTarget target);
+ PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target);
/// Given a target returns a downstream compiler the prelude should be taken from.
- PassThroughMode getPreludeDownstreamCompilerForTarget(Session* session, CodeGenTarget target);
+ SourceLanguage getDefaultSourceLanguageForDownstreamCompiler(PassThroughMode compiler);
struct TypeCheckingCache;
@@ -2033,7 +2033,10 @@ namespace Slang
SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage) override;
- /// Get the default cpp compiler for a language
+ SLANG_NO_THROW void SLANG_MCALL setLanguagePrelude(SlangSourceLanguage inSourceLanguage, char const* prelude) override;
+ SLANG_NO_THROW void SLANG_MCALL getLanguagePrelude(SlangSourceLanguage inSourceLanguage, ISlangBlob** outPrelude) override;
+
+ /// Get the default compiler for a language
DownstreamCompiler* getDefaultDownstreamCompiler(SourceLanguage sourceLanguage);
enum class SharedLibraryFuncType
@@ -2103,8 +2106,8 @@ namespace Slang
SlangFuncPtr getSharedLibraryFunc(SharedLibraryFuncType type, DiagnosticSink* sink);
- /// Get the downstream compiler prelude
- const String& getDownstreamCompilerPrelude(PassThroughMode mode) { return m_downstreamCompilerPreludes[int(mode)]; }
+ /// Get the prelude associated with the language
+ const String& getPreludeForLanguage(SourceLanguage language) { return m_languagePreludes[int(language)]; }
void init();
@@ -2128,12 +2131,11 @@ namespace Slang
SlangResult _loadRequest(EndToEndCompileRequest* request, const void* data, size_t size);
-
/// Linkage used for all built-in (stdlib) code.
RefPtr<Linkage> m_builtinLinkage;
- String m_downstreamCompilerPaths[int(PassThroughMode::CountOf)]; ///< Paths for each pass through
- String m_downstreamCompilerPreludes[int(PassThroughMode::CountOf)]; ///< Prelude for each type of target
+ String m_downstreamCompilerPaths[int(PassThroughMode::CountOf)]; ///< Paths for each pass through
+ String m_languagePreludes[int(SourceLanguage::CountOf)]; ///< Prelude for each source language
PassThroughMode m_defaultDownstreamCompilers[int(SourceLanguage::CountOf)];
};
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index eae3bdedc..6c004c84c 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -78,7 +78,7 @@ struct CLikeSourceEmitter::ComputeEmitActionsContext
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!! CLikeSourceEmitter !!!!!!!!!!!!!!!!!!!!!!!!!! */
-/* static */CLikeSourceEmitter::SourceStyle CLikeSourceEmitter::getSourceStyle(CodeGenTarget target)
+/* static */SourceLanguage CLikeSourceEmitter::getSourceLanguage(CodeGenTarget target)
{
switch (target)
{
@@ -86,17 +86,17 @@ struct CLikeSourceEmitter::ComputeEmitActionsContext
case CodeGenTarget::Unknown:
case CodeGenTarget::None:
{
- return SourceStyle::Unknown;
+ return SourceLanguage::Unknown;
}
case CodeGenTarget::GLSL:
case CodeGenTarget::GLSL_Vulkan:
case CodeGenTarget::GLSL_Vulkan_OneDesc:
{
- return SourceStyle::GLSL;
+ return SourceLanguage::GLSL;
}
case CodeGenTarget::HLSL:
{
- return SourceStyle::HLSL;
+ return SourceLanguage::HLSL;
}
case CodeGenTarget::PTX:
case CodeGenTarget::SPIRV:
@@ -106,19 +106,19 @@ struct CLikeSourceEmitter::ComputeEmitActionsContext
case CodeGenTarget::DXIL:
case CodeGenTarget::DXILAssembly:
{
- return SourceStyle::Unknown;
+ return SourceLanguage::Unknown;
}
case CodeGenTarget::CSource:
{
- return SourceStyle::C;
+ return SourceLanguage::C;
}
case CodeGenTarget::CPPSource:
{
- return SourceStyle::CPP;
+ return SourceLanguage::CPP;
}
case CodeGenTarget::CUDASource:
{
- return SourceStyle::CUDA;
+ return SourceLanguage::CUDA;
}
}
}
@@ -126,8 +126,8 @@ struct CLikeSourceEmitter::ComputeEmitActionsContext
CLikeSourceEmitter::CLikeSourceEmitter(const Desc& desc)
{
m_writer = desc.sourceWriter;
- m_sourceStyle = getSourceStyle(desc.target);
- SLANG_ASSERT(m_sourceStyle != SourceStyle::Unknown);
+ m_sourceLanguage = getSourceLanguage(desc.target);
+ SLANG_ASSERT(m_sourceLanguage != SourceLanguage::Unknown);
m_target = desc.target;
@@ -389,17 +389,17 @@ void CLikeSourceEmitter::maybeCloseParens(bool needClose)
bool CLikeSourceEmitter::isTargetIntrinsicModifierApplicable(const String& targetName)
{
- switch(getSourceStyle())
+ switch(getSourceLanguage())
{
default:
SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled code generation target");
return false;
- case SourceStyle::C: return targetName == "c";
- case SourceStyle::CPP: return targetName == "cpp";
- case SourceStyle::GLSL: return targetName == "glsl";
- case SourceStyle::HLSL: return targetName == "hlsl";
- case SourceStyle::CUDA: return targetName == "cuda";
+ case SourceLanguage::C: return targetName == "c";
+ case SourceLanguage::CPP: return targetName == "cpp";
+ case SourceLanguage::GLSL: return targetName == "glsl";
+ case SourceLanguage::HLSL: return targetName == "hlsl";
+ case SourceLanguage::CUDA: return targetName == "cuda";
}
}
@@ -552,7 +552,7 @@ String CLikeSourceEmitter::scrubName(const String& name)
// and write some legal characters to the output as we go.
StringBuilder sb;
- if(getSourceStyle() == SourceStyle::GLSL)
+ if(getSourceLanguage() == SourceLanguage::GLSL)
{
// GLSL reserves all names that start with `gl_`,
// so if we are in danger of collision, then make
@@ -667,7 +667,7 @@ String CLikeSourceEmitter::generateName(IRInst* inst)
auto entryPointDecor = inst->findDecoration<IREntryPointDecoration>();
if (entryPointDecor)
{
- if (getSourceStyle() == SourceStyle::GLSL)
+ if (getSourceLanguage() == SourceLanguage::GLSL)
{
// GLSL will always need to use `main` as the
// name for an entry-point function, but other
@@ -1011,7 +1011,7 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst)
// GLSL doesn't allow texture/resource types to
// be used as first-class values, so we need
// to fold them into their use sites in all cases
- if (getSourceStyle() == SourceStyle::GLSL)
+ if (getSourceLanguage() == SourceLanguage::GLSL)
{
if(as<IRResourceTypeBase>(type))
{
@@ -1219,12 +1219,12 @@ void CLikeSourceEmitter::emitInstResultDecl(IRInst* inst)
{
// "Ordinary" instructions at module scope are constants
- switch (getSourceStyle())
+ switch (getSourceLanguage())
{
- case SourceStyle::CUDA:
- case SourceStyle::HLSL:
- case SourceStyle::C:
- case SourceStyle::CPP:
+ case SourceLanguage::CUDA:
+ case SourceLanguage::HLSL:
+ case SourceLanguage::C:
+ case SourceLanguage::CPP:
m_writer->emit("static ");
break;
@@ -1652,7 +1652,7 @@ void CLikeSourceEmitter::emitIntrinsicCallExprImpl(
for(IRIntegerValue ii = elementCount; ii < 4; ++ii)
{
m_writer->emit(", ");
- if(getSourceStyle() == SourceStyle::GLSL)
+ if(getSourceLanguage() == SourceLanguage::GLSL)
{
emitSimpleType(elementType);
m_writer->emit("(0)");
@@ -1710,7 +1710,7 @@ void CLikeSourceEmitter::emitIntrinsicCallExprImpl(
auto arg = args[argIndex].get();
if(arg->op == kIROp_ImageSubscript)
{
- if(getSourceStyle() == SourceStyle::GLSL)
+ if(getSourceLanguage() == SourceLanguage::GLSL)
{
// TODO: we don't handle the multisample
// case correctly here, where the last
@@ -2003,7 +2003,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
auto base = fieldExtract->getBase();
emitOperand(base, leftSide(outerPrec, prec));
m_writer->emit(".");
- if(getSourceStyle() == SourceStyle::GLSL
+ if(getSourceLanguage() == SourceLanguage::GLSL
&& as<IRUniformParameterGroupType>(base->getDataType()))
{
m_writer->emit("_data.");
@@ -2023,7 +2023,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
auto base = ii->getBase();
emitOperand(base, leftSide(outerPrec, prec));
m_writer->emit(".");
- if(getSourceStyle() == SourceStyle::GLSL
+ if(getSourceLanguage() == SourceLanguage::GLSL
&& as<IRUniformParameterGroupType>(base->getDataType()))
{
m_writer->emit("_data.");
@@ -2120,7 +2120,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
{
auto base = inst->getOperand(0);
emitOperand(base, outerPrec);
- if(getSourceStyle() == SourceStyle::GLSL
+ if(getSourceLanguage() == SourceLanguage::GLSL
&& as<IRUniformParameterGroupType>(base->getDataType()))
{
m_writer->emit("._data");
@@ -3240,7 +3240,7 @@ void CLikeSourceEmitter::emitStruct(IRStructType* structType)
continue;
// Note: GLSL doesn't support interpolation modifiers on `struct` fields
- if( getSourceStyle() != SourceStyle::GLSL )
+ if( getSourceLanguage() != SourceLanguage::GLSL )
{
emitInterpolationModifiers(fieldKey, fieldType, nullptr);
}
@@ -3455,9 +3455,9 @@ void CLikeSourceEmitter::emitGlobalVar(IRGlobalVar* varDecl)
// shader parameter) may need special
// modifiers to indicate it as such.
//
- switch (getSourceStyle())
+ switch (getSourceLanguage())
{
- case SourceStyle::HLSL:
+ case SourceLanguage::HLSL:
// HLSL requires the `static` modifier on any
// global variables; otherwise they are assumed
// to be uniforms.
diff --git a/source/slang/slang-emit-c-like.h b/source/slang/slang-emit-c-like.h
index bead26db3..453a8dbbf 100644
--- a/source/slang/slang-emit-c-like.h
+++ b/source/slang/slang-emit-c-like.h
@@ -38,18 +38,6 @@ public:
kThreadGroupAxisCount = 3,
};
- /// To simplify cases
- enum class SourceStyle
- {
- Unknown,
- GLSL,
- HLSL,
- C,
- CPP,
- CUDA,
- CountOf,
- };
-
typedef unsigned int ESemanticMask;
enum
{
@@ -113,7 +101,7 @@ public:
/// Get the code gen target
CodeGenTarget getTarget() { return m_target; }
/// Get the source style
- SLANG_FORCE_INLINE SourceStyle getSourceStyle() const { return m_sourceStyle; }
+ SLANG_FORCE_INLINE SourceLanguage getSourceLanguage() const { return m_sourceLanguage; }
void noteInternalErrorLoc(SourceLoc loc) { return getSink()->noteInternalErrorLoc(loc); }
@@ -298,8 +286,9 @@ public:
virtual RefObject* getExtensionTracker() { return nullptr; }
- /// Gets a source style for a target. Returns Unknown if not a known target
- static SourceStyle getSourceStyle(CodeGenTarget target);
+ /// Gets a source language for a target for a target. Returns Unknown if not a known target
+ static SourceLanguage getSourceLanguage(CodeGenTarget target);
+
/// Gets the default type name for built in scalar types. Different impls may require something different.
/// Returns an empty slice if not a built in type
static UnownedStringSlice getDefaultBuiltinTypeName(IROp op);
@@ -372,8 +361,8 @@ public:
// The target language we want to generate code for
CodeGenTarget m_target;
- // Source style - a simplification of the more nuanced m_target
- SourceStyle m_sourceStyle;
+ // Source language (based on the more nuanced m_target)
+ SourceLanguage m_sourceLanguage;
// Where source is written to
SourceWriter* m_writer;
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index 0154f9741..d09c778b9 100644
--- a/source/slang/slang-emit-glsl.cpp
+++ b/source/slang/slang-emit-glsl.cpp
@@ -49,7 +49,7 @@ void GLSLSourceEmitter::_requireGLSLExtension(const UnownedStringSlice& name)
void GLSLSourceEmitter::_requireGLSLVersion(ProfileVersion version)
{
- if (getSourceStyle() != SourceStyle::GLSL)
+ if (getSourceLanguage() != SourceLanguage::GLSL)
return;
m_glslExtensionTracker->requireVersion(version);
@@ -553,12 +553,12 @@ void GLSLSourceEmitter::_emitGLSLLayoutQualifiers(IRVarLayout* layout, EmitVarCh
{
if (!layout) return;
- switch (getSourceStyle())
+ switch (getSourceLanguage())
{
default:
return;
- case SourceStyle::GLSL:
+ case SourceLanguage::GLSL:
break;
}
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index f33697045..440b9bc68 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -135,12 +135,12 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, char con
auto layout = chain->varLayout;
- switch (getSourceStyle())
+ switch (getSourceLanguage())
{
default:
return;
- case SourceStyle::HLSL:
+ case SourceLanguage::HLSL:
break;
}
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 1afca6127..f2552f95d 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -308,7 +308,7 @@ Result linkAndOptimizeIR(
// We don't need the legalize pass for C/C++ based types
if(options.shouldLegalizeExistentialAndResourceTypes )
-// if (!(sourceStyle == SourceStyle::CPP || sourceStyle == SourceStyle::C))
+// if (!(sourceLanguage == SourceLanguage::CPP || sourceStyle == SourceLanguage::C))
{
// The Slang language allows interfaces to be used like
// ordinary types (including placing them in constant
@@ -646,27 +646,25 @@ SlangResult emitEntryPointSourceFromIR(
RefPtr<CLikeSourceEmitter> sourceEmitter;
- typedef CLikeSourceEmitter::SourceStyle SourceStyle;
-
- SourceStyle sourceStyle = CLikeSourceEmitter::getSourceStyle(target);
- switch (sourceStyle)
+ SourceLanguage sourceLanguage = CLikeSourceEmitter::getSourceLanguage(target);
+ switch (sourceLanguage)
{
- case SourceStyle::CPP:
+ case SourceLanguage::CPP:
{
sourceEmitter = new CPPSourceEmitter(desc);
break;
}
- case SourceStyle::GLSL:
+ case SourceLanguage::GLSL:
{
sourceEmitter = new GLSLSourceEmitter(desc);
break;
}
- case SourceStyle::HLSL:
+ case SourceLanguage::HLSL:
{
sourceEmitter = new HLSLSourceEmitter(desc);
break;
}
- case SourceStyle::CUDA:
+ case SourceLanguage::CUDA:
{
sourceEmitter = new CUDASourceEmitter(desc);
break;
@@ -687,14 +685,14 @@ SlangResult emitEntryPointSourceFromIR(
linkingAndOptimizationOptions.sourceEmitter = sourceEmitter;
- switch( sourceStyle )
+ switch( sourceLanguage )
{
default:
break;
- case SourceStyle::CPP:
- case SourceStyle::C:
- case SourceStyle::CUDA:
+ case SourceLanguage::CPP:
+ case SourceLanguage::C:
+ case SourceLanguage::CUDA:
linkingAndOptimizationOptions.shouldLegalizeExistentialAndResourceTypes = false;
break;
}
@@ -728,43 +726,8 @@ SlangResult emitEntryPointSourceFromIR(
// it is time to stitch together the final output.
{
- Session* session = compileRequest->getSession();
-
- // Get the downstream compiler needed for final target
- PassThroughMode passThru = getDownstreamCompilerRequiredForTarget(session, targetRequest->target);
-
- // 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)
- {
- // 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)
- {
- 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);
- }
- }
- }
-
// If there is a prelude emit it
- const auto& prelude = compileRequest->getSession()->getDownstreamCompilerPrelude(passThru);
+ const auto& prelude = compileRequest->getSession()->getPreludeForLanguage(sourceLanguage);
if (prelude.getLength() > 0)
{
sourceWriter.emit(prelude.getUnownedSlice());
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 02c9e25e3..5279b2a40 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -254,20 +254,51 @@ SLANG_NO_THROW void SLANG_MCALL Session::setDownstreamCompilerPrelude(
SlangPassThrough inPassThrough,
char const* prelude)
{
- PassThroughMode passThrough = PassThroughMode(inPassThrough);
- SLANG_ASSERT(int(passThrough) > int(PassThroughMode::None) && int(passThrough) < int(PassThroughMode::CountOf));
-
- m_downstreamCompilerPreludes[int(passThrough)] = prelude;
+ PassThroughMode downstreamCompiler = PassThroughMode(inPassThrough);
+ SLANG_ASSERT(int(downstreamCompiler) > int(PassThroughMode::None) && int(downstreamCompiler) < int(PassThroughMode::CountOf));
+ const SourceLanguage sourceLanguage = getDefaultSourceLanguageForDownstreamCompiler(downstreamCompiler);
+ setLanguagePrelude(SlangSourceLanguage(sourceLanguage), prelude);
}
SLANG_NO_THROW void SLANG_MCALL Session::getDownstreamCompilerPrelude(
SlangPassThrough inPassThrough,
ISlangBlob** outPrelude)
{
- PassThroughMode passThrough = PassThroughMode(inPassThrough);
- SLANG_ASSERT(int(passThrough) > int(PassThroughMode::None) && int(passThrough) < int(PassThroughMode::CountOf));
+ PassThroughMode downstreamCompiler = PassThroughMode(inPassThrough);
+ SLANG_ASSERT(int(downstreamCompiler) > int(PassThroughMode::None) && int(downstreamCompiler) < int(PassThroughMode::CountOf));
+ const SourceLanguage sourceLanguage = getDefaultSourceLanguageForDownstreamCompiler(downstreamCompiler);
+ getLanguagePrelude(SlangSourceLanguage(sourceLanguage), outPrelude);
+}
+
+SLANG_NO_THROW void SLANG_MCALL Session::setLanguagePrelude(
+ SlangSourceLanguage inSourceLanguage,
+ char const* prelude)
+{
+ SourceLanguage sourceLanguage = SourceLanguage(inSourceLanguage);
+ SLANG_ASSERT(int(sourceLanguage) > int(SourceLanguage::Unknown) && int(sourceLanguage) < int(SourceLanguage::CountOf));
+
+ SLANG_ASSERT(sourceLanguage != SourceLanguage::Unknown);
- *outPrelude = Slang::StringUtil::createStringBlob(m_downstreamCompilerPreludes[int(passThrough)]).detach();
+ if (sourceLanguage != SourceLanguage::Unknown)
+ {
+ m_languagePreludes[int(sourceLanguage)] = prelude;
+ }
+}
+
+SLANG_NO_THROW void SLANG_MCALL Session::getLanguagePrelude(
+ SlangSourceLanguage inSourceLanguage,
+ ISlangBlob** outPrelude)
+{
+ SourceLanguage sourceLanguage = SourceLanguage(inSourceLanguage);
+ SLANG_ASSERT(int(sourceLanguage) > int(SourceLanguage::Unknown) && int(sourceLanguage) < int(SourceLanguage::CountOf));
+
+ SLANG_ASSERT(sourceLanguage != SourceLanguage::Unknown);
+
+ *outPrelude = nullptr;
+ if (sourceLanguage != SourceLanguage::Unknown)
+ {
+ *outPrelude = Slang::StringUtil::createStringBlob(m_languagePreludes[int(sourceLanguage)]).detach();
+ }
}
SLANG_NO_THROW const char* SLANG_MCALL Session::getBuildTagString()