1 //===- llvm/Support/CBindingWrapph.h - C Interface Wrapping -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the wrapping macros for the C interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
15 #define LLVM_SUPPORT_CBINDINGWRAPPING_H
17 #include "llvm/Support/Casting.h"
18 #include "llvm-c/Types.h"
20 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
21 inline ty *unwrap(ref P) { \
22 return reinterpret_cast<ty*>(P); \
25 inline ref wrap(const ty *P) { \
26 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
29 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
30 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
32 template<typename T> \
33 inline T *unwrap(ref P) { \
34 return cast<T>(unwrap(P)); \
37 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
38 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
40 template<typename T> \
41 inline T *unwrap(ref P) { \
42 T *Q = (T*)unwrap(P); \
43 assert(Q && "Invalid cast!"); \