Skip to content

Commit 04d4e93

Browse files
committed
Move C++ code out of the C headers and into either C++ headers
or the C++ files themselves. This enables people to use just a C compiler to interoperate with LLVM. llvm-svn: 180063
1 parent ebeabab commit 04d4e93

File tree

27 files changed

+253
-228
lines changed

27 files changed

+253
-228
lines changed

llvm/include/llvm-c/Core.h

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
#include "llvm/Support/DataTypes.h"
1919

2020
#ifdef __cplusplus
21-
22-
/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
23-
and 'unwrap' conversion functions. */
24-
#include "llvm/IR/IRBuilder.h"
25-
#include "llvm/IR/Module.h"
26-
#include "llvm/PassRegistry.h"
27-
2821
extern "C" {
2922
#endif
3023

@@ -60,11 +53,6 @@ extern "C" {
6053
* with C++ due to name mangling. So in addition to C, this interface enables
6154
* tools written in such languages.
6255
*
63-
* When included into a C++ source file, also declares 'wrap' and 'unwrap'
64-
* helpers to perform opaque reference<-->pointer conversions. These helpers
65-
* are shorter and more tightly typed than writing the casts by hand when
66-
* authoring bindings. In assert builds, they will do runtime type checking.
67-
*
6856
* @{
6957
*/
7058

@@ -2690,100 +2678,6 @@ LLVMBool LLVMIsMultithreaded();
26902678

26912679
#ifdef __cplusplus
26922680
}
2693-
2694-
namespace llvm {
2695-
class MemoryBuffer;
2696-
class PassManagerBase;
2697-
2698-
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2699-
inline ty *unwrap(ref P) { \
2700-
return reinterpret_cast<ty*>(P); \
2701-
} \
2702-
\
2703-
inline ref wrap(const ty *P) { \
2704-
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2705-
}
2706-
2707-
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2708-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2709-
\
2710-
template<typename T> \
2711-
inline T *unwrap(ref P) { \
2712-
return cast<T>(unwrap(P)); \
2713-
}
2714-
2715-
#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2716-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2717-
\
2718-
template<typename T> \
2719-
inline T *unwrap(ref P) { \
2720-
T *Q = (T*)unwrap(P); \
2721-
assert(Q && "Invalid cast!"); \
2722-
return Q; \
2723-
}
2724-
2725-
DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2726-
DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
2727-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2728-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
2729-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
2730-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
2731-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
2732-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
2733-
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
2734-
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
2735-
/* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2736-
* Module.
2737-
*/
2738-
inline Module *unwrap(LLVMModuleProviderRef MP) {
2739-
return reinterpret_cast<Module*>(MP);
2740-
}
2741-
2742-
#undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2743-
#undef DEFINE_ISA_CONVERSION_FUNCTIONS
2744-
#undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2745-
2746-
/* Specialized opaque context conversions.
2747-
*/
2748-
inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2749-
return reinterpret_cast<LLVMContext**>(Tys);
2750-
}
2751-
2752-
inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2753-
return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2754-
}
2755-
2756-
/* Specialized opaque type conversions.
2757-
*/
2758-
inline Type **unwrap(LLVMTypeRef* Tys) {
2759-
return reinterpret_cast<Type**>(Tys);
2760-
}
2761-
2762-
inline LLVMTypeRef *wrap(Type **Tys) {
2763-
return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2764-
}
2765-
2766-
/* Specialized opaque value conversions.
2767-
*/
2768-
inline Value **unwrap(LLVMValueRef *Vals) {
2769-
return reinterpret_cast<Value**>(Vals);
2770-
}
2771-
2772-
template<typename T>
2773-
inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2774-
#ifdef DEBUG
2775-
for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2776-
cast<T>(*I);
2777-
#endif
2778-
(void)Length;
2779-
return reinterpret_cast<T**>(Vals);
2780-
}
2781-
2782-
inline LLVMValueRef *wrap(const Value **Vals) {
2783-
return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2784-
}
2785-
}
2786-
27872681
#endif /* !defined(__cplusplus) */
27882682

27892683
#endif /* !defined(LLVM_C_CORE_H) */

llvm/include/llvm-c/ExecutionEngine.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,7 @@ void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
137137
*/
138138

139139
#ifdef __cplusplus
140-
}
141-
142-
namespace llvm {
143-
struct GenericValue;
144-
class ExecutionEngine;
145-
146-
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
147-
inline ty *unwrap(ref P) { \
148-
return reinterpret_cast<ty*>(P); \
149-
} \
150-
\
151-
inline ref wrap(const ty *P) { \
152-
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
153-
}
154-
155-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue, LLVMGenericValueRef )
156-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
157-
158-
#undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
159-
}
160-
140+
}
161141
#endif /* defined(__cplusplus) */
162142

163143
#endif

llvm/include/llvm-c/Object.h

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "llvm/Config/llvm-config.h"
2424

2525
#ifdef __cplusplus
26-
#include "llvm/Object/ObjectFile.h"
27-
2826
extern "C" {
2927
#endif
3028

@@ -99,50 +97,6 @@ const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);
9997

10098
#ifdef __cplusplus
10199
}
102-
103-
namespace llvm {
104-
namespace object {
105-
inline ObjectFile *unwrap(LLVMObjectFileRef OF) {
106-
return reinterpret_cast<ObjectFile*>(OF);
107-
}
108-
109-
inline LLVMObjectFileRef wrap(const ObjectFile *OF) {
110-
return reinterpret_cast<LLVMObjectFileRef>(const_cast<ObjectFile*>(OF));
111-
}
112-
113-
inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
114-
return reinterpret_cast<section_iterator*>(SI);
115-
}
116-
117-
inline LLVMSectionIteratorRef
118-
wrap(const section_iterator *SI) {
119-
return reinterpret_cast<LLVMSectionIteratorRef>
120-
(const_cast<section_iterator*>(SI));
121-
}
122-
123-
inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) {
124-
return reinterpret_cast<symbol_iterator*>(SI);
125-
}
126-
127-
inline LLVMSymbolIteratorRef
128-
wrap(const symbol_iterator *SI) {
129-
return reinterpret_cast<LLVMSymbolIteratorRef>
130-
(const_cast<symbol_iterator*>(SI));
131-
}
132-
133-
inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
134-
return reinterpret_cast<relocation_iterator*>(SI);
135-
}
136-
137-
inline LLVMRelocationIteratorRef
138-
wrap(const relocation_iterator *SI) {
139-
return reinterpret_cast<LLVMRelocationIteratorRef>
140-
(const_cast<relocation_iterator*>(SI));
141-
}
142-
143-
}
144-
}
145-
146100
#endif /* defined(__cplusplus) */
147101

148102
#endif

llvm/include/llvm-c/Target.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,29 +235,6 @@ void LLVMDisposeTargetData(LLVMTargetDataRef);
235235

236236
#ifdef __cplusplus
237237
}
238-
239-
namespace llvm {
240-
class DataLayout;
241-
class TargetLibraryInfo;
242-
243-
inline DataLayout *unwrap(LLVMTargetDataRef P) {
244-
return reinterpret_cast<DataLayout*>(P);
245-
}
246-
247-
inline LLVMTargetDataRef wrap(const DataLayout *P) {
248-
return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout*>(P));
249-
}
250-
251-
inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
252-
return reinterpret_cast<TargetLibraryInfo*>(P);
253-
}
254-
255-
inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
256-
TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
257-
return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
258-
}
259-
}
260-
261238
#endif /* defined(__cplusplus) */
262239

263240
#endif

llvm/include/llvm-c/TargetMachine.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,8 @@ LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
117117
/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
118118
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
119119
LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
120-
121-
122-
123120
#ifdef __cplusplus
124121
}
125-
126-
namespace llvm {
127-
class TargetMachine;
128-
class Target;
129-
130-
inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
131-
return reinterpret_cast<TargetMachine*>(P);
132-
}
133-
inline Target *unwrap(LLVMTargetRef P) {
134-
return reinterpret_cast<Target*>(P);
135-
}
136-
inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
137-
return reinterpret_cast<LLVMTargetMachineRef>(
138-
const_cast<TargetMachine*>(P));
139-
}
140-
inline LLVMTargetRef wrap(const Target * P) {
141-
return reinterpret_cast<LLVMTargetRef>(const_cast<Target*>(P));
142-
}
143-
}
144122
#endif
145123

146124
#endif

llvm/include/llvm-c/Transforms/PassManagerBuilder.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,6 @@ void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
8686

8787
#ifdef __cplusplus
8888
}
89-
90-
namespace llvm {
91-
inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) {
92-
return reinterpret_cast<PassManagerBuilder*>(P);
93-
}
94-
95-
inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) {
96-
return reinterpret_cast<LLVMPassManagerBuilderRef>(P);
97-
}
98-
}
9989
#endif
10090

10191
#endif

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class MCContext;
3232
class PassManagerBase;
3333
class Target;
3434
class DataLayout;
35+
class TargetLibraryInfo;
3536
class TargetFrameLowering;
3637
class TargetInstrInfo;
3738
class TargetIntrinsicInfo;

0 commit comments

Comments
 (0)