CBindingWrapping.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Support/CBindingWrapping.h - C Interface Wrapping ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the wrapping macros for the C interface.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
  18. #define LLVM_SUPPORT_CBINDINGWRAPPING_H
  19. #include "llvm-c/Types.h"
  20. #include "llvm/Support/Casting.h"
  21. #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
  22. inline ty *unwrap(ref P) { \
  23. return reinterpret_cast<ty*>(P); \
  24. } \
  25. \
  26. inline ref wrap(const ty *P) { \
  27. return reinterpret_cast<ref>(const_cast<ty*>(P)); \
  28. }
  29. #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
  30. DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
  31. \
  32. template<typename T> \
  33. inline T *unwrap(ref P) { \
  34. return cast<T>(unwrap(P)); \
  35. }
  36. #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
  37. DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
  38. \
  39. template<typename T> \
  40. inline T *unwrap(ref P) { \
  41. T *Q = (T*)unwrap(P); \
  42. assert(Q && "Invalid cast!"); \
  43. return Q; \
  44. }
  45. #endif
  46. #ifdef __GNUC__
  47. #pragma GCC diagnostic pop
  48. #endif