CBindingWrapping.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===- llvm/Support/CBindingWrapping.h - C Interface Wrapping ---*- C++ -*-===//
  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 declares the wrapping macros for the C interface.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
  13. #define LLVM_SUPPORT_CBINDINGWRAPPING_H
  14. #include "llvm-c/Types.h"
  15. #include "llvm/Support/Casting.h"
  16. #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
  17. inline ty *unwrap(ref P) { \
  18. return reinterpret_cast<ty*>(P); \
  19. } \
  20. \
  21. inline ref wrap(const ty *P) { \
  22. return reinterpret_cast<ref>(const_cast<ty*>(P)); \
  23. }
  24. #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
  25. DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
  26. \
  27. template<typename T> \
  28. inline T *unwrap(ref P) { \
  29. return cast<T>(unwrap(P)); \
  30. }
  31. #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
  32. DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
  33. \
  34. template<typename T> \
  35. inline T *unwrap(ref P) { \
  36. T *Q = (T*)unwrap(P); \
  37. assert(Q && "Invalid cast!"); \
  38. return Q; \
  39. }
  40. #endif