From 5eb835f0332868fd56ac14ce7560e0ae9cfafec9 Mon Sep 17 00:00:00 2001 From: David Siher <32305650+dsiher@users.noreply.github.com> Date: Thu, 3 Feb 2022 19:16:54 -0800 Subject: 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 --- source/slang/slang-emit-c-like.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source/slang/slang-emit-c-like.cpp') 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()) + { + // 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()) + { + return nameHintDecoration->getName(); + } + // Otherwise, we just want the instruction to not be mangled, which is + // similarly handled in `getMangledName`. + if (auto linkageDecoration = inst->findDecoration()) + { + 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()) + { + return; + } + m_writer->emit("struct "); emitPostKeywordTypeAttributes(structType); -- cgit v1.2.3