1//===- llvm/Support/CBindingWrapph.h - C Interface Wrapping -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the wrapping macros for the C interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
15#define LLVM_SUPPORT_CBINDINGWRAPPING_H
16
17#include "llvm-c/Types.h"
18#include "llvm/Support/Casting.h"
19
20#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
21 inline ty *unwrap(ref P) { \
22 return reinterpret_cast<ty*>(P); \
23 } \
24 \
25 inline ref wrap(const ty *P) { \
26 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
27 }
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
37#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
38 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
39 \
40 template<typename T> \
41 inline T *unwrap(ref P) { \
42 T *Q = (T*)unwrap(P); \
43 assert(Q && "Invalid cast!"); \
44 return Q; \
45 }
46
47#endif
48