bh_assert.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _BH_ASSERT_H
  6. #define _BH_ASSERT_H
  7. #include "bh_config.h"
  8. #include "bh_platform.h"
  9. #ifdef BH_TEST
  10. # ifndef BH_DEBUG
  11. # error "BH_TEST should be defined under BH_DEBUG"
  12. # endif
  13. #endif
  14. #ifdef BH_TEST
  15. # if defined(WIN32) || defined(__linux__)
  16. # else
  17. # error "Test case can not run on the current platform"
  18. # endif
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #ifdef BH_DEBUG
  24. void bh_assert_internal(int v, const char *file_name, int line_number,
  25. const char *expr_string);
  26. #define bh_assert(expr) bh_assert_internal((int)(expr), __FILE__, __LINE__, #expr)
  27. void bh_debug_internal(const char *file_name, int line_number,
  28. const char *fmt, ...);
  29. #if defined(WIN32)
  30. #define bh_debug(fmt, ...) bh_debug_internal(__FILE__, __LINE__, fmt, __VA_ARGS__)
  31. #elif defined(__linux__)
  32. #define bh_debug bh_debug_internal(__FILE__, __LINE__, "");printf
  33. #else
  34. #error "Unsupported platform"
  35. #endif
  36. #else /* else of BH_DEBUG */
  37. #define bh_debug if(0)printf
  38. #endif /* end of BH_DEBUG */
  39. #ifdef BH_TEST
  40. #define BH_STATIC
  41. #else
  42. #define BH_STATIC static
  43. #endif /* end of BH_TEST */
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif