Move C++ code out of the C headers and into either C++ headers
authorEric Christopher <echristo@gmail.com>
Mon, 22 Apr 2013 22:47:22 +0000 (22:47 +0000)
committerEric Christopher <echristo@gmail.com>
Mon, 22 Apr 2013 22:47:22 +0000 (22:47 +0000)
or the C++ files themselves. This enables people to use
just a C compiler to interoperate with LLVM.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180063 91177308-0d34-0410-b5e6-96231b3b80d8

27 files changed:
include/llvm-c/Core.h
include/llvm-c/ExecutionEngine.h
include/llvm-c/Object.h
include/llvm-c/Target.h
include/llvm-c/TargetMachine.h
include/llvm-c/Transforms/PassManagerBuilder.h
include/llvm/Target/TargetMachine.h
include/llvm/Wrap.h [new file with mode: 0644]
lib/Analysis/Analysis.cpp
lib/Analysis/IPA/IPA.cpp
lib/Bitcode/Reader/BitReader.cpp
lib/Bitcode/Writer/BitWriter.cpp
lib/CodeGen/CodeGen.cpp
lib/ExecutionEngine/ExecutionEngineBindings.cpp
lib/IR/Core.cpp
lib/Linker/LinkModules.cpp
lib/Object/Object.cpp
lib/Target/Target.cpp
lib/Target/TargetMachineC.cpp
lib/Transforms/IPO/IPO.cpp
lib/Transforms/IPO/PassManagerBuilder.cpp
lib/Transforms/InstCombine/InstructionCombining.cpp
lib/Transforms/Instrumentation/Instrumentation.cpp
lib/Transforms/ObjCARC/ObjCARC.cpp
lib/Transforms/Scalar/Scalar.cpp
lib/Transforms/Utils/Utils.cpp
lib/Transforms/Vectorize/Vectorize.cpp

index 96359af51a0d8cc4b2cfd2771d272c2a206d0a09..559c50ed3c93cf498eda7722689d266044221a36 100644 (file)
 #include "llvm/Support/DataTypes.h"
 
 #ifdef __cplusplus
 #include "llvm/Support/DataTypes.h"
 
 #ifdef __cplusplus
-
-/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 
-   and 'unwrap' conversion functions. */
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Module.h"
-#include "llvm/PassRegistry.h"
-
 extern "C" {
 #endif
 
 extern "C" {
 #endif
 
@@ -60,11 +53,6 @@ extern "C" {
  * with C++ due to name mangling. So in addition to C, this interface enables
  * tools written in such languages.
  *
  * 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.
- *
  * @{
  */
 
  * @{
  */
 
@@ -2690,100 +2678,6 @@ LLVMBool LLVMIsMultithreaded();
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
-
-namespace llvm {
-  class MemoryBuffer;
-  class PassManagerBase;
-  
-  #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
-    inline ty *unwrap(ref P) {                          \
-      return reinterpret_cast<ty*>(P);                  \
-    }                                                   \
-                                                        \
-    inline ref wrap(const ty *P) {                      \
-      return reinterpret_cast<ref>(const_cast<ty*>(P)); \
-    }
-  
-  #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
-    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
-                                                        \
-    template<typename T>                                \
-    inline T *unwrap(ref P) {                           \
-      return cast<T>(unwrap(P));                        \
-    }
-  
-  #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
-    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
-                                                        \
-    template<typename T>                                \
-    inline T *unwrap(ref P) {                           \
-      T *Q = (T*)unwrap(P);                             \
-      assert(Q && "Invalid cast!");                     \
-      return Q;                                         \
-    }
-  
-  DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
-  DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use,                LLVMUseRef           )
-  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
-  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry,       LLVMPassRegistryRef  )
-  /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
-   * Module.
-   */
-  inline Module *unwrap(LLVMModuleProviderRef MP) {
-    return reinterpret_cast<Module*>(MP);
-  }
-  
-  #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
-  #undef DEFINE_ISA_CONVERSION_FUNCTIONS
-  #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
-
-  /* Specialized opaque context conversions.
-   */
-  inline LLVMContext **unwrap(LLVMContextRef* Tys) {
-    return reinterpret_cast<LLVMContext**>(Tys);
-  }
-  
-  inline LLVMContextRef *wrap(const LLVMContext **Tys) {
-    return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
-  }
-  
-  /* Specialized opaque type conversions.
-   */
-  inline Type **unwrap(LLVMTypeRef* Tys) {
-    return reinterpret_cast<Type**>(Tys);
-  }
-  
-  inline LLVMTypeRef *wrap(Type **Tys) {
-    return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
-  }
-  
-  /* Specialized opaque value conversions.
-   */ 
-  inline Value **unwrap(LLVMValueRef *Vals) {
-    return reinterpret_cast<Value**>(Vals);
-  }
-  
-  template<typename T>
-  inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
-    #ifdef DEBUG
-    for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
-      cast<T>(*I);
-    #endif
-    (void)Length;
-    return reinterpret_cast<T**>(Vals);
-  }
-  
-  inline LLVMValueRef *wrap(const Value **Vals) {
-    return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
-  }
-}
-
 #endif /* !defined(__cplusplus) */
 
 #endif /* !defined(LLVM_C_CORE_H) */
 #endif /* !defined(__cplusplus) */
 
 #endif /* !defined(LLVM_C_CORE_H) */
index cb77bb2e2e23d4c68021d02d28f30c14af10d2eb..be763312d22e2a3da1810c0b516acb5376905e67 100644 (file)
@@ -137,27 +137,7 @@ void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
  */
 
 #ifdef __cplusplus
  */
 
 #ifdef __cplusplus
-}
-
-namespace llvm {
-  struct GenericValue;
-  class ExecutionEngine;
-  
-  #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
-    inline ty *unwrap(ref P) {                          \
-      return reinterpret_cast<ty*>(P);                  \
-    }                                                   \
-                                                        \
-    inline ref wrap(const ty *P) {                      \
-      return reinterpret_cast<ref>(const_cast<ty*>(P)); \
-    }
-  
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue,    LLVMGenericValueRef   )
-  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
-  
-  #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
-}
-  
+}  
 #endif /* defined(__cplusplus) */
 
 #endif
 #endif /* defined(__cplusplus) */
 
 #endif
index e2dad62b4e07b8f946cdc42545373d472c995f99..ecccfeed7f54b1d8955a294f8fb744d3da6db8c9 100644 (file)
@@ -23,8 +23,6 @@
 #include "llvm/Config/llvm-config.h"
 
 #ifdef __cplusplus
 #include "llvm/Config/llvm-config.h"
 
 #ifdef __cplusplus
-#include "llvm/Object/ObjectFile.h"
-
 extern "C" {
 #endif
 
 extern "C" {
 #endif
 
@@ -99,50 +97,6 @@ const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
-
-namespace llvm {
-  namespace object {
-    inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
-      return reinterpret_cast<ObjectFile*>(OF);
-    }
-
-    inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
-      return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
-    }
-
-    inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
-      return reinterpret_cast<section_iterator*>(SI);
-    }
-
-    inline LLVMSectionIteratorRef
-    wrap(const section_iterator *SI) {
-      return reinterpret_cast<LLVMSectionIteratorRef>
-        (const_cast<section_iterator*>(SI));
-    }
-
-    inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
-      return reinterpret_cast<symbol_iterator*>(SI);
-    }
-
-    inline LLVMSymbolIteratorRef
-    wrap(const symbol_iterator *SI) {
-      return reinterpret_cast<LLVMSymbolIteratorRef>
-        (const_cast<symbol_iterator*>(SI));
-    }
-
-    inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
-      return reinterpret_cast<relocation_iterator*>(SI);
-    }
-
-    inline LLVMRelocationIteratorRef
-    wrap(const relocation_iterator *SI) {
-      return reinterpret_cast<LLVMRelocationIteratorRef>
-        (const_cast<relocation_iterator*>(SI));
-    }
-
-  }
-}
-
 #endif /* defined(__cplusplus) */
 
 #endif
 #endif /* defined(__cplusplus) */
 
 #endif
index 57abfa0207fe7f936753a3b76362597c118b450d..80fc3e5ad72c07b1d3d65a072f04a26340a53ab4 100644 (file)
@@ -235,29 +235,6 @@ void LLVMDisposeTargetData(LLVMTargetDataRef);
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
-
-namespace llvm {
-  class DataLayout;
-  class TargetLibraryInfo;
-
-  inline DataLayout *unwrap(LLVMTargetDataRef P) {
-    return reinterpret_cast<DataLayout*>(P);
-  }
-  
-  inline LLVMTargetDataRef wrap(const DataLayout *P) {
-    return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout*>(P));
-  }
-
-  inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
-    return reinterpret_cast<TargetLibraryInfo*>(P);
-  }
-
-  inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
-    TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
-    return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
-  }
-}
-
 #endif /* defined(__cplusplus) */
 
 #endif
 #endif /* defined(__cplusplus) */
 
 #endif
index a02161aaa4e418a8041e6b9d1ac4f561c3ae4c7f..587872350834f12b5f33c625234e123a56799b11 100644 (file)
@@ -117,30 +117,8 @@ LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
 /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
   LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
 /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
   LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
-
-
-
 #ifdef __cplusplus
 }
 #ifdef __cplusplus
 }
-
-namespace llvm {
-  class TargetMachine;
-  class Target;
-
-  inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
-    return reinterpret_cast<TargetMachine*>(P);
-  }
-  inline Target *unwrap(LLVMTargetRef P) {
-    return reinterpret_cast<Target*>(P);
-  }
-  inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
-    return reinterpret_cast<LLVMTargetMachineRef>(
-      const_cast<TargetMachine*>(P));
-  }
-  inline LLVMTargetRef wrap(const Target * P) {
-    return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
-  }
-}
 #endif
 
 #endif
 #endif
 
 #endif
index 82e513d4905d9ff19484861703c6b8ee22f8654c..545f8aae8ca250aad81c0bb6b18a02837dfd37d6 100644 (file)
@@ -86,16 +86,6 @@ void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
-
-namespace llvm {
-  inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
-    return reinterpret_cast<PassManagerBuilder*>(P);
-  }
-
-  inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
-    return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
-  }
-}
 #endif
 
 #endif
 #endif
 
 #endif
index 66f3a3c71b689852a06eeee802a06caaeb555627..37a79fe8526f4d8161c9ded84fa812e7f83d0374 100644 (file)
@@ -32,6 +32,7 @@ class MCContext;
 class PassManagerBase;
 class Target;
 class DataLayout;
 class PassManagerBase;
 class Target;
 class DataLayout;
+class TargetLibraryInfo;
 class TargetFrameLowering;
 class TargetInstrInfo;
 class TargetIntrinsicInfo;
 class TargetFrameLowering;
 class TargetInstrInfo;
 class TargetIntrinsicInfo;
diff --git a/include/llvm/Wrap.h b/include/llvm/Wrap.h
new file mode 100644 (file)
index 0000000..79790d4
--- /dev/null
@@ -0,0 +1,119 @@
+//===- llvm/Wrap.h - C++ Type Wrapping for the C Interface  -----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the wrapping functions for the C interface.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm-c/Core.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/PassRegistry.h"
+
+/* 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.
+
+  Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 
+  and 'unwrap' conversion functions. */
+
+namespace llvm {
+  class MemoryBuffer;
+  class PassManagerBase;
+  struct GenericValue;
+  class ExecutionEngine;
+
+  #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
+    inline ty *unwrap(ref P) {                          \
+      return reinterpret_cast<ty*>(P);                  \
+    }                                                   \
+                                                        \
+    inline ref wrap(const ty *P) {                      \
+      return reinterpret_cast<ref>(const_cast<ty*>(P)); \
+    }
+  
+  #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)      \
+    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
+                                                        \
+    template<typename T>                                \
+    inline T *unwrap(ref P) {                           \
+      return cast<T>(unwrap(P));                        \
+    }
+  
+  #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
+    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
+                                                        \
+    template<typename T>                                \
+    inline T *unwrap(ref P) {                           \
+      T *Q = (T*)unwrap(P);                             \
+      assert(Q && "Invalid cast!");                     \
+      return Q;                                         \
+    }
+  
+  DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
+  DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
+  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use,                LLVMUseRef           )
+  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
+  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry,       LLVMPassRegistryRef  )
+
+  /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
+   * Module.
+   */
+  inline Module *unwrap(LLVMModuleProviderRef MP) {
+    return reinterpret_cast<Module*>(MP);
+  }
+  
+  /* Specialized opaque context conversions.
+   */
+  inline LLVMContext **unwrap(LLVMContextRef* Tys) {
+    return reinterpret_cast<LLVMContext**>(Tys);
+  }
+  
+  inline LLVMContextRef *wrap(const LLVMContext **Tys) {
+    return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
+  }
+  
+  /* Specialized opaque type conversions.
+   */
+  inline Type **unwrap(LLVMTypeRef* Tys) {
+    return reinterpret_cast<Type**>(Tys);
+  }
+  
+  inline LLVMTypeRef *wrap(Type **Tys) {
+    return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
+  }
+  
+  /* Specialized opaque value conversions.
+   */ 
+  inline Value **unwrap(LLVMValueRef *Vals) {
+    return reinterpret_cast<Value**>(Vals);
+  }
+  
+  template<typename T>
+  inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
+    #ifdef DEBUG
+    for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
+      cast<T>(*I);
+    #endif
+    (void)Length;
+    return reinterpret_cast<T**>(Vals);
+  }
+  
+  inline LLVMValueRef *wrap(const Value **Vals) {
+    return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
+  }
+}
index 66e416cd140c97dc85215ae4e23529e3d1e7ce23..141a493aa8c7a106b3ddf5edd90827241287952c 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "llvm-c/Analysis.h"
 #include "llvm-c/Initialization.h"
 
 #include "llvm-c/Analysis.h"
 #include "llvm-c/Initialization.h"
+#include "llvm/Wrap.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/InitializePasses.h"
 #include <cstring>
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/InitializePasses.h"
 #include <cstring>
index aa5164e9e79bcfdfe8f44037863ed422c08000c3..e164e1dafdd16a5823ea7a262776cd53bb5b3f27 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
+#include "llvm/Wrap.h"
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
index 5cd6c552bd8a7b22b8aa80f339c0371eed47cd16..d777c8c6aad36ef57cb91cbbf7211018415b095f 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/BitReader.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/BitReader.h"
+#include "llvm/Wrap.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/MemoryBuffer.h"
index 9f51c35ad92e2068e64e9e55046fbcc9cc41b57c..a8b0cc4f4b5a93340d616d35e1d3521add3de5b5 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/BitWriter.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/BitWriter.h"
+#include "llvm/Wrap.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
index 35ec68d00cec77bac19fbd3ccb0ed170f7aa8e17..124fd4008ad69a24f9b678e26e21a0651e4541d9 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
+#include "llvm/Wrap.h"
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
index f4e8246476a550ddbb7c8a52b36639a260c64fed..03500c396fc19e4aa663ba871d51c445528711e6 100644 (file)
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Wrap.h"
 #include <cstring>
 
 using namespace llvm;
 
 #include <cstring>
 
 using namespace llvm;
 
+// Wrapping the C bindings types.
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue,       LLVMGenericValueRef  )
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine,    LLVMExecutionEngineRef)
+
+inline DataLayout *unwrap(LLVMTargetDataRef P) {
+  return reinterpret_cast<DataLayout*>(P);
+}
+  
+inline LLVMTargetDataRef wrap(const DataLayout *P) {
+  return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout*>(P));
+}
+
+inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
+  return reinterpret_cast<TargetLibraryInfo*>(P);
+}
+
+inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
+  TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
+  return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
+}
+
 /*===-- Operations on generic values --------------------------------------===*/
 
 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
 /*===-- Operations on generic values --------------------------------------===*/
 
 LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
index a47976f29cc28355b8349714c19f82e936591307..1585f25d6a63583e58300cb1e4adce640a480d25 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/Core.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm-c/Core.h"
+#include "llvm/Wrap.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/Constants.h"
index 74cbdadd61eba980e69aa22c382beb5b8e9d5e94..d3526a690153a62def010590e2b79d366a178cb0 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Linker.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Linker.h"
+#include "llvm/Wrap.h"
 #include "llvm-c/Linker.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm-c/Linker.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Optional.h"
index f061ea7cebedac40087ed7ac5189a7a006e8a7dc..ea641a4831ce0bf62a57251a8f38dfb0abfed53b 100644 (file)
 
 #include "llvm/Object/ObjectFile.h"
 #include "llvm-c/Object.h"
 
 #include "llvm/Object/ObjectFile.h"
 #include "llvm-c/Object.h"
+#include "llvm/Wrap.h"
 
 using namespace llvm;
 using namespace object;
 
 
 using namespace llvm;
 using namespace object;
 
+inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
+  return reinterpret_cast<ObjectFile*>(OF);
+}
+
+inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
+  return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
+}
+
+inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
+  return reinterpret_cast<section_iterator*>(SI);
+}
+
+inline LLVMSectionIteratorRef
+wrap(const section_iterator *SI) {
+  return reinterpret_cast<LLVMSectionIteratorRef>
+    (const_cast<section_iterator*>(SI));
+}
+
+inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
+  return reinterpret_cast<symbol_iterator*>(SI);
+}
+
+inline LLVMSymbolIteratorRef
+wrap(const symbol_iterator *SI) {
+  return reinterpret_cast<LLVMSymbolIteratorRef>
+    (const_cast<symbol_iterator*>(SI));
+}
+
+inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
+  return reinterpret_cast<relocation_iterator*>(SI);
+}
+
+inline LLVMRelocationIteratorRef
+wrap(const relocation_iterator *SI) {
+  return reinterpret_cast<LLVMRelocationIteratorRef>
+    (const_cast<relocation_iterator*>(SI));
+}
+
 // ObjectFile creation
 LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
   return wrap(ObjectFile::createObjectFile(unwrap(MemBuf)));
 // ObjectFile creation
 LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) {
   return wrap(ObjectFile::createObjectFile(unwrap(MemBuf)));
index 9a78ebc3facb150f34e4cc956f80d508e30daf5d..c96235c9538a1dcd38254d7a9fa6fd61d5af0f94 100644 (file)
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
+#include "llvm/Wrap.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include <cstring>
 
 using namespace llvm;
 
 #include "llvm/Target/TargetLibraryInfo.h"
 #include <cstring>
 
 using namespace llvm;
 
+inline DataLayout *unwrap(LLVMTargetDataRef P) {
+  return reinterpret_cast<DataLayout*>(P);
+}
+
+inline LLVMTargetDataRef wrap(const DataLayout *P) {
+  return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout*>(P));
+}
+
+inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
+  return reinterpret_cast<TargetLibraryInfo*>(P);
+}
+
+inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
+  TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
+  return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
+}
+
 void llvm::initializeTarget(PassRegistry &Registry) {
   initializeDataLayoutPass(Registry);
   initializeTargetLibraryInfoPass(Registry);
 void llvm::initializeTarget(PassRegistry &Registry) {
   initializeDataLayoutPass(Registry);
   initializeTargetLibraryInfoPass(Registry);
index 11a5d7a684509412a07d56420f946905892e2edb..7c644fcfcaa810e54d6358f3b5f56cac6b1a2a38 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Module.h"
 #include "llvm/PassManager.h"
+#include "llvm/Wrap.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/TargetRegistry.h"
 
 using namespace llvm;
 
 
 using namespace llvm;
 
+inline DataLayout *unwrap(LLVMTargetDataRef P) {
+  return reinterpret_cast<DataLayout*>(P);
+}
+
+inline LLVMTargetDataRef wrap(const DataLayout *P) {
+  return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout*>(P));
+}
 
 
+inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
+  return reinterpret_cast<TargetLibraryInfo*>(P);
+}
+
+inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
+  TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
+  return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
+}
+
+inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
+  return reinterpret_cast<TargetMachine*>(P);
+}
+inline Target *unwrap(LLVMTargetRef P) {
+  return reinterpret_cast<Target*>(P);
+}
+inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
+  return
+    reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
+}
+inline LLVMTargetRef wrap(const Target * P) {
+  return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
+}
 
 LLVMTargetRef LLVMGetFirstTarget() {
    const Target* target = &*TargetRegistry::begin();
 
 LLVMTargetRef LLVMGetFirstTarget() {
    const Target* target = &*TargetRegistry::begin();
index 5d563d8bbf512fd07daa3d66b739bc7f22ff58b3..f40a1b1f024f41acf2ebac67050e60fccfa0e582 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm-c/Transforms/IPO.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
 #include "llvm-c/Transforms/IPO.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
+#include "llvm/Wrap.h"
 #include "llvm/Transforms/IPO.h"
 
 using namespace llvm;
 #include "llvm/Transforms/IPO.h"
 
 using namespace llvm;
index ffd07b6afcecc10296fcb29b21dc09717af26466..e6e6f6ace44d37d5f2b5df5f585b122a5eda247d 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/PassManager.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/PassManager.h"
+#include "llvm/Wrap.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Target/TargetLibraryInfo.h"
@@ -330,6 +331,14 @@ void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
   PM.add(createGlobalDCEPass());
 }
 
   PM.add(createGlobalDCEPass());
 }
 
+inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
+    return reinterpret_cast<PassManagerBuilder*>(P);
+}
+
+inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
+  return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
+}
+
 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
   PassManagerBuilder *PMB = new PassManagerBuilder();
   return wrap(PMB);
 LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate() {
   PassManagerBuilder *PMB = new PassManagerBuilder();
   return wrap(PMB);
index c6115e3e91fe51d90d0ecf093e5891b09a803209..fc832dc0c35823109eaf53679e66715492c60320 100644 (file)
@@ -53,6 +53,7 @@
 #include "llvm/Support/ValueHandle.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Support/ValueHandle.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Utils/Local.h"
+#include "llvm/Wrap.h"
 #include <algorithm>
 #include <climits>
 using namespace llvm;
 #include <algorithm>
 #include <climits>
 using namespace llvm;
index 8ba102559bb6aeb9423d6d10587dd34e57be63d0..d5207b74baed44b78cf9d834a856afb60e3c4a37 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
+#include "llvm/Wrap.h"
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
index 373168e89888532c716d63bf7e3c07f7e6ac4a7e..b76a33668dee283da88f1aae4cd66667f7a8049f 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm-c/Core.h"
 #include "llvm-c/Initialization.h"
 #include "llvm/InitializePasses.h"
 #include "llvm-c/Core.h"
 #include "llvm-c/Initialization.h"
 #include "llvm/InitializePasses.h"
+#include "llvm/Wrap.h"
 #include "llvm/Support/CommandLine.h"
 
 namespace llvm {
 #include "llvm/Support/CommandLine.h"
 
 namespace llvm {
index 8a9c7da113c1f0a6fa59f5c103ac971b6d99fe15..a7dc26e202669b07ccf802674800ab49eb123eff 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
+#include "llvm/Wrap.h"
 
 using namespace llvm;
 
 
 using namespace llvm;
 
index 5812d4607dfcf78b7a462c54dcc7c6ff227a6d51..b7f92df203b180fbec6cb871e45f484a7dde1921 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
 //===----------------------------------------------------------------------===//
 
 #include "llvm/InitializePasses.h"
+#include "llvm/Wrap.h"
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
 #include "llvm-c/Initialization.h"
 
 using namespace llvm;
index a927fe145171e21cd4563c14f96d9bb4feb4b600..29e59fa59256e65599596755d243f59100669fd2 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassManager.h"
+#include "llvm/Wrap.h"
 
 using namespace llvm;
 
 
 using namespace llvm;