diff options
| author | David Siher <32305650+dsiher@users.noreply.github.com> | 2022-02-03 19:16:54 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-03 19:16:54 -0800 |
| commit | 5eb835f0332868fd56ac14ce7560e0ae9cfafec9 (patch) | |
| tree | 67ed2ae3b2527e8cfa66f835062490decf3052ad /source/slang/slang-emit-c-like.cpp | |
| parent | 1eda86377847155ed3f0e0b2e40a105af35bd387 (diff) | |
Fixed naming conflicts in heterogeneous-hello-world (#2114)
* Fixed naming conflicts in heterogeneous-hello-world
Added 3 new modifiers (`__unmangled`, `__exportDirectly`, `__externLib`)
`__unmangled` causes mangleName() to return the normal name of the decl.
`__exportDirectly` changes parent decl name concatenation behavior to use
"::" instead of "." (for Name Hint) and emits the name hint when it exists,
otherwise it emits the mangled name.
`__externLib` stops Slang from emitting the corresponding struct.
Also made necessary changes to heterogeneous-hello-world so that this new
functionality is shown off.
* Undo unintentional formatting changes
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index e04759773..c0106e9ad 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -740,6 +740,28 @@ String CLikeSourceEmitter::_generateUniqueName(const UnownedStringSlice& name) String CLikeSourceEmitter::generateName(IRInst* inst) { + // Handle `__exportDirectly` decoration before all else + if (inst->findDecoration<IR__exportDirectly>()) + { + // If instruction has a NameHint, we naively emit it as a namespace + // This is automatically handled in `getNameforNameHint` when the + // `__exportDirectly` decoration is found, so we can just return it. + // TODO: This is a very hacky solution. + // + // Another option would be to have two separate decorations, one that + // handles this namespace, and a separate decoration for unmangled names. + if (auto nameHintDecoration = inst->findDecoration<IRNameHintDecoration>()) + { + return nameHintDecoration->getName(); + } + // Otherwise, we just want the instruction to not be mangled, which is + // similarly handled in `getMangledName`. + if (auto linkageDecoration = inst->findDecoration<IRLinkageDecoration>()) + { + return linkageDecoration->getMangledName(); + } + } + // If the instruction names something // that should be emitted as a target intrinsic, // then use that name instead. @@ -2901,6 +2923,13 @@ void CLikeSourceEmitter::emitStruct(IRStructType* structType) return; } + // If the selected `struct` type is externally defined + // then we also don't want to emit anything. + if (auto externLibDecoration = structType->findDecoration<IR__externLib>()) + { + return; + } + m_writer->emit("struct "); emitPostKeywordTypeAttributes(structType); |
