yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d4136c934
master
1#include "slang-signal.h" 2 3#include "slang-exception.h" 4#include "stdio.h" 5 6namespace Slang 7{ 8 9thread_localString g_lastSignalMessage ; 10 11static const char * _getSignalTypeAsText (SignalType type ) 12{ 13switch (type ) 14 { 15case SignalType ::AssertFailure : 16return "assert failure" ; 17case SignalType ::Unimplemented : 18return "unimplemented" ; 19case SignalType ::Unreachable : 20return "hit unreachable code" ; 21case SignalType ::Unexpected : 22return "unexpected" ; 23case SignalType ::InvalidOperation : 24return "invalid operation" ; 25case SignalType ::AbortCompilation : 26return "abort compilation" ; 27default : 28return "unhandled" ; 29 } 30} 31 32String _getMessage (SignalType type ,char const * message ) 33{ 34StringBuilder buf ; 35const char * const typeText = _getSignalTypeAsText (type ); 36buf <<typeText ; 37if (message ) 38 { 39buf <<": " <<message ; 40 } 41 42return buf .produceString (); 43} 44 45// One point of having as a single function is a choke point both for handling (allowing different 46// handling scenarios) as well as a choke point to set a breakpoint to catch 'signal' types 47[[noreturn ]]void handleSignal (SignalType type ,char const * message ) 48{ 49StringBuilder buf ; 50const char * const typeText = _getSignalTypeAsText (type ); 51buf <<typeText <<": " <<message ; 52 53// Can be useful to enable during debug when problem is on CI 54if (false) 55 { 56printf ("%s\n" ,_getMessage (type ,message ).getBuffer ()); 57 } 58 59g_lastSignalMessage = _getMessage (type ,message ); 60 61#if SLANG_HAS_EXCEPTIONS 62switch (type ) 63 { 64case SignalType ::InvalidOperation : 65throw InvalidOperationException (_getMessage (type ,message )); 66case SignalType ::AbortCompilation : 67throw AbortCompilationException (_getMessage (type ,message )); 68default : 69throw InternalError (_getMessage (type ,message )); 70 } 71#else 72// Attempt to drop out into the debugger. If a debugger isn't attached this will likely crash - 73// which is probably the best we can do. 74 75SLANG_BREAKPOINT (0 ); 76 77// 'panic'. Exit with an error code as we can't throw or catch. 78exit (-1 ); 79#endif 80} 81 82const char * getLastSignalMessage () 83{ 84return g_lastSignalMessage .getBuffer (); 85} 86 87}// namespace Slang