1251607Sdim//===- llvm/Support/CBindingWrapph.h - C Interface Wrapping -----*- C++ -*-===// 2251607Sdim// 3251607Sdim// The LLVM Compiler Infrastructure 4251607Sdim// 5251607Sdim// This file is distributed under the University of Illinois Open Source 6251607Sdim// License. See LICENSE.TXT for details. 7251607Sdim// 8251607Sdim//===----------------------------------------------------------------------===// 9251607Sdim// 10251607Sdim// This file declares the wrapping macros for the C interface. 11251607Sdim// 12251607Sdim//===----------------------------------------------------------------------===// 13251607Sdim 14251607Sdim#ifndef LLVM_C_BINDING_WRAPPING_H 15251607Sdim#define LLVM_C_BINDING_WRAPPING_H 16251607Sdim 17251607Sdim#include "llvm/Support/Casting.h" 18251607Sdim 19251607Sdim#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 20251607Sdim inline ty *unwrap(ref P) { \ 21251607Sdim return reinterpret_cast<ty*>(P); \ 22251607Sdim } \ 23251607Sdim \ 24251607Sdim inline ref wrap(const ty *P) { \ 25251607Sdim return reinterpret_cast<ref>(const_cast<ty*>(P)); \ 26251607Sdim } 27251607Sdim 28251607Sdim#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \ 29251607Sdim DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 30251607Sdim \ 31251607Sdim template<typename T> \ 32251607Sdim inline T *unwrap(ref P) { \ 33251607Sdim return cast<T>(unwrap(P)); \ 34251607Sdim } 35251607Sdim 36251607Sdim#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ 37251607Sdim DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 38251607Sdim \ 39251607Sdim template<typename T> \ 40251607Sdim inline T *unwrap(ref P) { \ 41251607Sdim T *Q = (T*)unwrap(P); \ 42251607Sdim assert(Q && "Invalid cast!"); \ 43251607Sdim return Q; \ 44251607Sdim } 45251607Sdim 46251607Sdim#endif 47