int_util.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //===-- int_util.h - internal utility functions ---------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is not part of the interface of this library.
  10. //
  11. // This file defines non-inline utilities which are available for use in the
  12. // library. The function definitions themselves are all contained in int_util.c
  13. // which will always be compiled into any compiler-rt library.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef INT_UTIL_H
  17. #define INT_UTIL_H
  18. /// \brief Trigger a program abort (or panic for kernel code).
  19. #define compilerrt_abort() __compilerrt_abort_impl(__FILE__, __LINE__, __func__)
  20. NORETURN void __compilerrt_abort_impl(const char *file, int line,
  21. const char *function);
  22. #define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__)
  23. #define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt)
  24. #define COMPILE_TIME_ASSERT2(expr, cnt) \
  25. typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED
  26. // Force unrolling the code specified to be repeated N times.
  27. #define REPEAT_0_TIMES(code_to_repeat) /* do nothing */
  28. #define REPEAT_1_TIMES(code_to_repeat) code_to_repeat
  29. #define REPEAT_2_TIMES(code_to_repeat) \
  30. REPEAT_1_TIMES(code_to_repeat) \
  31. code_to_repeat
  32. #define REPEAT_3_TIMES(code_to_repeat) \
  33. REPEAT_2_TIMES(code_to_repeat) \
  34. code_to_repeat
  35. #define REPEAT_4_TIMES(code_to_repeat) \
  36. REPEAT_3_TIMES(code_to_repeat) \
  37. code_to_repeat
  38. #define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat)
  39. #define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat)
  40. #endif // INT_UTIL_H