From: Gordon Henriksen Date: Fri, 5 Oct 2007 23:59:36 +0000 (+0000) Subject: Removing the silly CHelpers header by rolling wrap and unwrap into the C X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=acd96191cd8d85f376ec0baafdc4f21b3042f677 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 --- diff --git a/Xcode/LLVM.xcodeproj/project.pbxproj b/Xcode/LLVM.xcodeproj/project.pbxproj index 600a9cc6550..a195dbda590 100644 --- a/Xcode/LLVM.xcodeproj/project.pbxproj +++ b/Xcode/LLVM.xcodeproj/project.pbxproj @@ -170,8 +170,6 @@ 9FE25D940CAB16FB005383FC /* RegisterCoalescer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RegisterCoalescer.cpp; sourceTree = ""; }; 9FE25D950CAB1724005383FC /* APFloat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APFloat.cpp; sourceTree = ""; }; 9FE25D960CAB1759005383FC /* TargetCallingConv.td */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TargetCallingConv.td; sourceTree = ""; }; - 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 = ""; }; 9FE4508C0C77A77000C4FEA4 /* ARMGenAsmWriter.inc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.pascal; path = ARMGenAsmWriter.inc; sourceTree = ""; }; 9FE4508D0C77A77000C4FEA4 /* ARMGenDAGISel.inc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.pascal; path = ARMGenDAGISel.inc; sourceTree = ""; }; @@ -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 */, diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 47b89aa513e..fb01b837352 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -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(M); + } + + inline LLVMModuleRef wrap(Module *M) { + return reinterpret_cast(M); + } + + /* Opaque type conversions + */ + inline Type *unwrap(LLVMTypeRef Ty) { + return reinterpret_cast(Ty); + } + + template + inline T *unwrap(LLVMTypeRef Ty) { + return cast(unwrap(Ty)); + } + + inline Type **unwrap(LLVMTypeRef* Tys) { + return reinterpret_cast(Tys); + } + + inline LLVMTypeRef wrap(const Type *Ty) { + return reinterpret_cast(const_cast(Ty)); + } + + inline LLVMTypeRef *wrap(const Type **Tys) { + return reinterpret_cast(const_cast(Tys)); + } + + /* Opaque value conversions + */ + inline Value *unwrap(LLVMValueRef Val) { + return reinterpret_cast(Val); + } + + template + inline T *unwrap(LLVMValueRef Val) { + return cast(unwrap(Val)); + } + + inline Value **unwrap(LLVMValueRef *Vals) { + return reinterpret_cast(Vals); + } + + template + inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { + #if DEBUG + for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I) + cast(*I); + #endif + return reinterpret_cast(Vals); + } + + inline LLVMValueRef wrap(const Value *Val) { + return reinterpret_cast(const_cast(Val)); + } + + inline LLVMValueRef *wrap(const Value **Vals) { + return reinterpret_cast(const_cast(Vals)); + } + + /* Basic block conversions + */ + inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) { + return reinterpret_cast(BBRef); + } + + inline LLVMBasicBlockRef wrap(const BasicBlock *BB) { + return reinterpret_cast(const_cast(BB)); + } + + /* Opaque builder conversions. + */ + inline LLVMBuilder *unwrap(LLVMBuilderRef B) { + return reinterpret_cast(B); + } + + inline LLVMBuilderRef wrap(LLVMBuilder *B) { + return reinterpret_cast(B); + } +} + +#endif /* !defined(__cplusplus) */ + +#endif /* !defined(LLVM_C_CORE_H) */ diff --git a/include/llvm/Support/CHelpers.h b/include/llvm/Support/CHelpers.h deleted file mode 100644 index 0ae7503ab07..00000000000 --- a/include/llvm/Support/CHelpers.h +++ /dev/null @@ -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(M); - } - - inline LLVMModuleRef wrap(Module *M) { - return reinterpret_cast(M); - } - - /// Opaque type conversions - /// - inline Type *unwrap(LLVMTypeRef Ty) { - return reinterpret_cast(Ty); - } - - template - inline T *unwrap(LLVMTypeRef Ty) { - return cast(unwrap(Ty)); - } - - inline Type **unwrap(LLVMTypeRef* Tys) { - return reinterpret_cast(Tys); - } - - inline LLVMTypeRef wrap(const Type *Ty) { - return reinterpret_cast(const_cast(Ty)); - } - - inline LLVMTypeRef *wrap(const Type **Tys) { - return reinterpret_cast(const_cast(Tys)); - } - - /// Opaque value conversions - /// - inline Value *unwrap(LLVMValueRef Val) { - return reinterpret_cast(Val); - } - - template - inline T *unwrap(LLVMValueRef Val) { - return cast(unwrap(Val)); - } - - inline Value **unwrap(LLVMValueRef *Vals) { - return reinterpret_cast(Vals); - } - - template - inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { - #if DEBUG - for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I) - cast(*I); - #endif - return reinterpret_cast(Vals); - } - - inline LLVMValueRef wrap(const Value *Val) { - return reinterpret_cast(const_cast(Val)); - } - - inline LLVMValueRef *wrap(const Value **Vals) { - return reinterpret_cast(const_cast(Vals)); - } - - /// Basic block conversions - /// - inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) { - return reinterpret_cast(BBRef); - } - - inline LLVMBasicBlockRef wrap(const BasicBlock *BB) { - return reinterpret_cast(const_cast(BB)); - } -} - -#endif diff --git a/lib/Bitcode/Writer/BitWriter.cpp b/lib/Bitcode/Writer/BitWriter.cpp index b2e7ac2ec0f..8f562e98d9f 100644 --- a/lib/Bitcode/Writer/BitWriter.cpp +++ b/lib/Bitcode/Writer/BitWriter.cpp @@ -9,7 +9,6 @@ #include "llvm-c/BitWriter.h" #include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/Support/CHelpers.h" #include using namespace llvm; diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index f35951d45b0..b6a825462ae 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -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 using namespace llvm; -namespace { - /// Opaque builder conversions. - /// - inline LLVMBuilder *unwrap(LLVMBuilderRef B) { - return reinterpret_cast(B); - } - - inline LLVMBuilderRef wrap(LLVMBuilder *B) { - return reinterpret_cast(B); - } -} - /*===-- Operations on modules ---------------------------------------------===*/