Removing the silly CHelpers header by rolling wrap and unwrap into the C

bindings headers themselves, hidden behind #ifdef __cplusplus.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42666 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Gordon Henriksen 2007-10-05 23:59:36 +00:00
parent bf287b63b3
commit acd96191cd
5 changed files with 101 additions and 125 deletions

View File

@ -170,8 +170,6 @@
9FE25D940CAB16FB005383FC /* RegisterCoalescer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RegisterCoalescer.cpp; sourceTree = "<group>"; };
9FE25D950CAB1724005383FC /* APFloat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APFloat.cpp; sourceTree = "<group>"; };
9FE25D960CAB1759005383FC /* TargetCallingConv.td */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TargetCallingConv.td; sourceTree = "<group>"; };
9FE25D970CAB17F9005383FC /* DominatorCalculation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DominatorCalculation.h; path = ../lib/VMCore/DominatorCalculation.h; sourceTree = SOURCE_ROOT; };
9FE25D980CAB17F9005383FC /* DominatorInternals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DominatorInternals.cpp; path = ../lib/VMCore/DominatorInternals.cpp; sourceTree = SOURCE_ROOT; };
9FE4508B0C77A77000C4FEA4 /* ARMCodeEmitter.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ARMCodeEmitter.cpp; sourceTree = "<group>"; };
9FE4508C0C77A77000C4FEA4 /* ARMGenAsmWriter.inc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.pascal; path = ARMGenAsmWriter.inc; sourceTree = "<group>"; };
9FE4508D0C77A77000C4FEA4 /* ARMGenDAGISel.inc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.pascal; path = ARMGenDAGISel.inc; sourceTree = "<group>"; };
@ -1345,8 +1343,6 @@
9F77937D0C73C4F400551F9C /* ConstantFold.h */,
DE66EC6008ABE86A00323D32 /* Constants.cpp */,
9FD3E5900CA0129D00E54D15 /* Core.cpp */,
9FE25D970CAB17F9005383FC /* DominatorCalculation.h */,
9FE25D980CAB17F9005383FC /* DominatorInternals.cpp */,
DE66EC6108ABE86A00323D32 /* Dominators.cpp */,
DE66EC6208ABE86A00323D32 /* Function.cpp */,
DE66EC6308ABE86A00323D32 /* Globals.cpp */,

View File

@ -23,12 +23,23 @@
|* with C++ due to name mangling. So in addition to C, this interface enables *|
|* tools written in such languages. *|
|* *|
|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
|* helpers to perform opaque reference<-->pointer conversions. These helpers *|
|* are shorter and more tightly typed than writing the casts by hand when *|
|* authoring bindings. In assert builds, they will do runtime type checking. *|
|* *|
\*===----------------------------------------------------------------------===*/
#ifndef LLVM_C_CORE_H
#define LLVM_C_CORE_H
#ifdef __cplusplus
/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
and 'unwrap' conversion functions. */
#include "llvm/Module.h"
#include "llvm/Support/LLVMBuilder.h"
extern "C" {
#endif
@ -412,6 +423,94 @@ LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
#ifdef __cplusplus
}
#endif
#endif
namespace llvm {
/* Opaque module conversions
*/
inline Module *unwrap(LLVMModuleRef M) {
return reinterpret_cast<Module*>(M);
}
inline LLVMModuleRef wrap(Module *M) {
return reinterpret_cast<LLVMModuleRef>(M);
}
/* Opaque type conversions
*/
inline Type *unwrap(LLVMTypeRef Ty) {
return reinterpret_cast<Type*>(Ty);
}
template<typename T>
inline T *unwrap(LLVMTypeRef Ty) {
return cast<T>(unwrap(Ty));
}
inline Type **unwrap(LLVMTypeRef* Tys) {
return reinterpret_cast<Type**>(Tys);
}
inline LLVMTypeRef wrap(const Type *Ty) {
return reinterpret_cast<LLVMTypeRef>(const_cast<Type*>(Ty));
}
inline LLVMTypeRef *wrap(const Type **Tys) {
return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
}
/* Opaque value conversions
*/
inline Value *unwrap(LLVMValueRef Val) {
return reinterpret_cast<Value*>(Val);
}
template<typename T>
inline T *unwrap(LLVMValueRef Val) {
return cast<T>(unwrap(Val));
}
inline Value **unwrap(LLVMValueRef *Vals) {
return reinterpret_cast<Value**>(Vals);
}
template<typename T>
inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
#if DEBUG
for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
cast<T>(*I);
#endif
return reinterpret_cast<T**>(Vals);
}
inline LLVMValueRef wrap(const Value *Val) {
return reinterpret_cast<LLVMValueRef>(const_cast<Value*>(Val));
}
inline LLVMValueRef *wrap(const Value **Vals) {
return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
}
/* Basic block conversions
*/
inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) {
return reinterpret_cast<BasicBlock*>(BBRef);
}
inline LLVMBasicBlockRef wrap(const BasicBlock *BB) {
return reinterpret_cast<LLVMBasicBlockRef>(const_cast<BasicBlock*>(BB));
}
/* Opaque builder conversions.
*/
inline LLVMBuilder *unwrap(LLVMBuilderRef B) {
return reinterpret_cast<LLVMBuilder*>(B);
}
inline LLVMBuilderRef wrap(LLVMBuilder *B) {
return reinterpret_cast<LLVMBuilderRef>(B);
}
}
#endif /* !defined(__cplusplus) */
#endif /* !defined(LLVM_C_CORE_H) */

View File

@ -1,104 +0,0 @@
//===-- Support/CHelpers.h - Utilities for writing C bindings -------------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// These opaque reference<-->pointer conversions are shorter and more tightly
// typed than writing the casts by hand in C bindings. In assert builds, they
// will do type checking.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_SUPPORT_CHELPERS_H
#define LLVM_SUPPORT_CHELPERS_H
#include "llvm/Module.h"
#include "llvm/Type.h"
#include "llvm/Value.h"
typedef struct LLVMOpaqueModule *LLVMModuleRef;
typedef struct LLVMOpaqueType *LLVMTypeRef;
typedef struct LLVMOpaqueValue *LLVMValueRef;
namespace llvm {
/// Opaque module conversions
///
inline Module *unwrap(LLVMModuleRef M) {
return reinterpret_cast<Module*>(M);
}
inline LLVMModuleRef wrap(Module *M) {
return reinterpret_cast<LLVMModuleRef>(M);
}
/// Opaque type conversions
///
inline Type *unwrap(LLVMTypeRef Ty) {
return reinterpret_cast<Type*>(Ty);
}
template<typename T>
inline T *unwrap(LLVMTypeRef Ty) {
return cast<T>(unwrap(Ty));
}
inline Type **unwrap(LLVMTypeRef* Tys) {
return reinterpret_cast<Type**>(Tys);
}
inline LLVMTypeRef wrap(const Type *Ty) {
return reinterpret_cast<LLVMTypeRef>(const_cast<Type*>(Ty));
}
inline LLVMTypeRef *wrap(const Type **Tys) {
return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
}
/// Opaque value conversions
///
inline Value *unwrap(LLVMValueRef Val) {
return reinterpret_cast<Value*>(Val);
}
template<typename T>
inline T *unwrap(LLVMValueRef Val) {
return cast<T>(unwrap(Val));
}
inline Value **unwrap(LLVMValueRef *Vals) {
return reinterpret_cast<Value**>(Vals);
}
template<typename T>
inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
#if DEBUG
for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
cast<T>(*I);
#endif
return reinterpret_cast<T**>(Vals);
}
inline LLVMValueRef wrap(const Value *Val) {
return reinterpret_cast<LLVMValueRef>(const_cast<Value*>(Val));
}
inline LLVMValueRef *wrap(const Value **Vals) {
return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
}
/// Basic block conversions
///
inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) {
return reinterpret_cast<BasicBlock*>(BBRef);
}
inline LLVMBasicBlockRef wrap(const BasicBlock *BB) {
return reinterpret_cast<LLVMBasicBlockRef>(const_cast<BasicBlock*>(BB));
}
}
#endif

View File

@ -9,7 +9,6 @@
#include "llvm-c/BitWriter.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/CHelpers.h"
#include <fstream>
using namespace llvm;

View File

@ -17,25 +17,11 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Support/CHelpers.h"
#include "llvm/Support/LLVMBuilder.h"
#include "llvm/TypeSymbolTable.h"
#include <cassert>
using namespace llvm;
namespace {
/// Opaque builder conversions.
///
inline LLVMBuilder *unwrap(LLVMBuilderRef B) {
return reinterpret_cast<LLVMBuilder*>(B);
}
inline LLVMBuilderRef wrap(LLVMBuilder *B) {
return reinterpret_cast<LLVMBuilderRef>(B);
}
}
/*===-- Operations on modules ---------------------------------------------===*/