@@ -20,36 +20,35 @@ namespace codegen {
20
20
// / This file contains several macros that help in creating proxies to C++
21
21
// / classes.
22
22
23
- #define PROXY (N ) struct N ##Proxy
23
+ #define PROXY (clazz ) struct clazz ##Proxy
24
24
25
- #define DECLARE_MEMBER (P, T, N ) \
26
- static const ::peloton::codegen::ProxyMember<P, T> _##N ;
25
+ #define DECLARE_MEMBER (pos, type, name ) \
26
+ static const ::peloton::codegen::ProxyMember<pos, type> name ;
27
27
28
28
#define DECLARE_TYPE \
29
29
static ::llvm::Type *GetType (::peloton::codegen::CodeGen &codegen);
30
30
31
- #define DECLARE_METHOD (N ) \
32
- struct _ ##N : public ::peloton::codegen::ProxyMethod<_##N> { \
33
- static const char *k##N##FnName; \
31
+ #define DECLARE_METHOD (name ) \
32
+ struct _ ##name { \
34
33
::llvm::Function *GetFunction (::peloton::codegen::CodeGen &codegen) const ; \
35
34
}; \
36
- static _##N N ;
35
+ static _##name name ;
37
36
38
- #define MEMBER (N ) decltype (_##N )
37
+ #define MEMBER (member_name ) decltype (member_name )
39
38
#define FIELDS (...) \
40
39
(::peloton::codegen::proxy::TypeList<__VA_ARGS__>::GetType(codegen))
41
40
42
- #define DEFINE_TYPE (P, N , ...) \
43
- ::llvm::Type *P ##Proxy::GetType(::peloton::codegen::CodeGen &codegen) { \
44
- static constexpr const char *kTypeName = N; \
45
- /* Check if type has already been registered */ \
46
- ::llvm::Type *type = codegen.LookupType (kTypeName ); \
47
- if (type != nullptr ) { \
48
- return type; \
49
- } \
50
- ::std::vector<::llvm::Type *> fields = (FIELDS (__VA_ARGS__)); \
51
- return ::llvm::StructType::create (codegen.GetContext (), fields, \
52
- kTypeName ); \
41
+ #define DEFINE_TYPE (clazz, str_name , ...) \
42
+ ::llvm::Type *clazz ##Proxy::GetType(::peloton::codegen::CodeGen &codegen) { \
43
+ static constexpr const char *kTypeName = str_name; \
44
+ /* Check if type has already been registered */ \
45
+ ::llvm::Type *type = codegen.LookupType (kTypeName ); \
46
+ if (type != nullptr ) { \
47
+ return type; \
48
+ } \
49
+ ::std::vector<::llvm::Type *> fields = (FIELDS (__VA_ARGS__)); \
50
+ return ::llvm::StructType::create (codegen.GetContext (), fields, \
51
+ kTypeName ); \
53
52
}
54
53
55
54
namespace proxy {
@@ -195,31 +194,31 @@ struct MemFn<R (*)(Args..., ...), T, F> {
195
194
196
195
#define STR (x ) #x
197
196
198
- #define DEFINE_METHOD (NS, C, F ) \
199
- C##Proxy::_##F C##Proxy::F = {}; \
200
- const char *C##Proxy::_##F::k##F##FnName = STR(NS::C::F); \
201
- ::llvm::Function *C##Proxy::_##F::GetFunction( \
202
- ::peloton::codegen::CodeGen &codegen) const { \
203
- /* If the function has already been defined, return it. */ \
204
- if (::llvm::Function *func = codegen.LookupBuiltin (k##F##FnName )) { \
205
- return func; \
206
- } \
207
- \
208
- /* Ensure either a function pointer or a member function pointer */ \
209
- static_assert ( \
210
- ((::std::is_pointer<decltype (&NS::C::F)>::value && \
211
- ::std::is_function<typename ::std::remove_pointer<decltype ( \
212
- &NS::C::F)>::type>::value) || \
213
- ::std::is_member_function_pointer<decltype (&NS::C::F)>::value), \
214
- " You must provide a pointer to the function you want to proxy" ); \
215
- \
216
- /* The function hasn't been registered. Do it now. */ \
217
- auto *func_type_ptr = ::llvm::cast<::llvm::PointerType>( \
218
- ::peloton::codegen::proxy::TypeBuilder<decltype (&NS::C::F)>::GetType ( \
219
- codegen)); \
220
- auto *func_type = \
221
- ::llvm::cast<::llvm::FunctionType>(func_type_ptr->getElementType ()); \
222
- return codegen.RegisterBuiltin (k##F##FnName , func_type, MEMFN (&NS::C::F)); \
197
+ #define DEFINE_METHOD (NS, C, F ) \
198
+ C##Proxy::_##F C##Proxy::F = {}; \
199
+ ::llvm::Function *C##Proxy::_##F::GetFunction( \
200
+ ::peloton::codegen::CodeGen &codegen) const { \
201
+ static constexpr const char * kFnName = STR (NS::C::F); \
202
+ /* If the function has already been defined, return it. */ \
203
+ if (::llvm::Function *func = codegen.LookupBuiltin (kFnName )) { \
204
+ return func; \
205
+ } \
206
+ \
207
+ /* Ensure either a function pointer or a member function pointer */ \
208
+ static_assert ( \
209
+ ((::std::is_pointer<decltype (&NS::C::F)>::value && \
210
+ ::std::is_function<typename ::std::remove_pointer<decltype ( \
211
+ &NS::C::F)>::type>::value) || \
212
+ ::std::is_member_function_pointer<decltype (&NS::C::F)>::value), \
213
+ " You must provide a pointer to the function you want to proxy" ); \
214
+ \
215
+ /* The function hasn't been registered. Do it now. */ \
216
+ auto *func_type_ptr = ::llvm::cast<::llvm::PointerType>( \
217
+ ::peloton::codegen::proxy::TypeBuilder<decltype (&NS::C::F)>::GetType ( \
218
+ codegen)); \
219
+ auto *func_type = \
220
+ ::llvm::cast<::llvm::FunctionType>(func_type_ptr->getElementType ()); \
221
+ return codegen.RegisterBuiltin (kFnName , func_type, MEMFN (&NS::C::F)); \
223
222
}
224
223
225
224
#define TYPE_BUILDER (PROXY, TYPE ) \
0 commit comments