Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:28

0001 //===- llvm/Support/CBindingWrapping.h - C Interface Wrapping ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the wrapping macros for the C interface.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
0014 #define LLVM_SUPPORT_CBINDINGWRAPPING_H
0015 
0016 #include "llvm-c/Types.h"
0017 #include "llvm/Support/Casting.h"
0018 
0019 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)     \
0020   inline ty *unwrap(ref P) {                            \
0021     return reinterpret_cast<ty*>(P);                    \
0022   }                                                     \
0023                                                         \
0024   inline ref wrap(const ty *P) {                        \
0025     return reinterpret_cast<ref>(const_cast<ty*>(P));   \
0026   }
0027 
0028 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)        \
0029   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)           \
0030                                                         \
0031   template<typename T>                                  \
0032   inline T *unwrap(ref P) {                             \
0033     return cast<T>(unwrap(P));                          \
0034   }
0035 
0036 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)     \
0037   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)           \
0038                                                         \
0039   template<typename T>                                  \
0040   inline T *unwrap(ref P) {                             \
0041     T *Q = (T*)unwrap(P);                               \
0042     assert(Q && "Invalid cast!");                       \
0043     return Q;                                           \
0044   }
0045 
0046 #endif