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"
19 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
20 inline ty *unwrap(ref P) { \
21 return reinterpret_cast<ty*>(P); \
24 inline ref wrap(const ty *P) { \
25 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
28 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
29 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
31 template<typename T> \
32 inline T *unwrap(ref P) { \
33 return cast<T>(unwrap(P)); \
36 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
37 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
39 template<typename T> \
40 inline T *unwrap(ref P) { \
41 T *Q = (T*)unwrap(P); \
42 assert(Q && "Invalid cast!"); \