bh_assert.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _BH_ASSERT_H
  17. #define _BH_ASSERT_H
  18. #include "bh_config.h"
  19. #include "bh_platform.h"
  20. #ifdef BH_TEST
  21. # ifndef BH_DEBUG
  22. # error "BH_TEST should be defined under BH_DEBUG"
  23. # endif
  24. #endif
  25. #ifdef BH_TEST
  26. # if defined(WIN32) || defined(__linux__)
  27. # else
  28. # error "Test case can not run on the current platform"
  29. # endif
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #ifdef BH_DEBUG
  35. extern void bh_assert_internal(int v, const char *file_name, int line_number, const char *expr_string);
  36. #define bh_assert(expr) bh_assert_internal((int)(expr), __FILE__, __LINE__, # expr)
  37. extern void bh_debug_internal(const char *file_name, int line_number, const char *fmt, ...);
  38. #if defined(WIN32) || defined(EMU)
  39. # define bh_debug(fmt, ...) bh_debug_internal(__FILE__, __LINE__, fmt, __VA_ARGS__)
  40. #elif defined(__linux__)
  41. /*# define bh_debug(...) bh_debug_internal(__FILE__, __LINE__, ## __VA_ARGS__)*/
  42. # define bh_debug bh_debug_internal(__FILE__, __LINE__, "");printf
  43. #elif defined(PLATFORM_SEC)
  44. # define bh_debug(fmt, ...) bh_debug_internal(__FILE__, __LINE__, fmt, __VA_ARGS__)
  45. #else
  46. # error "Unsupported platform"
  47. #endif
  48. #else
  49. #define bh_debug if(0)printf
  50. #endif
  51. #define bh_assert_abort(x) do { \
  52. if (!x) \
  53. abort(); \
  54. } while (0)
  55. #ifdef BH_TEST
  56. # define BH_STATIC
  57. #else
  58. # define BH_STATIC static
  59. #endif
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif
  64. /* Local Variables: */
  65. /* mode:c */
  66. /* c-basic-offset: 4 */
  67. /* indent-tabs-mode: nil */
  68. /* End: */