LLVM API Documentation

CBindingWrapping.h
Go to the documentation of this file.
00001 //===- llvm/Support/CBindingWrapph.h - C Interface Wrapping -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the wrapping macros for the C interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
00015 #define LLVM_SUPPORT_CBINDINGWRAPPING_H
00016 
00017 #include "llvm/Support/Casting.h"
00018 
00019 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)     \
00020   inline ty *unwrap(ref P) {                            \
00021     return reinterpret_cast<ty*>(P);                    \
00022   }                                                     \
00023                                                         \
00024   inline ref wrap(const ty *P) {                        \
00025     return reinterpret_cast<ref>(const_cast<ty*>(P));   \
00026   }
00027 
00028 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)        \
00029   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)           \
00030                                                         \
00031   template<typename T>                                  \
00032   inline T *unwrap(ref P) {                             \
00033     return cast<T>(unwrap(P));                          \
00034   }
00035 
00036 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)     \
00037   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)           \
00038                                                         \
00039   template<typename T>                                  \
00040   inline T *unwrap(ref P) {                             \
00041     T *Q = (T*)unwrap(P);                               \
00042     assert(Q && "Invalid cast!");                       \
00043     return Q;                                           \
00044   }
00045 
00046 #endif