From 255fd5873f65a6b01d5385c277d55612dc3cc587 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 28 Mar 2022 22:14:33 -0700 Subject: Allow slangc to generate exe from .slang file. (#2170) --- source/slang/slang-emit-c-like.cpp | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (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 d3dd0e5b8..eb178a366 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -78,6 +78,7 @@ struct CLikeSourceEmitter::ComputeEmitActionsContext return SourceLanguage::C; } case CodeGenTarget::CPPSource: + case CodeGenTarget::HostCPPSource: { return SourceLanguage::CPP; } @@ -741,28 +742,6 @@ 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. @@ -802,6 +781,13 @@ String CLikeSourceEmitter::generateName(IRInst* inst) return generateEntryPointNameImpl(entryPointDecor); } + // If the instruction has a linkage decoration, just use that. + if (auto externCppDecoration = inst->findDecoration()) + { + // Just use the linkages mangled name directly. + return externCppDecoration->getName(); + } + // If we have a name hint on the instruction, then we will try to use that // to provide the basis for the actual name in the output code. if(auto nameHintDecoration = inst->findDecoration()) @@ -2915,13 +2901,6 @@ 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