diff options
| author | Yong He <yonghe@outlook.com> | 2023-09-21 14:00:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-21 14:00:48 -0700 |
| commit | 5b2eb06816521cc0fcfe03258452560bd200002d (patch) | |
| tree | dc06cc626ff0059dded3f4245f9309b3071ae94c /source/slang/slang-emit-c-like.cpp | |
| parent | af8ce68e9fd7b6255b6e4e9e9524a285497116dc (diff) | |
Various slangpy fixes. (#3227)
* Make dynamic cast transparent through `IRAttributedType`.
* Add [CUDAXxx] variant of attributes.
* Support marshaling of vector types.
* Wrap cuda kernels in `extern "C"` block.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index a74459954..d26893987 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -3321,6 +3321,20 @@ bool CLikeSourceEmitter::isTargetIntrinsic(IRInst* inst) return findTargetIntrinsicDefinition(inst, intrinsicDef); } +bool shouldWrappInExternCBlock(IRFunc* func) +{ + for (auto decor : func->getDecorations()) + { + switch (decor->getOp()) + { + case kIROp_ExternCDecoration: + case kIROp_CudaKernelDecoration: + return true; + } + } + return false; +} + void CLikeSourceEmitter::emitFunc(IRFunc* func) { // Target-intrinsic functions should never be emitted @@ -3329,6 +3343,15 @@ void CLikeSourceEmitter::emitFunc(IRFunc* func) if (isTargetIntrinsic(func)) return; + bool shouldCloseExternCBlock = shouldWrappInExternCBlock(func); + if (shouldCloseExternCBlock) + { + // If this is a C++ `extern "C"` function, then we need to emit + // it as a C function, since that is what the C++ compiler will + // expect. + // + m_writer->emit("extern \"C\" {\n"); + } if(!isDefinition(func)) { @@ -3345,6 +3368,10 @@ void CLikeSourceEmitter::emitFunc(IRFunc* func) // emitSimpleFunc(func); } + if (shouldCloseExternCBlock) + { + m_writer->emit("}\n"); + } } void CLikeSourceEmitter::emitFuncDecorationsImpl(IRFunc* func) |
