From 05c4c2679ae979cfcb61e4c2acdb432c34384ddb Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 17 May 2022 17:27:12 -0400 Subject: Refactor prelude emit (#2236) * #include an absolute path didn't work - because paths were taken to always be relative. * Refactor how prelude output works in emit. * Small improvement to emit output. * Move around comment on target specific language directives based on review. Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com> --- source/slang/slang-emit-cpp.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-emit-cpp.cpp') diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index 81d32c297..9887f1ba6 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -2459,15 +2459,13 @@ static Index _calcTypeOrder(IRType* a) } } -void CPPSourceEmitter::emitPreprocessorDirectivesImpl() +void CPPSourceEmitter::emitPreModuleImpl() { - SourceWriter* writer = getSourceWriter(); - - writer->emit("\n"); - - if (m_target == CodeGenTarget::CPPSource) { + // NOTE, that this opens an anonymous scope. + // The scope is closed in `emitModuleImpl` + // When generating kernel code in C++, put all into an anonymous namespace // This includes any generated types, and generated intrinsics. m_writer->emit("namespace { // anonymous \n\n"); @@ -2476,6 +2474,8 @@ void CPPSourceEmitter::emitPreprocessorDirectivesImpl() m_writer->emit("#endif\n\n"); } + // Emit generated functions and types + if (m_target == CodeGenTarget::CSource) { // For C output we need to emit type definitions. @@ -2507,7 +2507,7 @@ void CPPSourceEmitter::emitPreprocessorDirectivesImpl() m_intrinsicSet.getIntrinsics(intrinsics); // Emit all the intrinsics that were used - for (auto intrinsic: intrinsics) + for (auto intrinsic : intrinsics) { _maybeEmitSpecializedOperationDefinition(intrinsic); } @@ -2757,7 +2757,6 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module, DiagnosticSink* sink) _emitForwardDeclarations(actions); - { // Output all the thread locals for (auto action : actions) -- cgit v1.2.3