From 8ccd495d5eaa82cb831378c28dd190e657b6c999 Mon Sep 17 00:00:00 2001 From: Theresa Foley <10618364+tangent-vector@users.noreply.github.com> Date: Thu, 24 Jul 2025 12:59:58 -0700 Subject: Organize code better by splitting some big files (#7890) * Organize code better by splitting some big files The basic change here is that the majority of the declarations in `slang-compiler.h` have been split out into a set of smaller and more focused files. As a result, the implement of those declarations have been moved from `slang-compiler.cpp` and `slang.cpp` over to those new files when the proper home for code is obvious. I have tried as much as possible to *not* make any edits to the code along the way, and just copy-paste declarations from one place to another as-is. The exceptions I am aware of are: * In some cases a function that used to be file-scope `static` was used by code that landed in two or more different `.cpp` files. In these cases, I changed the function to be non-`static` (removing the `_` prefix from its name, if it had one, per our naming conventions), and put a declaration for the function into the most appropriate header I could identify. * I added a few comments in places where I saw ugly or unfortunate things in the code I was moving, and wanted to tag them with `TODO`s so we can hopefully get to them in the fullness of time. * I added top-level comments to each of the new `.h` files that was introduced to try to explain the logic for what goes into that file. * In cases where one of the new header files mostly existed to declare a single type, I sometimes added more detail to the doc comment on that type, to better explain the type and its role in the compiler (this is text that otherwise might have gone into the comment at the top leve lof the file, but I figured that the doc comment would have higher discoverability). I expect that the most contentious choice here is that the `Session` class lands in `slang-global-session.h` while `slang-session.h` holds the `Linkage` class. The names used in this change are consistent with how the relevant concepts in the public Slang API are named, and are consistent with how we *intend* to rename the classes themselves in time. * format code * fixup --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/compiler-core/slang-diagnostic-sink.cpp | 41 ++++++++++++++++++++++++++ source/compiler-core/slang-diagnostic-sink.h | 13 ++++++++ 2 files changed, 54 insertions(+) (limited to 'source/compiler-core') diff --git a/source/compiler-core/slang-diagnostic-sink.cpp b/source/compiler-core/slang-diagnostic-sink.cpp index 28a98266a..de8bdf52c 100644 --- a/source/compiler-core/slang-diagnostic-sink.cpp +++ b/source/compiler-core/slang-diagnostic-sink.cpp @@ -828,4 +828,45 @@ DiagnosticsLookup::DiagnosticsLookup( add(diagnostics, diagnosticsCount); } +void outputExceptionDiagnostic( + const AbortCompilationException& exception, + DiagnosticSink& sink, + slang::IBlob** outDiagnostics) +{ + sink.diagnoseRaw(Severity::Error, exception.Message.getUnownedSlice()); + sink.getBlobIfNeeded(outDiagnostics); +} + +void outputExceptionDiagnostic( + const Exception& exception, + DiagnosticSink& sink, + slang::IBlob** outDiagnostics) +{ + try + { + sink.diagnoseRaw(Severity::Internal, exception.Message.getUnownedSlice()); + } + catch (const AbortCompilationException&) + { + // Catch and ignore the AbortCompilationException that diagnoseRaw throws + // for Internal severity to prevent exception leak from loadModule + } + sink.getBlobIfNeeded(outDiagnostics); +} + +void outputExceptionDiagnostic(DiagnosticSink& sink, slang::IBlob** outDiagnostics) +{ + try + { + sink.diagnoseRaw(Severity::Fatal, "An unknown exception occurred"); + } + catch (const AbortCompilationException&) + { + // Catch and ignore the AbortCompilationException that diagnoseRaw throws + // for Fatal severity to prevent exception leak from loadModule + } + sink.getBlobIfNeeded(outDiagnostics); +} + + } // namespace Slang diff --git a/source/compiler-core/slang-diagnostic-sink.h b/source/compiler-core/slang-diagnostic-sink.h index 2d60747d9..fe05d953b 100644 --- a/source/compiler-core/slang-diagnostic-sink.h +++ b/source/compiler-core/slang-diagnostic-sink.h @@ -393,6 +393,19 @@ protected: MemoryArena m_arena; }; + +void outputExceptionDiagnostic( + const AbortCompilationException& exception, + DiagnosticSink& sink, + slang::IBlob** outDiagnostics); + +void outputExceptionDiagnostic( + const Exception& exception, + DiagnosticSink& sink, + slang::IBlob** outDiagnostics); + +void outputExceptionDiagnostic(DiagnosticSink& sink, slang::IBlob** outDiagnostics); + } // namespace Slang #endif -- cgit v1.2.3