platform.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef BX_PLATFORM_H_HEADER_GUARD
  6. #define BX_PLATFORM_H_HEADER_GUARD
  7. #define BX_COMPILER_CLANG 0
  8. #define BX_COMPILER_GCC 0
  9. #define BX_COMPILER_MSVC 0
  10. #define BX_PLATFORM_ANDROID 0
  11. #define BX_PLATFORM_EMSCRIPTEN 0
  12. #define BX_PLATFORM_IOS 0
  13. #define BX_PLATFORM_LINUX 0
  14. #define BX_PLATFORM_NACL 0
  15. #define BX_PLATFORM_OSX 0
  16. #define BX_PLATFORM_QNX 0
  17. #define BX_PLATFORM_WINDOWS 0
  18. #define BX_PLATFORM_XBOX360 0
  19. #define BX_CPU_ARM 0
  20. #define BX_CPU_JIT 0
  21. #define BX_CPU_MIPS 0
  22. #define BX_CPU_PPC 0
  23. #define BX_CPU_X86 0
  24. #define BX_ARCH_32BIT 0
  25. #define BX_ARCH_64BIT 0
  26. #define BX_CPU_ENDIAN_BIG 0
  27. #define BX_CPU_ENDIAN_LITTLE 0
  28. // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
  29. #if defined(_MSC_VER)
  30. # undef BX_COMPILER_MSVC
  31. # define BX_COMPILER_MSVC 1
  32. #elif defined(__clang__)
  33. // clang defines __GNUC__
  34. # undef BX_COMPILER_CLANG
  35. # define BX_COMPILER_CLANG 1
  36. #elif defined(__GNUC__)
  37. # undef BX_COMPILER_GCC
  38. # define BX_COMPILER_GCC 1
  39. #else
  40. # error "BX_COMPILER_* is not defined!"
  41. #endif //
  42. // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Operating_Systems
  43. #if defined(_XBOX_VER)
  44. # undef BX_PLATFORM_XBOX360
  45. # define BX_PLATFORM_XBOX360 1
  46. #elif defined(_WIN32) || defined(_WIN64)
  47. # undef BX_PLATFORM_WINDOWS
  48. // http://msdn.microsoft.com/en-us/library/6sehtctf.aspx
  49. # if !defined(WINVER) && !defined(_WIN32_WINNT)
  50. // Windows Server 2003 with SP1, Windows XP with SP2 and above
  51. # define WINVER 0x0502
  52. # define _WIN32_WINNT 0x0502
  53. # endif // !defined(WINVER) && !defined(_WIN32_WINNT)
  54. # define BX_PLATFORM_WINDOWS _WIN32_WINNT
  55. #elif defined(__native_client__)
  56. // NaCl compiler defines __linux__
  57. # undef BX_PLATFORM_NACL
  58. # define BX_PLATFORM_NACL 1
  59. #elif defined(__ANDROID__)
  60. // Android compiler defines __linux__
  61. # undef BX_PLATFORM_ANDROID
  62. # define BX_PLATFORM_ANDROID 1
  63. #elif defined(__linux__)
  64. # undef BX_PLATFORM_LINUX
  65. # define BX_PLATFORM_LINUX 1
  66. #elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
  67. # undef BX_PLATFORM_IOS
  68. # define BX_PLATFORM_IOS 1
  69. #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
  70. # undef BX_PLATFORM_OSX
  71. # define BX_PLATFORM_OSX 1
  72. #elif defined(EMSCRIPTEN)
  73. # undef BX_PLATFORM_EMSCRIPTEN
  74. # define BX_PLATFORM_EMSCRIPTEN 1
  75. #elif defined(__QNX__)
  76. # undef BX_PLATFORM_QNX
  77. # define BX_PLATFORM_QNX 1
  78. #else
  79. # error "BX_PLATFORM_* is not defined!"
  80. #endif //
  81. #define BX_PLATFORM_POSIX (BX_PLATFORM_ANDROID \
  82. || BX_PLATFORM_EMSCRIPTEN \
  83. || BX_PLATFORM_IOS \
  84. || BX_PLATFORM_LINUX \
  85. || BX_PLATFORM_NACL \
  86. || BX_PLATFORM_OSX \
  87. || BX_PLATFORM_QNX)
  88. // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures
  89. #if defined(__arm__)
  90. # undef BX_CPU_ARM
  91. # define BX_CPU_ARM 1
  92. # define BX_CACHE_LINE_SIZE 64
  93. #elif defined(__MIPSEL__) || defined(__mips_isa_rev) // defined(mips)
  94. # undef BX_CPU_MIPS
  95. # define BX_CPU_MIPS 1
  96. # define BX_CACHE_LINE_SIZE 64
  97. #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc64__)
  98. # undef BX_CPU_PPC
  99. # define BX_CPU_PPC 1
  100. # define BX_CACHE_LINE_SIZE 128
  101. #elif defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__)
  102. # undef BX_CPU_X86
  103. # define BX_CPU_X86 1
  104. # define BX_CACHE_LINE_SIZE 64
  105. #else // PNaCl doesn't have CPU defined.
  106. # undef BX_CPU_JIT
  107. # define BX_CPU_JIT 1
  108. # define BX_CACHE_LINE_SIZE 64
  109. #endif //
  110. #if defined(__x86_64__) || defined(_M_X64) || defined(__64BIT__) || defined(__powerpc64__) || defined(__ppc64__)
  111. # undef BX_ARCH_64BIT
  112. # define BX_ARCH_64BIT 64
  113. #else
  114. # undef BX_ARCH_32BIT
  115. # define BX_ARCH_32BIT 32
  116. #endif //
  117. #if BX_CPU_PPC
  118. # undef BX_CPU_ENDIAN_BIG
  119. # define BX_CPU_ENDIAN_BIG 1
  120. #else
  121. # undef BX_CPU_ENDIAN_LITTLE
  122. # define BX_CPU_ENDIAN_LITTLE 1
  123. #endif // BX_PLATFORM_
  124. #ifndef BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS
  125. # define BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS 0
  126. #endif // BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS
  127. #if BX_COMPILER_GCC
  128. # define BX_COMPILER_NAME "GCC"
  129. #elif BX_COMPILER_CLANG
  130. # define BX_COMPILER_NAME "Clang"
  131. #elif BX_COMPILER_MSVC
  132. # define BX_COMPILER_NAME "MSVC"
  133. #endif // BX_COMPILER_
  134. #if BX_PLATFORM_ANDROID
  135. # define BX_PLATFORM_NAME "Android"
  136. #elif BX_PLATFORM_EMSCRIPTEN
  137. # define BX_PLATFORM_NAME "asm.js"
  138. #elif BX_PLATFORM_IOS
  139. # define BX_PLATFORM_NAME "iOS"
  140. #elif BX_PLATFORM_LINUX
  141. # define BX_PLATFORM_NAME "Linux"
  142. #elif BX_PLATFORM_NACL
  143. # define BX_PLATFORM_NAME "NaCl"
  144. #elif BX_PLATFORM_OSX
  145. # define BX_PLATFORM_NAME "OSX"
  146. #elif BX_PLATFORM_QNX
  147. # define BX_PLATFORM_NAME "QNX"
  148. #elif BX_PLATFORM_WINDOWS
  149. # define BX_PLATFORM_NAME "Windows"
  150. #endif // BX_PLATFORM_
  151. #if BX_CPU_ARM
  152. # define BX_CPU_NAME "ARM"
  153. #elif BX_CPU_MIPS
  154. # define BX_CPU_NAME "MIPS"
  155. #elif BX_CPU_PPC
  156. # define BX_CPU_NAME "PowerPC"
  157. #elif BX_CPU_JIT
  158. # define BX_CPU_NAME "JIT-VM"
  159. #elif BX_CPU_X86
  160. # define BX_CPU_NAME "x86"
  161. #endif // BX_CPU_
  162. #if BX_ARCH_32BIT
  163. # define BX_ARCH_NAME "32-bit"
  164. #elif BX_ARCH_64BIT
  165. # define BX_ARCH_NAME "64-bit"
  166. #endif // BX_ARCH_
  167. #if BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS && BX_COMPILER_MSVC
  168. # pragma warning(error:4062) // ENABLE warning C4062: enumerator'...' in switch of enum '...' is not handled
  169. # pragma warning(error:4121) // ENABLE warning C4121: 'symbol' : alignment of a member was sensitive to packing
  170. //# pragma warning(error:4127) // ENABLE warning C4127: conditional expression is constant
  171. # pragma warning(error:4130) // ENABLE warning C4130: 'operator' : logical operation on address of string constant
  172. # pragma warning(error:4239) // ENABLE warning C4239: nonstandard extension used : 'argument' : conversion from '*' to '* &' A non-const reference may only be bound to an lvalue
  173. //# pragma warning(error:4244) // ENABLE warning C4244: 'argument' : conversion from 'type1' to 'type2', possible loss of data
  174. # pragma warning(error:4245) // ENABLE warning C4245: 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
  175. # pragma warning(error:4263) // ENABLE warning C4263: 'function' : member function does not override any base class virtual member function
  176. # pragma warning(error:4265) // ENABLE warning C4265: class has virtual functions, but destructor is not virtual
  177. # pragma warning(error:4431) // ENABLE warning C4431: missing type specifier - int assumed. Note: C no longer supports default-int
  178. # pragma warning(error:4545) // ENABLE warning C4545: expression before comma evaluates to a function which is missing an argument list
  179. # pragma warning(error:4549) // ENABLE warning C4549: 'operator' : operator before comma has no effect; did you intend 'operator'?
  180. # pragma warning(error:4701) // ENABLE warning C4701: potentially uninitialized local variable 'name' used
  181. # pragma warning(error:4706) // ENABLE warning C4706: assignment within conditional expression
  182. # pragma warning(error:4100) // ENABLE warning C4100: '' : unreferenced formal parameter
  183. # pragma warning(error:4189) // ENABLE warning C4189: '' : local variable is initialized but not referenced
  184. # pragma warning(error:4505) // ENABLE warning C4505: '' : unreferenced local function has been removed
  185. #endif // BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS && BX_COMPILER_MSVC
  186. #if BX_COMPILER_CLANG && BX_PLATFORM_LINUX
  187. // Clang on Linux complains about missing __float128 type...
  188. typedef struct { long double x, y; } __float128;
  189. #endif // BX_COMPILER_CLANG && BX_PLATFORM_LINUX
  190. #endif // BX_PLATFORM_H_HEADER_GUARD