llvm.org GIT mirror llvm / 40be1e8
This patch breaks up Wrap.h so that it does not have to include all of the things, and renames it to CBindingWrapping.h. I also moved CBindingWrapping.h into Support/. This new file just contains the macros for defining different wrap/unwrap methods. The calls to those macros, as well as any custom wrap/unwrap definitions (like for array of Values for example), are put into corresponding C++ headers. Doing this required some #include surgery, since some .cpp files relied on the fact that including Wrap.h implicitly caused the inclusion of a bunch of other things. This also now means that the C++ headers will include their corresponding C API headers; for example Value.h must include llvm-c/Core.h. I think this is harmless, since the C API headers contain just external function declarations and some C types, so I don't believe there should be any nasty dependency issues here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180881 91177308-0d34-0410-b5e6-96231b3b80d8 Filip Pizlo 7 years ago
32 changed file(s) with 156 addition(s) and 145 deletion(s). Raw diff Collapse all Expand all
2525 #include "llvm/Support/ValueHandle.h"
2626 #include "llvm/Target/TargetMachine.h"
2727 #include "llvm/Target/TargetOptions.h"
28 #include "llvm/Wrap.h"
2928 #include
3029 #include
3130 #include
633632 ExecutionEngine *create(TargetMachine *TM);
634633 };
635634
636 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
635 // Create wrappers for C Binding types (see CBindingWrapping.h).
636 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
637637
638638 } // End llvm namespace
639639
1717 #include "llvm/ADT/ilist.h"
1818 #include "llvm/IR/Instruction.h"
1919 #include "llvm/IR/SymbolTableListTraits.h"
20 #include "llvm/Support/CBindingWrapping.h"
2021 #include "llvm/Support/DataTypes.h"
2122
2223 namespace llvm {
297298 }
298299 };
299300
301 // Create wrappers for C Binding types (see CBindingWrapping.h).
302 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef)
303
300304 } // End llvm namespace
301305
302306 #endif
2222 #include "llvm/IR/Instructions.h"
2323 #include "llvm/IR/LLVMContext.h"
2424 #include "llvm/IR/Operator.h"
25 #include "llvm/Support/CBindingWrapping.h"
2526 #include "llvm/Support/ConstantFolder.h"
2627
2728 namespace llvm {
13951396 }
13961397 };
13971398
1399 // Create wrappers for C Binding types (see CBindingWrapping.h).
1400 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef)
1401
13981402 }
13991403
14001404 #endif
1414 #ifndef LLVM_IR_LLVMCONTEXT_H
1515 #define LLVM_IR_LLVMCONTEXT_H
1616
17 #include "llvm/Support/CBindingWrapping.h"
1718 #include "llvm/Support/Compiler.h"
19 #include "llvm-c/Core.h"
1820
1921 namespace llvm {
2022
108110 /// only care about operating on a single thread.
109111 extern LLVMContext &getGlobalContext();
110112
113 // Create wrappers for C Binding types (see CBindingWrapping.h).
114 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef)
115
116 /* Specialized opaque context conversions.
117 */
118 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
119 return reinterpret_cast(Tys);
120 }
121
122 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
123 return reinterpret_cast(const_cast(Tys));
124 }
125
111126 }
112127
113128 #endif
1919 #include "llvm/IR/GlobalAlias.h"
2020 #include "llvm/IR/GlobalVariable.h"
2121 #include "llvm/IR/Metadata.h"
22 #include "llvm/Support/CBindingWrapping.h"
2223 #include "llvm/Support/DataTypes.h"
2324
2425 namespace llvm {
583584 return O;
584585 }
585586
587 // Create wrappers for C Binding types (see CBindingWrapping.h).
588 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef)
589
590 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
591 * Module.
592 */
593 inline Module *unwrap(LLVMModuleProviderRef MP) {
594 return reinterpret_cast(MP);
595 }
596
586597 } // End llvm namespace
587598
588599 #endif
1616
1717 #include "llvm/ADT/APFloat.h"
1818 #include "llvm/Support/Casting.h"
19 #include "llvm/Support/CBindingWrapping.h"
1920 #include "llvm/Support/DataTypes.h"
2021 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm-c/Core.h"
2123
2224 namespace llvm {
2325
466468 }
467469 };
468470
471 // Create wrappers for C Binding types (see CBindingWrapping.h).
472 DEFINE_ISA_CONVERSION_FUNCTIONS(Type, LLVMTypeRef)
473
474 /* Specialized opaque type conversions.
475 */
476 inline Type **unwrap(LLVMTypeRef* Tys) {
477 return reinterpret_cast(Tys);
478 }
479
480 inline LLVMTypeRef *wrap(Type **Tys) {
481 return reinterpret_cast(const_cast(Tys));
482 }
483
469484 } // End llvm namespace
470485
471486 #endif
2525 #define LLVM_IR_USE_H
2626
2727 #include "llvm/ADT/PointerIntPair.h"
28 #include "llvm/Support/CBindingWrapping.h"
2829 #include "llvm/Support/Compiler.h"
30 #include "llvm-c/Core.h"
2931 #include
3032 #include
3133
213215 unsigned getOperandNo() const;
214216 };
215217
218 // Create wrappers for C Binding types (see CBindingWrapping.h).
219 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef)
220
216221 } // End llvm namespace
217222
218223 #endif
1515
1616 #include "llvm/IR/Use.h"
1717 #include "llvm/Support/Casting.h"
18 #include "llvm/Support/CBindingWrapping.h"
1819 #include "llvm/Support/Compiler.h"
20 #include "llvm-c/Core.h"
1921
2022 namespace llvm {
2123
405407 enum { NumLowBitsAvailable = 2 };
406408 };
407409
410 // Create wrappers for C Binding types (see CBindingWrapping.h).
411 DEFINE_ISA_CONVERSION_FUNCTIONS(Value, LLVMValueRef)
412
413 /* Specialized opaque value conversions.
414 */
415 inline Value **unwrap(LLVMValueRef *Vals) {
416 return reinterpret_cast(Vals);
417 }
418
419 template
420 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
421 #ifdef DEBUG
422 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
423 cast(*I);
424 #endif
425 (void)Length;
426 return reinterpret_cast(Vals);
427 }
428
429 inline LLVMValueRef *wrap(const Value **Vals) {
430 return reinterpret_cast(const_cast(Vals));
431 }
432
408433 } // End llvm namespace
409434
410435 #endif
1717 #define LLVM_PASSMANAGER_H
1818
1919 #include "llvm/Pass.h"
20 #include "llvm/Support/CBindingWrapping.h"
2021
2122 namespace llvm {
2223
9798 Module *M;
9899 };
99100
101 // Create wrappers for C Binding types (see CBindingWrapping.h).
102 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef)
103
100104 } // End llvm namespace
101105
102106 #endif
1717 #define LLVM_PASSREGISTRY_H
1818
1919 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/CBindingWrapping.h"
21 #include "llvm-c/Core.h"
2022
2123 namespace llvm {
2224
7880 void removeRegistrationListener(PassRegistrationListener *L);
7981 };
8082
83 // Create wrappers for C Binding types (see CBindingWrapping.h).
84 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef)
85
8186 }
8287
8388 #endif
0 //===- llvm/Wrap.h - C++ Type Wrapping for the C Interface -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the wrapping macros for the C interface.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_C_BINDING_WRAPPING_H
14 #define LLVM_C_BINDING_WRAPPING_H
15
16 #include "llvm/Support/Casting.h"
17
18 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
19 inline ty *unwrap(ref P) { \
20 return reinterpret_cast(P); \
21 } \
22 \
23 inline ref wrap(const ty *P) { \
24 return reinterpret_cast(const_cast(P)); \
25 }
26
27 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
28 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
29 \
30 template \
31 inline T *unwrap(ref P) { \
32 return cast(unwrap(P)); \
33 }
34
35 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
36 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
37 \
38 template \
39 inline T *unwrap(ref P) { \
40 T *Q = (T*)unwrap(P); \
41 assert(Q && "Invalid cast!"); \
42 return Q; \
43 }
44
45 #endif
1414 #define LLVM_SUPPORT_MEMORYBUFFER_H
1515
1616 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/CBindingWrapping.h"
1718 #include "llvm/Support/Compiler.h"
1819 #include "llvm/Support/DataTypes.h"
20 #include "llvm-c/Core.h"
1921
2022 namespace llvm {
2123
136138 virtual BufferKind getBufferKind() const = 0;
137139 };
138140
141 // Create wrappers for C Binding types (see CBindingWrapping.h).
142 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef)
143
139144 } // end namespace llvm
140145
141146 #endif
+0
-124
include/llvm/Wrap.h less more
None //===- llvm/Wrap.h - C++ Type Wrapping for the C Interface -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the wrapping functions for the C interface.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_WRAP_H
14 #define LLVM_WRAP_H
15
16 #include "llvm-c/Core.h"
17 #include "llvm/IR/BasicBlock.h"
18 #include "llvm/IR/IRBuilder.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/IR/Type.h"
21 #include "llvm/PassRegistry.h"
22
23 /* When included into a C++ source file, also declares 'wrap' and 'unwrap'
24 helpers to perform opaque reference<-->pointer conversions. These helpers
25 are shorter and more tightly typed than writing the casts by hand when
26 authoring bindings. In assert builds, they will do runtime type checking.
27
28 Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
29 and 'unwrap' conversion functions. */
30
31 namespace llvm {
32 class MemoryBuffer;
33 class PassManagerBase;
34 struct GenericValue;
35 class ExecutionEngine;
36
37 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
38 inline ty *unwrap(ref P) { \
39 return reinterpret_cast(P); \
40 } \
41 \
42 inline ref wrap(const ty *P) { \
43 return reinterpret_cast(const_cast(P)); \
44 }
45
46 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
47 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
48 \
49 template \
50 inline T *unwrap(ref P) { \
51 return cast(unwrap(P)); \
52 }
53
54 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
55 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
56 \
57 template \
58 inline T *unwrap(ref P) { \
59 T *Q = (T*)unwrap(P); \
60 assert(Q && "Invalid cast!"); \
61 return Q; \
62 }
63
64 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
65 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
66 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
67 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
68 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
69 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
70 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
71 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
72 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
73 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
74
75 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
76 * Module.
77 */
78 inline Module *unwrap(LLVMModuleProviderRef MP) {
79 return reinterpret_cast(MP);
80 }
81
82 /* Specialized opaque context conversions.
83 */
84 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
85 return reinterpret_cast(Tys);
86 }
87
88 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
89 return reinterpret_cast(const_cast(Tys));
90 }
91
92 /* Specialized opaque type conversions.
93 */
94 inline Type **unwrap(LLVMTypeRef* Tys) {
95 return reinterpret_cast(Tys);
96 }
97
98 inline LLVMTypeRef *wrap(Type **Tys) {
99 return reinterpret_cast(const_cast(Tys));
100 }
101
102 /* Specialized opaque value conversions.
103 */
104 inline Value **unwrap(LLVMValueRef *Vals) {
105 return reinterpret_cast(Vals);
106 }
107
108 template
109 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
110 #ifdef DEBUG
111 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
112 cast(*I);
113 #endif
114 (void)Length;
115 return reinterpret_cast(Vals);
116 }
117
118 inline LLVMValueRef *wrap(const Value **Vals) {
119 return reinterpret_cast(const_cast(Vals));
120 }
121 }
122
123 #endif
88
99 #include "llvm-c/Analysis.h"
1010 #include "llvm-c/Initialization.h"
11 #include "llvm/Wrap.h"
1211 #include "llvm/Analysis/Verifier.h"
1312 #include "llvm/InitializePasses.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/PassRegistry.h"
1415 #include
1516
1617 using namespace llvm;
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/InitializePasses.h"
14 #include "llvm/Wrap.h"
14 #include "llvm/PassRegistry.h"
1515 #include "llvm-c/Initialization.h"
1616
1717 using namespace llvm;
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm-c/BitReader.h"
10 #include "llvm/Wrap.h"
1110 #include "llvm/Bitcode/ReaderWriter.h"
1211 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/Module.h"
1313 #include "llvm/Support/MemoryBuffer.h"
1414 #include
1515 #include
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm-c/BitWriter.h"
10 #include "llvm/Wrap.h"
1110 #include "llvm/Bitcode/ReaderWriter.h"
11 #include "llvm/IR/Module.h"
1212 #include "llvm/Support/raw_ostream.h"
1313 using namespace llvm;
1414
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/InitializePasses.h"
15 #include "llvm/Wrap.h"
15 #include "llvm/PassRegistry.h"
1616 #include "llvm-c/Initialization.h"
1717
1818 using namespace llvm;
1414 #include "llvm-c/ExecutionEngine.h"
1515 #include "llvm/ExecutionEngine/ExecutionEngine.h"
1616 #include "llvm/ExecutionEngine/GenericValue.h"
17 #include "llvm/IR/DerivedTypes.h"
18 #include "llvm/IR/Module.h"
1719 #include "llvm/Support/ErrorHandling.h"
1820 #include
1921
2022 using namespace llvm;
2123
2224 // Wrapping the C bindings types.
23 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue, LLVMGenericValueRef )
25 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue, LLVMGenericValueRef)
2426
2527 inline DataLayout *unwrap(LLVMTargetDataRef P) {
2628 return reinterpret_cast(P);
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm-c/Core.h"
15 #include "llvm/Wrap.h"
1615 #include "llvm/Bitcode/ReaderWriter.h"
1716 #include "llvm/IR/Attributes.h"
1817 #include "llvm/IR/Constants.h"
2120 #include "llvm/IR/GlobalVariable.h"
2221 #include "llvm/IR/InlineAsm.h"
2322 #include "llvm/IR/IntrinsicInst.h"
23 #include "llvm/IR/IRBuilder.h"
2424 #include "llvm/IR/LLVMContext.h"
25 #include "llvm/IR/Module.h"
2526 #include "llvm/PassManager.h"
2627 #include "llvm/Support/CallSite.h"
2728 #include "llvm/Support/Debug.h"
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/Linker.h"
14 #include "llvm/Wrap.h"
1514 #include "llvm-c/Linker.h"
1615 #include "llvm/ADT/DenseSet.h"
1716 #include "llvm/ADT/Optional.h"
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/ADT/SmallVector.h"
1415 #include "llvm/Object/ObjectFile.h"
1516 #include "llvm-c/Object.h"
16 #include "llvm/Wrap.h"
1717
1818 using namespace llvm;
1919 using namespace object;
1515 #include "llvm-c/Initialization.h"
1616 #include "llvm/IR/DataLayout.h"
1717 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/IR/Value.h"
1819 #include "llvm/InitializePasses.h"
1920 #include "llvm/PassManager.h"
20 #include "llvm/Wrap.h"
2121 #include "llvm/Target/TargetLibraryInfo.h"
2222 #include
2323
1616 #include "llvm/IR/DataLayout.h"
1717 #include "llvm/IR/Module.h"
1818 #include "llvm/PassManager.h"
19 #include "llvm/Wrap.h"
2019 #include "llvm/Support/CodeGen.h"
2120 #include "llvm/Support/FormattedStream.h"
2221 #include "llvm/Support/TargetRegistry.h"
1616 #include "llvm-c/Transforms/IPO.h"
1717 #include "llvm/InitializePasses.h"
1818 #include "llvm/PassManager.h"
19 #include "llvm/Wrap.h"
2019 #include "llvm/Transforms/IPO.h"
2120
2221 using namespace llvm;
1818 #include "llvm/Analysis/Passes.h"
1919 #include "llvm/Analysis/Verifier.h"
2020 #include "llvm/PassManager.h"
21 #include "llvm/Wrap.h"
2221 #include "llvm/Support/CommandLine.h"
2322 #include "llvm/Support/ManagedStatic.h"
2423 #include "llvm/Target/TargetLibraryInfo.h"
5252 #include "llvm/Support/ValueHandle.h"
5353 #include "llvm/Target/TargetLibraryInfo.h"
5454 #include "llvm/Transforms/Utils/Local.h"
55 #include "llvm/Wrap.h"
5655 #include
5756 #include
5857 using namespace llvm;
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/InitializePasses.h"
15 #include "llvm/Wrap.h"
15 #include "llvm/PassRegistry.h"
1616 #include "llvm-c/Initialization.h"
1717
1818 using namespace llvm;
1616 #include "llvm-c/Core.h"
1717 #include "llvm-c/Initialization.h"
1818 #include "llvm/InitializePasses.h"
19 #include "llvm/Wrap.h"
2019 #include "llvm/Support/CommandLine.h"
2120
2221 namespace llvm {
2020 #include "llvm/IR/DataLayout.h"
2121 #include "llvm/InitializePasses.h"
2222 #include "llvm/PassManager.h"
23 #include "llvm/Wrap.h"
2423
2524 using namespace llvm;
2625
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/InitializePasses.h"
15 #include "llvm/Wrap.h"
15 #include "llvm/PassRegistry.h"
1616 #include "llvm-c/Initialization.h"
1717
1818 using namespace llvm;
1919 #include "llvm/Analysis/Verifier.h"
2020 #include "llvm/InitializePasses.h"
2121 #include "llvm/PassManager.h"
22 #include "llvm/Wrap.h"
2322
2423 using namespace llvm;
2524