#pragma once
#include <executorch/runtime/platform/abort.h>
#include <executorch/runtime/platform/compiler.h>
#include <executorch/runtime/platform/log.h>
#define ET_ASSERT_MESSAGE_EMIT(_format, ...) \
ET_LOG( \
Fatal, \
"In function %s(), assert failed" _format, \
ET_FUNCTION, \
##__VA_ARGS__)
#define ET_CHECK_MSG(_cond, _format, ...) \
do { \
if ET_UNLIKELY (!(_cond)) { \
ET_ASSERT_MESSAGE_EMIT(" (%s): " _format, #_cond, ##__VA_ARGS__); \
::executorch::runtime::runtime_abort(); \
} \
} while (0)
#define ET_CHECK(_cond) \
do { \
if ET_UNLIKELY (!(_cond)) { \
ET_ASSERT_MESSAGE_EMIT(": %s", #_cond); \
::executorch::runtime::runtime_abort(); \
} \
} while (0)
#ifdef NDEBUG
#define ET_DCHECK_MSG(_cond, _format, ...) ((void)0)
#define ET_DCHECK(_cond) ((void)0)
#define ET_DEBUG_ONLY [[maybe_unused]]
#else
#define ET_DCHECK_MSG(_cond, _format, ...) \
ET_CHECK_MSG(_cond, _format, ##__VA_ARGS__)
#define ET_DCHECK(_cond) ET_CHECK(_cond)
#define ET_DEBUG_ONLY
#endif
#define ET_ASSERT_UNREACHABLE() \
do { \
ET_CHECK_MSG(false, "Execution should not reach this point"); \
ET_UNREACHABLE(); \
} while (0)
#define ET_ASSERT_UNREACHABLE_MSG(_format, ...) \
do { \
ET_CHECK_MSG( \
false, \
"Execution should not reach this point. " _format, \
##__VA_ARGS__); \
ET_UNREACHABLE(); \
} while (0)