gencpp/project/dependencies/debug.hpp
Ed_ 050b00f28a WIP - Broken Compile : Added pragma once and includes to all files + Parser fixes, and String improvements
Adding the pragma once and includes the files broke compilation, still diagnosing why.

- Some string functions were moved to the cpp, still need to do some more evaluation of it and the containers...
- Added support for forceinline and neverinline to parsing (untested)
- Added support for specifiers in operator cast such as explicit, inline/forceinline/neverinline, etc.
    - Before it only support const.
    - Still need to support volatile.
- Forceinline was not supported at all for tokenization, fixed that.
2023-08-21 20:30:13 -04:00

62 lines
2.3 KiB
C++

#pragma once
#include "basic_types.hpp"
#pragma region Debug
#if defined( _MSC_VER )
# if _MSC_VER < 1300
# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */
# else
# define GEN_DEBUG_TRAP() __debugbreak()
# endif
#elif defined( GEN_COMPILER_TINYC )
# define GEN_DEBUG_TRAP() process_exit( 1 )
#else
# define GEN_DEBUG_TRAP() __builtin_trap()
#endif
#define GEN_ASSERT( cond ) GEN_ASSERT_MSG( cond, NULL )
#define GEN_ASSERT_MSG( cond, msg, ... ) \
do \
{ \
if ( ! ( cond ) ) \
{ \
assert_handler( #cond, __FILE__, zpl_cast( s64 ) __LINE__, msg, ##__VA_ARGS__ ); \
GEN_DEBUG_TRAP(); \
} \
} while ( 0 )
#define GEN_ASSERT_NOT_NULL( ptr ) GEN_ASSERT_MSG( ( ptr ) != NULL, #ptr " must not be NULL" )
// NOTE: Things that shouldn't happen with a message!
#define GEN_PANIC( msg, ... ) GEN_ASSERT_MSG( 0, msg, ##__VA_ARGS__ )
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... );
s32 assert_crash( char const* condition );
void process_exit( u32 code );
#if Build_Debug
#define GEN_FATAL( ... ) \
do \
{ \
local_persist thread_local \
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
\
str_fmt(buf, GEN_PRINTF_MAXLEN, __VA_ARGS__); \
GEN_PANIC(buf); \
} \
while (0)
#else
# define GEN_FATAL( ... ) \
do \
{ \
str_fmt_out_err( __VA_ARGS__ ); \
process_exit(1); \
} \
while (0)
#endif
#pragma endregion Debug