Coverage Report

Created: 2020-06-26 05:44

/home/arjun/llvm-project/llvm/include/llvm/Support/CBindingWrapping.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/Support/CBindingWrapping.h - C Interface Wrapping ---*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file declares the wrapping macros for the C interface.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_SUPPORT_CBINDINGWRAPPING_H
14
#define LLVM_SUPPORT_CBINDINGWRAPPING_H
15
16
#include "llvm-c/Types.h"
17
#include "llvm/Support/Casting.h"
18
19
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)     \
20
0
  inline ty *unwrap(ref P) {                            \
21
0
    return reinterpret_cast<ty*>(P);                    \
22
0
  }                                                     \
23
                                                        \
24
0
  inline ref wrap(const ty *P) {                        \
25
0
    return reinterpret_cast<ref>(const_cast<ty*>(P));   \
26
0
  }
27
28
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)        \
29
  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)           \
30
                                                        \
31
  template<typename T>                                  \
32
  inline T *unwrap(ref P) {                             \
33
    return cast<T>(unwrap(P));                          \
34
  }
35
36
#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)     \
37
  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)           \
38
                                                        \
39
  template<typename T>                                  \
40
  inline T *unwrap(ref P) {                             \
41
    T *Q = (T*)unwrap(P);                               \
42
    assert(Q && "Invalid cast!");                       \
43
    return Q;                                           \
44
  }
45
46
#endif