Skip to content

Instantly share code, notes, and snippets.

@raizam
Created December 16, 2019 01:42
Show Gist options
  • Save raizam/308477f1258a10ac19a81df877c15975 to your computer and use it in GitHub Desktop.
Save raizam/308477f1258a10ac19a81df877c15975 to your computer and use it in GitHub Desktop.
/*
* Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#ifndef NORMALIZE_H
#define NORMALIZE_H
#define PP_TO_STRING(v) #v
// Architecture
#define __arch_32bit 0
#define __arch_64bit 0
// Compiler
#define __compiler_clang 0
#define __compiler_clang_analyser 0
#define __compiler_gcc 0
#define __compiler_msvc 0
// Endianess
#define __cpu_endian_big 0
#define __cpu_endian_little 0
// CPU
#define __cpu_arm 0
#define __cpu_jit 0
#define __cpu_mips 0
#define __cpu_ppc 0
#define __cpu_riscv 0
#define __cpu_x86 0
// C Runtime
#define __crt_bionic 0
#define __crt_bsd 0
#define __crt_glibc 0
#define __crt_libcxx 0
#define __crt_mingw 0
#define __crt_msvc 0
#define __crt_newlib 0
#ifndef __crt_musl
# define __crt_musl 0
#endif // __crt_musl
#ifndef __crt_none
# define __crt_none 0
#endif // __crt_none
// Platform
#define __platform_android 0
#define __platform_bsd 0
#define __platform_emscripten 0
#define __platform_haiku 0
#define __platform_hurd 0
#define __platform_ios 0
#define __platform_linux 0
#define __platform_nx 0
#define __platform_osx 0
#define __platform_ps4 0
#define __platform_rpi 0
#define __platform_steamlink 0
#define __platform_windows 0
#define __platform_winrt 0
#define __platform_xboxone 0
// http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
#if defined(__clang__)
// clang defines __GNUC__ or _MSC_VER
# undef __compiler_clang
# define __compiler_clang (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
# if defined(__clang_analyzer__)
# undef __compiler_clang_analyser
# define __compiler_clang_analyser 1
# endif // defined(__clang_analyzer__)
#elif defined(_MSC_VER)
# undef __compiler_msvc
# define __compiler_msvc _MSC_VER
#elif defined(__GNUC__)
# undef __compiler_gcc
# define __compiler_gcc (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#else
# error "__compiler* is not defined!"
#endif //
// http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures
#if defined(__arm__) \
|| defined(__aarch64__) \
|| defined(_M_ARM)
# undef __cpu_arm
# define __cpu_arm 1
# define __cpu_cache_line_size 64
#elif defined(__MIPSEL__) \
|| defined(__mips_isa_rev) \
|| defined(__mips64)
# undef __cpu_mips
# define __cpu_mips 1
# define __cpu_cache_line_size 64
#elif defined(_M_PPC) \
|| defined(__powerpc__) \
|| defined(__powerpc64__)
# undef __cpu_ppc
# define __cpu_ppc 1
# define __cpu_cache_line_size 128
#elif defined(__riscv) \
|| defined(__riscv__) \
|| defined(RISCVEL)
# undef __cpu_riscv
# define __cpu_riscv 1
# define __cpu_cache_line_size 64
#elif defined(_M_IX86) \
|| defined(_M_X64) \
|| defined(__i386__) \
|| defined(__x86_64__)
# undef __cpu_x86
# define __cpu_x86 1
# define __cpu_cache_line_size 64
#else // PNaCl doesn't have CPU defined.
# undef __cpu_jit
# define __cpu_jit 1
# define __cpu_cache_line_size 64
#endif //
#if defined(__x86_64__) \
|| defined(_M_X64) \
|| defined(__aarch64__) \
|| defined(__64BIT__) \
|| defined(__mips64) \
|| defined(__powerpc64__) \
|| defined(__ppc64__) \
|| defined(__LP64__)
# undef __arch_64bit
# define __arch_64bit 64
#else
# undef __arch_32bit
# define __arch_32bit 32
#endif //
#if __cpu_ppc
// __BIG_ENDIAN__ is gcc predefined macro
# if defined(__BIG_ENDIAN__)
# undef __cpu_endian_big
# define __cpu_endian_big 1
# else
# undef __cpu_endian_little
# define __cpu_endian_little 1
# endif
#else
# undef __cpu_endian_little
# define __cpu_endian_little 1
#endif // __cpu_ppc
// http://sourceforge.net/apps/mediawiki/predef/index.php?title=Operating_Systems
#if defined(_DURANGO) || defined(_XBOX_ONE)
# undef __platform_xboxone
# define __platform_xboxone 1
#elif defined(_WIN32) || defined(_WIN64)
// http://msdn.microsoft.com/en-us/library/6sehtctf.aspx
# ifndef NOMINMAX
# define NOMINMAX
# endif // NOMINMAX
// If _USING_V110_SDK71_ is defined it means we are using the v110_xp or v120_xp toolset.
# if defined(_MSC_VER) && (_MSC_VER >= 1700) && (!_USING_V110_SDK71_)
# include <winapifamily.h>
# endif // defined(_MSC_VER) && (_MSC_VER >= 1700) && (!_USING_V110_SDK71_)
# if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
# undef __platform_windows
# if !defined(WINVER) && !defined(_WIN32_WINNT)
# if __arch_64bit
// When building 64-bit target Win7 and above.
# define WINVER 0x0601
# define _WIN32_WINNT 0x0601
# else
// Windows Server 2003 with SP1, Windows XP with SP2 and above
# define WINVER 0x0502
# define _WIN32_WINNT 0x0502
# endif // __arch_64bit
# endif // !defined(WINVER) && !defined(_WIN32_WINNT)
# define __platform_windows _WIN32_WINNT
# else
# undef __platform_winrt
# define __platform_winrt 1
# endif
#elif defined(__ANDROID__)
// Android compiler defines __linux__
# include <sys/cdefs.h> // Defines __BIONIC__ and includes android/api-level.h
# undef __platform_android
# define __platform_android __ANDROID_API__
#elif defined(__STEAMLINK__)
// SteamLink compiler defines __linux__
# undef __platform_steamlink
# define __platform_steamlink 1
#elif defined(__VCCOREVER__)
// RaspberryPi compiler defines __linux__
# undef __platform_rpi
# define __platform_rpi 1
#elif defined(__linux__)
# undef __platform_linux
# define __platform_linux 1
#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) \
|| defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
# undef __platform_ios
# define __platform_ios 1
#elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
# undef __platform_osx
# define __platform_osx __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
#elif defined(__EMSCRIPTEN__)
# undef __platform_emscripten
# define __platform_emscripten 1
#elif defined(__ORBIS__)
# undef __platform_ps4
# define __platform_ps4 1
#elif defined(__FreeBSD__) \
|| defined(__FreeBSD_kernel__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__DragonFly__)
# undef __platform_bsd
# define __platform_bsd 1
#elif defined(__GNU__)
# undef __platform_hurd
# define __platform_hurd 1
#elif defined(__NX__)
# undef __platform_nx
# define __platform_nx 1
#elif defined(__HAIKU__)
# undef __platform_haiku
# define __platform_haiku 1
#endif //
#if !__crt_none
// https://sourceforge.net/p/predef/wiki/Libraries/
# if defined(__BIONIC__)
# undef __crt_bionic
# define __crt_bionic 1
# elif defined(_MSC_VER)
# undef __crt_msvc
# define __crt_msvc 1
# elif defined(__GLIBC__)
# undef __crt_glibc
# define __crt_glibc (__GLIBC__ * 10000 + __GLIBC_MINOR__ * 100)
# elif defined(__MINGW32__) || defined(__MINGW64__)
# undef __crt_mingw
# define __crt_mingw 1
# elif defined(__apple_build_version__) || defined(__ORBIS__) || defined(__EMSCRIPTEN__) || defined(__llvm__) || defined(__HAIKU__)
# undef __crt_libcxx
# define __crt_libcxx 1
# elif __platform_bsd
# undef __crt_bsd
# define __crt_bsd 1
# endif //
# if !__crt_bionic \
&& !__crt_bsd \
&& !__crt_glibc \
&& !__crt_libcxx \
&& !__crt_mingw \
&& !__crt_msvc \
&& !__crt_musl \
&& !__crt_newlib
# undef __crt_none
# define __crt_none 1
# endif // BX_CRT_*
#endif // !__crt_none
///
#define __platform_posix (0 \
|| __platform_android \
|| __platform_bsd \
|| __platform_emscripten \
|| __platform_haiku \
|| __platform_hurd \
|| __platform_ios \
|| __platform_linux \
|| __platform_nx \
|| __platform_osx \
|| __platform_ps4 \
|| __platform_rpi \
|| __platform_steamlink \
)
///
#define __platform_none !(0 \
|| __platform_android \
|| __platform_bsd \
|| __platform_emscripten \
|| __platform_haiku \
|| __platform_hurd \
|| __platform_ios \
|| __platform_linux \
|| __platform_nx \
|| __platform_osx \
|| __platform_ps4 \
|| __platform_rpi \
|| __platform_steamlink \
|| __platform_windows \
|| __platform_winrt \
|| __platform_xboxone \
)
///
#define __platform_os_console (0 \
|| __platform_nx \
|| __platform_ps4 \
|| __platform_winrt \
|| __platform_xboxone \
)
///
#define __platform_os_desktop (0 \
|| __platform_bsd \
|| __platform_haiku \
|| __platform_hurd \
|| __platform_linux \
|| __platform_osx \
|| __platform_windows \
)
///
#define __platform_os_embedded (0 \
|| __platform_rpi \
|| __platform_steamlink \
)
///
#define __platform_os_mobile (0 \
|| __platform_android \
|| __platform_ios \
)
///
#define __platform_os_web (0 \
|| __platform_emscripten \
)
///
#if __compiler_gcc
# define __compiler_name "GCC " \
PP_TO_STRING(__GNUC__) "." \
PP_TO_STRING(__GNUC_MINOR__) "." \
PP_TO_STRING(__GNUC_PATCHLEVEL__)
#elif __compiler_clang
# define __compiler_name "Clang " \
PP_TO_STRING(__clang_major__) "." \
PP_TO_STRING(__clang_minor__) "." \
PP_TO_STRING(__clang_patchlevel__)
#elif __compiler_msvc
# if __compiler_msvc >= 1920 // Visual Studio 2019
# define __compiler_name "MSVC 16.0"
# elif __compiler_msvc >= 1910 // Visual Studio 2017
# define __compiler_name "MSVC 15.0"
# elif __compiler_msvc >= 1900 // Visual Studio 2015
# define __compiler_name "MSVC 14.0"
# elif __compiler_msvc >= 1800 // Visual Studio 2013
# define __compiler_name "MSVC 12.0"
# elif __compiler_msvc >= 1700 // Visual Studio 2012
# define __compiler_name "MSVC 11.0"
# elif __compiler_msvc >= 1600 // Visual Studio 2010
# define __compiler_name "MSVC 10.0"
# elif __compiler_msvc >= 1500 // Visual Studio 2008
# define __compiler_name "MSVC 9.0"
# else
# define __compiler_name "MSVC"
# endif //
#endif // BX_COMPILER_
#if __platform_android
# define __platform_name "Android " \
PP_TO_STRING(__platform_android)
#elif __platform_bsd
# define __platform_name "BSD"
#elif __platform_emscripten
# define __platform_name "asm.js " \
PP_TO_STRING(__EMSCRIPTEN_major__) "." \
PP_TO_STRING(__EMSCRIPTEN_minor__) "." \
PP_TO_STRING(__EMSCRIPTEN_tiny__)
#elif __platform_haiku
# define __platform_name "Haiku"
#elif __platform_hurd
# define __platform_name "Hurd"
#elif __platform_ios
# define __platform_name "iOS"
#elif __platform_linux
# define __platform_name "Linux"
#elif __platform_none
# define __platform_name "None"
#elif __platform_nx
# define __platform_name "NX"
#elif __platform_osx
# define __platform_name "OSX"
#elif __platform_ps4
# define __platform_name "PlayStation 4"
#elif __platform_rpi
# define __platform_name "RaspberryPi"
#elif __platform_steamlink
# define __platform_name "SteamLink"
#elif __platform_windows
# define __platform_name "Windows"
#elif __platform_winrt
# define __platform_name "WinRT"
#elif __platform_xboxone
# define __platform_name "Xbox One"
#else
# error "Unknown platform!"
#endif // __platform
#if __cpu_arm
# define __cpu_name "ARM"
#elif __cpu_jit
# define __cpu_name "JIT-VM"
#elif __cpu_mips
# define __cpu_name "MIPS"
#elif __cpu_ppc
# define __cpu_name "PowerPC"
#elif __cpu_riscv
# define __cpu_name "RISC-V"
#elif __cpu_x86
# define __cpu_name "x86"
#endif // __cpu
#if __crt_bionic
# define __crt_name "Bionic libc"
#elif __crt_bsd
# define __crt_name "BSD libc"
#elif __crt_glibc
# define __crt_name "GNU C Library"
#elif __crt_msvc
# define __crt_name "MSVC C Runtime"
#elif __crt_mingw
# define __crt_name "MinGW C Runtime"
#elif __crt_libcxx
# define __crt_name "Clang C Library"
#elif __crt_newlib
# define __crt_name "Newlib"
#elif __crt_musl
# define __crt_name "musl libc"
#elif __crt_none
# define __crt_name "None"
#else
# error "Unknown BX_CRT!"
#endif // __crt
#if __arch_32bit
# define __arch_name "32-bit"
#elif __arch_64bit
# define __arch_name "64-bit"
#endif // __arch
#if __compiler_msvc
# define __cpp_name "C++MsvcUnknown"
#elif defined(__cplusplus)
# if __cplusplus < 201103L
# error "Pre-C++11 compiler is not supported!"
# elif __cplusplus < 201402L
# define __cpp_name "C++11"
# elif __cplusplus < 201703L
# define __cpp_name "C++14"
# elif __cplusplus < 201704L
# define __cpp_name "C++17"
# else
// See: https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b#orthodox-c
# define __cpp_name "C++WayTooModern"
# endif // __cpp_name
#else
# define __cpp_name "C++Unknown"
#endif // defined(__cplusplus)
#endif // NORMALIZE_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment