summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-cpp.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-04-11 18:14:49 -0700
committerGitHub <noreply@github.com>2023-04-11 18:14:49 -0700
commit195af97638e59539cd9c14d16338789b6d683f3f (patch)
tree461ad6c2fea44dcb77dc034e4d368e69ead8a6aa /source/slang/slang-emit-cpp.cpp
parent7c3a40cf08091a6cf0ec2de1e9694c979fb5c551 (diff)
Fix missing `f` suffix for float lits in CUDA backend. (#2791)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-cpp.cpp')
-rw-r--r--source/slang/slang-emit-cpp.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index d6764ae06..89d1328bc 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -846,6 +846,30 @@ void CPPSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoint
m_writer->emit("SLANG_PRELUDE_EXPORT\n");
}
+bool isPublicOrExportedFunc(IRFunc* func)
+{
+ for (auto decor : func->getDecorations())
+ {
+ switch (decor->getOp())
+ {
+ case kIROp_PublicDecoration:
+ case kIROp_EntryPointDecoration:
+ case kIROp_HLSLExportDecoration:
+ case kIROp_DllExportDecoration:
+ case kIROp_DllImportDecoration:
+ case kIROp_CudaDeviceExportDecoration:
+ case kIROp_CudaHostDecoration:
+ case kIROp_CudaKernelDecoration:
+ {
+ return true;
+ }
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
void CPPSourceEmitter::emitSimpleFuncImpl(IRFunc* func)
{
// Emit function decorations
@@ -858,6 +882,11 @@ void CPPSourceEmitter::emitSimpleFuncImpl(IRFunc* func)
// Deal with decorations that need
// to be emitted as attributes
+ // If `func` is not public or exported, emit `static` to prevent linking clash.
+ if (!isPublicOrExportedFunc(func))
+ {
+ m_writer->emit("static ");
+ }
// We start by emitting the result type and function name.
//
if (IREntryPointDecoration* entryPointDecor = func->findDecoration<IREntryPointDecoration>())
@@ -990,7 +1019,16 @@ void CPPSourceEmitter::_emitType(IRType* type, DeclaratorInfo* declarator)
default:
CLikeSourceEmitter::_emitType(type, declarator);
break;
-
+ case kIROp_VectorType:
+ case kIROp_MatrixType:
+ {
+ StringBuilder sb;
+ calcTypeName(type, m_target, sb);
+ m_writer->emit(sb.ProduceString());
+ m_writer->emit(" ");
+ emitDeclarator(declarator);
+ break;
+ }
case kIROp_PtrType:
case kIROp_InOutType:
case kIROp_OutType: