CBindingWrapping.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===- llvm/Support/CBindingWrapph.h - C Interface Wrapping -----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file declares the wrapping macros for the C interface.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
  14. #define LLVM_SUPPORT_CBINDINGWRAPPING_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