mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 16:51:22 +08:00
#0 [Core] Added constexpr support macros and refactored extract_... functions
This commit is contained in:
parent
b812e1648c
commit
a0ab6a9000
@ -53,8 +53,6 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
//#define EASY_CODE_WRAP(Code) Code
|
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(EASY_PROFILER_STATIC)
|
#if defined(_WIN32) && !defined(EASY_PROFILER_STATIC)
|
||||||
// Visual Studio and MinGW
|
// Visual Studio and MinGW
|
||||||
# ifdef _BUILD_PROFILER
|
# ifdef _BUILD_PROFILER
|
||||||
@ -66,7 +64,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined (_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// Visual Studio
|
// Visual Studio
|
||||||
|
|
||||||
@ -80,19 +78,31 @@
|
|||||||
__declspec(thread) static VarType VarName = 0;\
|
__declspec(thread) static VarType VarName = 0;\
|
||||||
if (!VarName)\
|
if (!VarName)\
|
||||||
VarName = VarInitializer
|
VarName = VarInitializer
|
||||||
|
|
||||||
|
// No constexpr support before Visual Studio 2015
|
||||||
|
# define EASY_CONSTEXPR static const
|
||||||
|
# define EASY_STATIC_CONSTEXPR static const
|
||||||
|
# define EASY_CONSTEXPR_FCN
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#define EASY_FORCE_INLINE __forceinline
|
#define EASY_FORCE_INLINE __forceinline
|
||||||
|
|
||||||
#elif defined (__clang__)
|
#elif defined(__clang__)
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// Clang Compiler
|
// Clang Compiler
|
||||||
|
|
||||||
# if (__clang_major__ == 3 && __clang_minor__ < 3) || (__clang_major__ < 3)
|
# if (__clang_major__ == 3 && __clang_minor__ < 3) || (__clang_major__ < 3)
|
||||||
// There is no support for C++11 thread_local keyword prior to clang 3.3. Use __thread instead.
|
// There is no support for C++11 thread_local keyword prior to Clang v3.3. Use __thread instead.
|
||||||
# define EASY_THREAD_LOCAL __thread
|
# define EASY_THREAD_LOCAL __thread
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# if (__clang_major__ == 3 && __clang_minor__ < 1) || (__clang_major__ < 3)
|
||||||
|
// No constexpr support before Clang v3.1
|
||||||
|
# define EASY_CONSTEXPR static const
|
||||||
|
# define EASY_STATIC_CONSTEXPR static const
|
||||||
|
# define EASY_CONSTEXPR_FCN
|
||||||
|
# endif
|
||||||
|
|
||||||
# if (__clang_major__ == 2 && __clang_minor__ < 9) || (__clang_major__ < 2)
|
# if (__clang_major__ == 2 && __clang_minor__ < 9) || (__clang_major__ < 2)
|
||||||
// There is no support for C++11 magic statics feature prior to clang 2.9. It becomes slightly harder to initialize static vars - additional "if" for each profiler block.
|
// There is no support for C++11 magic statics feature prior to clang 2.9. It becomes slightly harder to initialize static vars - additional "if" for each profiler block.
|
||||||
# define EASY_LOCAL_STATIC_PTR(VarType, VarName, VarInitializer)\
|
# define EASY_LOCAL_STATIC_PTR(VarType, VarName, VarInitializer)\
|
||||||
@ -100,7 +110,7 @@
|
|||||||
if (!VarName)\
|
if (!VarName)\
|
||||||
VarName = VarInitializer
|
VarName = VarInitializer
|
||||||
|
|
||||||
// There is no support for C++11 final keyword prior to clang 2.9
|
// There is no support for C++11 final keyword prior to Clang v2.9
|
||||||
# define EASY_FINAL
|
# define EASY_FINAL
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
@ -115,6 +125,13 @@
|
|||||||
# define EASY_THREAD_LOCAL __thread
|
# define EASY_THREAD_LOCAL __thread
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# if (__GNUC__ == 4 && __GNUC_MINOR__ < 6) || (__GNUC__ < 4)
|
||||||
|
// No constexpr support before GCC v4.6
|
||||||
|
# define EASY_CONSTEXPR static const
|
||||||
|
# define EASY_STATIC_CONSTEXPR static const
|
||||||
|
# define EASY_CONSTEXPR_FCN
|
||||||
|
# endif
|
||||||
|
|
||||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || (__GNUC__ < 4)
|
# if (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || (__GNUC__ < 4)
|
||||||
// There is no support for C++11 magic statics feature prior to gcc 4.3. It becomes slightly harder to initialize static vars - additional "if" for each profiler block.
|
// There is no support for C++11 magic statics feature prior to gcc 4.3. It becomes slightly harder to initialize static vars - additional "if" for each profiler block.
|
||||||
# define EASY_LOCAL_STATIC_PTR(VarType, VarName, VarInitializer)\
|
# define EASY_LOCAL_STATIC_PTR(VarType, VarName, VarInitializer)\
|
||||||
@ -130,8 +147,13 @@
|
|||||||
|
|
||||||
#define EASY_FORCE_INLINE inline __attribute__((always_inline))
|
#define EASY_FORCE_INLINE inline __attribute__((always_inline))
|
||||||
|
|
||||||
|
#else
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// TODO: Add other compilers support
|
||||||
|
|
||||||
|
static_assert(false, "EasyProfiler is not configured yet for using your compiler type.");
|
||||||
#endif
|
#endif
|
||||||
// END // TODO: Add other compilers support
|
// END
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
@ -157,6 +179,13 @@
|
|||||||
# define EASY_FORCE_INLINE inline
|
# define EASY_FORCE_INLINE inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef EASY_CONSTEXPR
|
||||||
|
# define EASY_CONSTEXPR constexpr
|
||||||
|
# define EASY_STATIC_CONSTEXPR static constexpr
|
||||||
|
# define EASY_CONSTEXPR_FCN constexpr
|
||||||
|
# define EASY_CONSTEXPR_CPP11
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef PROFILER_API
|
#ifndef PROFILER_API
|
||||||
# define PROFILER_API
|
# define PROFILER_API
|
||||||
#endif
|
#endif
|
||||||
|
@ -136,61 +136,62 @@ namespace profiler {
|
|||||||
|
|
||||||
//***********************************************
|
//***********************************************
|
||||||
|
|
||||||
inline color_t extract_color() {
|
template <class ... TArgs>
|
||||||
|
inline EASY_CONSTEXPR_FCN color_t extract_color(TArgs...);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline EASY_CONSTEXPR_FCN color_t extract_color<>() {
|
||||||
return ::profiler::colors::Default;
|
return ::profiler::colors::Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ... TArgs>
|
template <class T>
|
||||||
inline color_t extract_color(::profiler::EasyBlockStatus, TArgs...) {
|
inline EASY_CONSTEXPR_FCN color_t extract_color(T) {
|
||||||
return ::profiler::colors::Default;
|
return ::profiler::colors::Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline EASY_CONSTEXPR_FCN color_t extract_color<color_t>(color_t _color) {
|
||||||
|
return _color;
|
||||||
|
}
|
||||||
|
|
||||||
template <class ... TArgs>
|
template <class ... TArgs>
|
||||||
inline color_t extract_color(color_t _color, TArgs...) {
|
inline EASY_CONSTEXPR_FCN color_t extract_color(color_t _color, TArgs...) {
|
||||||
return _color;
|
return _color;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, class ... TArgs>
|
template <class T, class ... TArgs>
|
||||||
inline color_t extract_color(T, color_t _color, TArgs...) {
|
inline EASY_CONSTEXPR_FCN color_t extract_color(T, TArgs... _args) {
|
||||||
return _color;
|
return extract_color(_args...);
|
||||||
}
|
|
||||||
|
|
||||||
template <class T, class U, class ... TArgs>
|
|
||||||
inline color_t extract_color(T, U, color_t _color, TArgs...) {
|
|
||||||
return _color;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ... TArgs>
|
|
||||||
inline color_t extract_color(TArgs...) {
|
|
||||||
static_assert(sizeof...(TArgs) < 2, "No profiler::color_t in arguments list for EASY_BLOCK(name, ...)!");
|
|
||||||
return ::profiler::colors::Default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//***********************************************
|
//***********************************************
|
||||||
|
|
||||||
inline EasyBlockStatus extract_enable_flag() {
|
template <class ... TArgs>
|
||||||
|
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(TArgs...);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag<>() {
|
||||||
return ::profiler::ON;
|
return ::profiler::ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(T) {
|
||||||
|
return ::profiler::ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(EasyBlockStatus _flag) {
|
||||||
|
return _flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ... TArgs>
|
||||||
|
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(EasyBlockStatus _flag, TArgs...) {
|
||||||
|
return _flag;
|
||||||
|
}
|
||||||
|
|
||||||
template <class T, class ... TArgs>
|
template <class T, class ... TArgs>
|
||||||
inline EasyBlockStatus extract_enable_flag(T, ::profiler::EasyBlockStatus _flag, TArgs...) {
|
inline EASY_CONSTEXPR_FCN EasyBlockStatus extract_enable_flag(T, TArgs... _args) {
|
||||||
return _flag;
|
return extract_enable_flag(_args...);
|
||||||
}
|
|
||||||
|
|
||||||
template <class T, class U, class ... TArgs>
|
|
||||||
inline EasyBlockStatus extract_enable_flag(T, U, ::profiler::EasyBlockStatus _flag, TArgs...) {
|
|
||||||
return _flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ... TArgs>
|
|
||||||
inline EasyBlockStatus extract_enable_flag(::profiler::EasyBlockStatus _flag, TArgs...) {
|
|
||||||
return _flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ... TArgs>
|
|
||||||
inline EasyBlockStatus extract_enable_flag(TArgs...) {
|
|
||||||
static_assert(sizeof...(TArgs) < 2, "No EasyBlockStatus in arguments list for EASY_BLOCK(name, ...)!");
|
|
||||||
return ::profiler::ON;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//***********************************************
|
//***********************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user